Jean-Francois Leveque

Création d'interface de recommandation et de 4 implémentations

package org.legrog.recommendation.process;
import org.grouplens.lenskit.GlobalItemScorer;
import org.grouplens.lenskit.ItemRecommender;
import org.grouplens.lenskit.ItemScorer;
import org.grouplens.lenskit.RecommenderBuildException;
import org.grouplens.lenskit.baseline.BaselineScorer;
import org.grouplens.lenskit.core.LenskitConfiguration;
import org.grouplens.lenskit.core.LenskitRecommender;
import org.grouplens.lenskit.data.dao.EventDAO;
import org.grouplens.lenskit.data.history.LikeCountUserHistorySummarizer;
import org.grouplens.lenskit.data.history.UserHistorySummarizer;
import org.grouplens.lenskit.data.pref.PreferenceDomain;
import org.grouplens.lenskit.data.text.DelimitedColumnEventFormat;
import org.grouplens.lenskit.data.text.Fields;
import org.grouplens.lenskit.data.text.LikeEventType;
import org.grouplens.lenskit.data.text.TextEventDAO;
import org.grouplens.lenskit.knn.item.ItemItemGlobalScorer;
import org.grouplens.lenskit.knn.item.ItemItemScorer;
import org.grouplens.lenskit.knn.item.ItemSimilarity;
import org.grouplens.lenskit.knn.item.ItemVectorSimilarity;
import org.grouplens.lenskit.scored.ScoredId;
import org.grouplens.lenskit.vectors.similarity.CosineVectorSimilarity;
import org.grouplens.lenskit.vectors.similarity.VectorSimilarity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
public class CosineRecommender implements Recommender {
Logger logger = LoggerFactory.getLogger(getClass());
LenskitConfiguration config;
DelimitedColumnEventFormat delimitedColumnEventFormat;
ItemRecommender irec;
@Override
public void Recommender(String filePath) {
config = new LenskitConfiguration();
config.bind(ItemScorer.class).to(ItemItemScorer.class);
config.bind(GlobalItemScorer.class).to(ItemItemGlobalScorer.class);
config.bind(BaselineScorer.class, ItemScorer.class).to(ItemItemScorer.class);
config.bind(PreferenceDomain.class).to(new PreferenceDomain(0, 1));
config.bind(ItemSimilarity.class).to(ItemVectorSimilarity.class);
config.bind(VectorSimilarity.class).to(CosineVectorSimilarity.class);
config.bind(UserHistorySummarizer.class).to(LikeCountUserHistorySummarizer.class);
delimitedColumnEventFormat = new DelimitedColumnEventFormat(new LikeEventType());
delimitedColumnEventFormat.setDelimiter("\t");
delimitedColumnEventFormat.setHeaderLines(1);
delimitedColumnEventFormat.setFields(Fields.item(), Fields.user());
TextEventDAO textEventDAO = new TextEventDAO(new File(filePath), delimitedColumnEventFormat);
config.bind(EventDAO.class).to(textEventDAO);
LenskitRecommender rec;
try {
rec = LenskitRecommender.build(config);
irec = rec.getItemRecommender();
} catch (RecommenderBuildException e) {
logger.error("Recommender RecommenderBuildException {}", e.getStackTrace());
}
}
@Override
public List<ScoredId> recommend(long user, int n) {
return irec.recommend(user, n);
}
}
package org.legrog.recommendation.process;
import org.grouplens.lenskit.GlobalItemScorer;
import org.grouplens.lenskit.ItemRecommender;
import org.grouplens.lenskit.ItemScorer;
import org.grouplens.lenskit.RecommenderBuildException;
import org.grouplens.lenskit.baseline.BaselineScorer;
import org.grouplens.lenskit.core.LenskitConfiguration;
import org.grouplens.lenskit.core.LenskitRecommender;
import org.grouplens.lenskit.data.dao.EventDAO;
import org.grouplens.lenskit.data.history.RatingVectorUserHistorySummarizer;
import org.grouplens.lenskit.data.history.UserHistorySummarizer;
import org.grouplens.lenskit.data.pref.PreferenceDomain;
import org.grouplens.lenskit.data.text.DelimitedColumnEventFormat;
import org.grouplens.lenskit.data.text.Fields;
import org.grouplens.lenskit.data.text.RatingEventType;
import org.grouplens.lenskit.data.text.TextEventDAO;
import org.grouplens.lenskit.knn.item.ItemItemGlobalScorer;
import org.grouplens.lenskit.mf.funksvd.FunkSVDItemScorer;
import org.grouplens.lenskit.scored.ScoredId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
public class FunkSVDRecommender implements Recommender {
Logger logger = LoggerFactory.getLogger(getClass());
LenskitConfiguration config;
DelimitedColumnEventFormat delimitedColumnEventFormat;
ItemRecommender irec;
@Override
public void Recommender(String filePath) {
config = new LenskitConfiguration();
config.bind(ItemScorer.class).to(FunkSVDItemScorer.class);
config.bind(GlobalItemScorer.class).to(ItemItemGlobalScorer.class);
config.bind(BaselineScorer.class, ItemScorer.class).to(FunkSVDItemScorer.class);
config.bind(PreferenceDomain.class).to(new PreferenceDomain(1.0, 5.0, 1.0));
config.bind(UserHistorySummarizer.class).to(RatingVectorUserHistorySummarizer.class);
delimitedColumnEventFormat = new DelimitedColumnEventFormat(new RatingEventType());
delimitedColumnEventFormat.setDelimiter("\t");
delimitedColumnEventFormat.setHeaderLines(1);
delimitedColumnEventFormat.setFields(Fields.item(), Fields.user(), Fields.rating());
TextEventDAO textEventDAO = new TextEventDAO(new File(filePath), delimitedColumnEventFormat);
config.bind(EventDAO.class).to(textEventDAO);
LenskitRecommender rec;
try {
rec = LenskitRecommender.build(config);
irec = rec.getItemRecommender();
} catch (RecommenderBuildException e) {
logger.error("Recommender RecommenderBuildException {}", e.getStackTrace());
}
}
@Override
public List<ScoredId> recommend(long user, int n) {
return irec.recommend(user, n);
}
}
package org.legrog.recommendation.process;
import org.grouplens.lenskit.GlobalItemScorer;
import org.grouplens.lenskit.ItemRecommender;
import org.grouplens.lenskit.ItemScorer;
import org.grouplens.lenskit.RecommenderBuildException;
import org.grouplens.lenskit.baseline.BaselineScorer;
import org.grouplens.lenskit.core.LenskitConfiguration;
import org.grouplens.lenskit.core.LenskitRecommender;
import org.grouplens.lenskit.data.dao.EventDAO;
import org.grouplens.lenskit.data.history.LikeCountUserHistorySummarizer;
import org.grouplens.lenskit.data.history.UserHistorySummarizer;
import org.grouplens.lenskit.data.pref.PreferenceDomain;
import org.grouplens.lenskit.data.text.DelimitedColumnEventFormat;
import org.grouplens.lenskit.data.text.Fields;
import org.grouplens.lenskit.data.text.LikeEventType;
import org.grouplens.lenskit.data.text.TextEventDAO;
import org.grouplens.lenskit.knn.item.ItemItemGlobalScorer;
import org.grouplens.lenskit.knn.item.ItemItemScorer;
import org.grouplens.lenskit.knn.item.ItemSimilarity;
import org.grouplens.lenskit.knn.item.ItemVectorSimilarity;
import org.grouplens.lenskit.scored.ScoredId;
import org.grouplens.lenskit.vectors.similarity.PearsonCorrelation;
import org.grouplens.lenskit.vectors.similarity.VectorSimilarity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
public class PearsonRecommender implements Recommender {
Logger logger = LoggerFactory.getLogger(getClass());
LenskitConfiguration config;
DelimitedColumnEventFormat delimitedColumnEventFormat;
ItemRecommender irec;
@Override
public void Recommender(String filePath) {
config = new LenskitConfiguration();
config.bind(ItemScorer.class).to(ItemItemScorer.class);
config.bind(GlobalItemScorer.class).to(ItemItemGlobalScorer.class);
config.bind(BaselineScorer.class, ItemScorer.class).to(ItemItemScorer.class);
config.bind(PreferenceDomain.class).to(new PreferenceDomain(0, 1));
config.bind(ItemSimilarity.class).to(ItemVectorSimilarity.class);
config.bind(VectorSimilarity.class).to(PearsonCorrelation.class);
config.bind(UserHistorySummarizer.class).to(LikeCountUserHistorySummarizer.class);
delimitedColumnEventFormat = new DelimitedColumnEventFormat(new LikeEventType());
delimitedColumnEventFormat.setDelimiter("\t");
delimitedColumnEventFormat.setHeaderLines(1);
delimitedColumnEventFormat.setFields(Fields.item(), Fields.user());
TextEventDAO textEventDAO = new TextEventDAO(new File(filePath), delimitedColumnEventFormat);
config.bind(EventDAO.class).to(textEventDAO);
LenskitRecommender rec;
try {
rec = LenskitRecommender.build(config);
irec = rec.getItemRecommender();
} catch (RecommenderBuildException e) {
logger.error("Recommender RecommenderBuildException {}", e.getStackTrace());
}
}
@Override
public List<ScoredId> recommend(long user, int n) {
return irec.recommend(user, n);
}
}
package org.legrog.recommendation.process;
import org.grouplens.lenskit.scored.ScoredId;
import java.util.List;
public interface Recommender {
void Recommender(String filePath);
List<ScoredId> recommend(long user, int n);
}
package org.legrog.recommendation.process;
import org.grouplens.lenskit.GlobalItemScorer;
import org.grouplens.lenskit.ItemRecommender;
import org.grouplens.lenskit.ItemScorer;
import org.grouplens.lenskit.RecommenderBuildException;
import org.grouplens.lenskit.baseline.BaselineScorer;
import org.grouplens.lenskit.core.LenskitConfiguration;
import org.grouplens.lenskit.core.LenskitRecommender;
import org.grouplens.lenskit.data.dao.EventDAO;
import org.grouplens.lenskit.data.history.RatingVectorUserHistorySummarizer;
import org.grouplens.lenskit.data.history.UserHistorySummarizer;
import org.grouplens.lenskit.data.pref.PreferenceDomain;
import org.grouplens.lenskit.data.text.*;
import org.grouplens.lenskit.knn.item.ItemItemGlobalScorer;
import org.grouplens.lenskit.scored.ScoredId;
import org.grouplens.lenskit.slopeone.SlopeOneItemScorer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.List;
public class SlopeOneRecommender implements Recommender {
Logger logger = LoggerFactory.getLogger(getClass());
LenskitConfiguration config;
DelimitedColumnEventFormat delimitedColumnEventFormat;
ItemRecommender irec;
@Override
public void Recommender(String filePath) {
config = new LenskitConfiguration();
config.bind(ItemScorer.class).to(SlopeOneItemScorer.class);
config.bind(GlobalItemScorer.class).to(ItemItemGlobalScorer.class);
config.bind(BaselineScorer.class, ItemScorer.class).to(SlopeOneItemScorer.class);
config.bind(PreferenceDomain.class).to(new PreferenceDomain(1.0, 5.0, 1.0));
config.bind(UserHistorySummarizer.class).to(RatingVectorUserHistorySummarizer.class);
delimitedColumnEventFormat = new DelimitedColumnEventFormat(new RatingEventType());
delimitedColumnEventFormat.setDelimiter("\t");
delimitedColumnEventFormat.setHeaderLines(1);
delimitedColumnEventFormat.setFields(Fields.item(), Fields.user(), Fields.rating());
TextEventDAO textEventDAO = new TextEventDAO(new File(filePath), delimitedColumnEventFormat);
config.bind(EventDAO.class).to(textEventDAO);
LenskitRecommender rec;
try {
rec = LenskitRecommender.build(config);
irec = rec.getItemRecommender();
} catch (RecommenderBuildException e) {
logger.error("Recommender RecommenderBuildException {}", e.getStackTrace());
}
}
@Override
public List<ScoredId> recommend(long user, int n) {
return irec.recommend(user, n);
}
}