您可以创建自己的Recommender
类的实现
class CustomRecommender implements Recommender{
....
public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
IDRescorer rescorer = new CustomResorer();
return delegate.recommend(userID, howMany, rescorer);
}
public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
return delegate.recommend(userID, howMany, rescorer);
}
public float estimatePreference(long userID, long itemID) throws TasteException {
IDRescorer rescorer = new CustomResorer();
return (float) rescorer.rescore( itemID, delegate.estimatePreference(userID, itemID));
}
...
}
在这里,即使在没有 rescorer 的情况下调用推荐,您也会将其合并到recommend
andestimatePreference
方法中。
然后,当您构建时,RecommenderBuilder
您将创建推荐器的实例:
RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
@Override
public Recommender buildRecommender(DataModel model) throws TasteException {
Similarity similarity = new ...
return new CustomRecommender(model, similarity);
}
};