Jean-Francois Leveque

En cas d'annotation, calcul de recommandation seulement pour les utilisateurs annotés.

......@@ -30,21 +30,35 @@ public class ProcessingRunner implements ApplicationRunner {
@Value("${ratingSample.filename}")
private String ratingSampleFilename;
@Value("${collectionAnnotated.filename}")
private String collectionAnnotatedFilename;
@Value("${ratingAnnotated.filename}")
private String ratingAnnotatedFilename;
@Value("${recommandations.filename}")
private String recommandationsFilename;
private String sampleFilename;
private String annotatedFilename;
private String algorithm;
private Recommender recommender;
private int topSize;
private int annotatePercent;
@Override
public void run(ApplicationArguments args) throws Exception {
loadParameters();
logger.trace("Parameters loaded");
List<Long> userIds = loadUserIdsFromSample();
List<Long> userIds;
if (annotatePercent > 0) {
userIds = loadUserIdsFromAnnotated();
} else {
userIds = loadUserIdsFromSample();
}
RecommenderFactory recommenderFactory = new RecommenderFactory();
recommender = recommenderFactory.build(algorithm ,dataDir+sampleFilename);
logger.trace("Recommender built");
......@@ -55,6 +69,30 @@ public class ProcessingRunner implements ApplicationRunner {
logger.trace("Recommendations written");
}
private List<Long> loadUserIdsFromAnnotated() throws ProcessingException {
List<Long> userIds = new ArrayList<>();
Reader in = null;
try {
in = new FileReader(dataDir+annotatedFilename);
Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
Long tmpLong;
for (CSVRecord record : records) {
tmpLong = Long.parseLong(record.get("userId"));
if (! userIds.contains(tmpLong)) {
userIds.add(tmpLong);
}
}
} catch (FileNotFoundException e) {
throw new ProcessingException("annotated file not found : {} " + dataDir + annotatedFilename, e);
} catch (IOException e) {
throw new ProcessingException("Can't read user ids from annotated file : {} " + dataDir + annotatedFilename, e);
}
logger.trace("Nombre d'utilisateurs : {}", userIds.size());
return userIds;
}
private List<Long> loadUserIdsFromSample() throws ProcessingException {
List<Long> userIds = new ArrayList<>();
......@@ -112,16 +150,32 @@ public class ProcessingRunner implements ApplicationRunner {
try (InputStream in = new FileInputStream(new File(dataDir, parametersFilename))) {
Properties properties = new Properties();
properties.load(in);
if (properties.containsKey("annotatePercent")) {
annotatePercent = Integer.parseInt(properties.getProperty("annotatePercent"));
} else {
// default annotate percent is 0
annotatePercent = 0;
}
if (properties.containsKey("ratings")) {
logger.trace("ratings {}", properties.getProperty("ratings"));
if (Boolean.parseBoolean(properties.getProperty("ratings"))) {
sampleFilename = ratingSampleFilename;
if (annotatePercent > 0) {
annotatedFilename = ratingAnnotatedFilename;
}
} else {
sampleFilename = collectionSampleFilename;
if (annotatePercent > 0) {
annotatedFilename = collectionAnnotatedFilename;
}
}
} else {
// by default, takes collection
sampleFilename = collectionSampleFilename;
if (annotatePercent > 0) {
annotatedFilename = collectionAnnotatedFilename;
}
}
if (properties.containsKey("algorithm")) {
algorithm = properties.getProperty("algorithm");
......