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?
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.