如何理解这段代码片段的错误消息?

发布于 2024-11-27 07:49:20 字数 1605 浏览 2 评论 0原文

我需要使用开源软件 Mahout 开展一个项目。示例程序 如下。

import org.apache.mahout.cf.taste.common.Refreshable;
import org.apache.mahout.cf.taste.impl.common.FastIDSet;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
public class GenderItemSimilarity implements ItemSimilarity {

   private final FastIDSet men;
   private final FastIDSet women;
   public GenderItemSimilarity(FastIDSet men, FastIDSet women) {
       this.men = men;
       this.women = women;
   }

   public double itemSimilarity(long profileID1, long profileID2) {
      Boolean profile1IsMan = isMan(profileID1);
      if (profile1IsMan == null) {
      return 0.0;
   }
   Boolean profile2IsMan = isMan(profileID2);
      if (profile2IsMan == null) {
        return 0.0;
      }
   return profile1IsMan == profile2IsMan ? 1.0 : -1.0;
   }

 public double[] itemSimilarities(long itemID1, long[] itemID2s) {
    double[] result = new double[itemID2s.length];
    for (int i = 0; i < itemID2s.length; i++) {
     result[i] = itemSimilarity(itemID1, itemID2s[i]);
    }
   return result;
 }

private Boolean isMan(long profileID) {
  if (men.contains(profileID)) {
  return Boolean.TRUE;
 }
if (women.contains(profileID)) {
    return Boolean.FALSE;
  }
   return null;
}

public void refresh(Collection<Refreshable> alreadyRefreshed) {
  // do nothing
 }
}

eclipse编译器给出错误信息,例如

类型 GenderItemSimilarity 必须实现继承的抽象方法 ItemSimilarity.allSimilarItemIDs(long)

在我看来,此错误消息表明存在一个类 ItemSimilarity,它具有 allSimilarItemIDs(long) 方法。不过目前的程序没有这个方法。我的分析正确吗?添加这种方法能解决问题吗?

I need to work on a project using open source software, mahout. An example program
is as follows.

import org.apache.mahout.cf.taste.common.Refreshable;
import org.apache.mahout.cf.taste.impl.common.FastIDSet;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
public class GenderItemSimilarity implements ItemSimilarity {

   private final FastIDSet men;
   private final FastIDSet women;
   public GenderItemSimilarity(FastIDSet men, FastIDSet women) {
       this.men = men;
       this.women = women;
   }

   public double itemSimilarity(long profileID1, long profileID2) {
      Boolean profile1IsMan = isMan(profileID1);
      if (profile1IsMan == null) {
      return 0.0;
   }
   Boolean profile2IsMan = isMan(profileID2);
      if (profile2IsMan == null) {
        return 0.0;
      }
   return profile1IsMan == profile2IsMan ? 1.0 : -1.0;
   }

 public double[] itemSimilarities(long itemID1, long[] itemID2s) {
    double[] result = new double[itemID2s.length];
    for (int i = 0; i < itemID2s.length; i++) {
     result[i] = itemSimilarity(itemID1, itemID2s[i]);
    }
   return result;
 }

private Boolean isMan(long profileID) {
  if (men.contains(profileID)) {
  return Boolean.TRUE;
 }
if (women.contains(profileID)) {
    return Boolean.FALSE;
  }
   return null;
}

public void refresh(Collection<Refreshable> alreadyRefreshed) {
  // do nothing
 }
}

The eclipse compiler gives the error message such as

The type GenderItemSimilarity must implement the inherited abstract method ItemSimilarity.allSimilarItemIDs(long)

It seems to me that this error message indicates that there exists a class ItemSimilarity, which has a method of allSimilarItemIDs(long). However, the current program does not have this method. Is my analysis correct? Will adding this kind of method solve the issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心清如水 2024-12-04 07:49:20

您是对的,ItemSimilarity 类声明了一个名为 allSimilarItemIDs 的抽象方法。当您实现此类时,您必须为类中的抽象方法定义方法体。

You're correct, the ItemSimilarity class declares an abstract method called allSimilarItemIDs. As you're implementing this class, you must define a method body for that abstract method in your class.

回心转意 2024-12-04 07:49:20

这是《Mahout in Action》一书中的片段。 (我是一名作者。)我认为这不是本书附带的完整的最新源代码。确保获取最新信息,目前不在曼宁,但生活(并将生活)在 GitHub

This is a snippet from the book Mahout in Action. (I'm an author.) I don't think this is the complete, latest source code that accompanies the book. Make sure to get the latest, which at the moment is not at Manning, but lives (and will live) on Github.

抱猫软卧 2024-12-04 07:49:20

从错误消息中我们可以了解到 ItemSimilarity 接口有一个名为 allSimilarItemIDs(long) 的方法,我们也需要处理该方法。

仅出于测试目的,通过添加简单的打印语句来实现此方法。
如果它解决了这个问题,那么我们就可以很容易地理解问题所在。

From the error message we could understand that ItemSimilarity interface is having a method called allSimilarItemIDs(long) which we need to handle also..

Just for testing purpose once implement this method by adding a simple print statement.
If it solves this then we can easily understand what the problem is..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文