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 { ...@@ -30,21 +30,35 @@ public class ProcessingRunner implements ApplicationRunner {
30 @Value("${ratingSample.filename}") 30 @Value("${ratingSample.filename}")
31 private String ratingSampleFilename; 31 private String ratingSampleFilename;
32 32
33 + @Value("${collectionAnnotated.filename}")
34 + private String collectionAnnotatedFilename;
35 +
36 + @Value("${ratingAnnotated.filename}")
37 + private String ratingAnnotatedFilename;
38 +
33 @Value("${recommandations.filename}") 39 @Value("${recommandations.filename}")
34 private String recommandationsFilename; 40 private String recommandationsFilename;
35 41
36 private String sampleFilename; 42 private String sampleFilename;
43 + private String annotatedFilename;
37 private String algorithm; 44 private String algorithm;
38 45
39 private Recommender recommender; 46 private Recommender recommender;
40 47
41 private int topSize; 48 private int topSize;
49 + private int annotatePercent;
42 50
43 @Override 51 @Override
44 public void run(ApplicationArguments args) throws Exception { 52 public void run(ApplicationArguments args) throws Exception {
45 loadParameters(); 53 loadParameters();
46 logger.trace("Parameters loaded"); 54 logger.trace("Parameters loaded");
47 - List<Long> userIds = loadUserIdsFromSample(); 55 + List<Long> userIds;
56 + if (annotatePercent > 0) {
57 + userIds = loadUserIdsFromAnnotated();
58 + } else {
59 + userIds = loadUserIdsFromSample();
60 + }
61 +
48 RecommenderFactory recommenderFactory = new RecommenderFactory(); 62 RecommenderFactory recommenderFactory = new RecommenderFactory();
49 recommender = recommenderFactory.build(algorithm ,dataDir+sampleFilename); 63 recommender = recommenderFactory.build(algorithm ,dataDir+sampleFilename);
50 logger.trace("Recommender built"); 64 logger.trace("Recommender built");
...@@ -55,6 +69,30 @@ public class ProcessingRunner implements ApplicationRunner { ...@@ -55,6 +69,30 @@ public class ProcessingRunner implements ApplicationRunner {
55 logger.trace("Recommendations written"); 69 logger.trace("Recommendations written");
56 } 70 }
57 71
72 + private List<Long> loadUserIdsFromAnnotated() throws ProcessingException {
73 + List<Long> userIds = new ArrayList<>();
74 +
75 + Reader in = null;
76 + try {
77 + in = new FileReader(dataDir+annotatedFilename);
78 + Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
79 + Long tmpLong;
80 + for (CSVRecord record : records) {
81 + tmpLong = Long.parseLong(record.get("userId"));
82 + if (! userIds.contains(tmpLong)) {
83 + userIds.add(tmpLong);
84 + }
85 + }
86 + } catch (FileNotFoundException e) {
87 + throw new ProcessingException("annotated file not found : {} " + dataDir + annotatedFilename, e);
88 + } catch (IOException e) {
89 + throw new ProcessingException("Can't read user ids from annotated file : {} " + dataDir + annotatedFilename, e);
90 + }
91 +
92 + logger.trace("Nombre d'utilisateurs : {}", userIds.size());
93 + return userIds;
94 + }
95 +
58 private List<Long> loadUserIdsFromSample() throws ProcessingException { 96 private List<Long> loadUserIdsFromSample() throws ProcessingException {
59 List<Long> userIds = new ArrayList<>(); 97 List<Long> userIds = new ArrayList<>();
60 98
...@@ -112,16 +150,32 @@ public class ProcessingRunner implements ApplicationRunner { ...@@ -112,16 +150,32 @@ public class ProcessingRunner implements ApplicationRunner {
112 try (InputStream in = new FileInputStream(new File(dataDir, parametersFilename))) { 150 try (InputStream in = new FileInputStream(new File(dataDir, parametersFilename))) {
113 Properties properties = new Properties(); 151 Properties properties = new Properties();
114 properties.load(in); 152 properties.load(in);
153 + if (properties.containsKey("annotatePercent")) {
154 + annotatePercent = Integer.parseInt(properties.getProperty("annotatePercent"));
155 +
156 + } else {
157 + // default annotate percent is 0
158 + annotatePercent = 0;
159 + }
115 if (properties.containsKey("ratings")) { 160 if (properties.containsKey("ratings")) {
116 logger.trace("ratings {}", properties.getProperty("ratings")); 161 logger.trace("ratings {}", properties.getProperty("ratings"));
117 if (Boolean.parseBoolean(properties.getProperty("ratings"))) { 162 if (Boolean.parseBoolean(properties.getProperty("ratings"))) {
118 sampleFilename = ratingSampleFilename; 163 sampleFilename = ratingSampleFilename;
164 + if (annotatePercent > 0) {
165 + annotatedFilename = ratingAnnotatedFilename;
166 + }
119 } else { 167 } else {
120 sampleFilename = collectionSampleFilename; 168 sampleFilename = collectionSampleFilename;
169 + if (annotatePercent > 0) {
170 + annotatedFilename = collectionAnnotatedFilename;
171 + }
121 } 172 }
122 } else { 173 } else {
123 // by default, takes collection 174 // by default, takes collection
124 sampleFilename = collectionSampleFilename; 175 sampleFilename = collectionSampleFilename;
176 + if (annotatePercent > 0) {
177 + annotatedFilename = collectionAnnotatedFilename;
178 + }
125 } 179 }
126 if (properties.containsKey("algorithm")) { 180 if (properties.containsKey("algorithm")) {
127 algorithm = properties.getProperty("algorithm"); 181 algorithm = properties.getProperty("algorithm");
......