如何理解这段代码片段的错误消息?
我需要使用开源软件 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是对的,
ItemSimilarity
类声明了一个名为allSimilarItemIDs
的抽象方法。当您实现此类时,您必须为类中的抽象方法定义方法体。You're correct, the
ItemSimilarity
class declares an abstract method calledallSimilarItemIDs
. As you're implementing this class, you must define a method body for that abstract method in your class.这是《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.
从错误消息中我们可以了解到 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..