Jean-Francois Leveque

Ajout des recommandations. Problème de packaging Spring. J'ai une NPE, je m'en occupe demain.

......@@ -25,6 +25,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
......
package org.legrog.recommendation.postprocess;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@SpringBootApplication
public class PostprocessingApplication {
Logger logger = LoggerFactory.getLogger(getClass());
@Value("${parameters.filename}")
String parametersFilename;
@Value("${data.dir}")
String dataDir;
@Value("${collectionSample.filename}")
String collectionSampleFilename;
@Value("${ratingSample.filename}")
String ratingSampleFilename;
String sampleFilename;
Properties properties;
Set<Long> sampleItemIds;
Set<Long> sampleUserIds;
HashMap<Long, Set<Long>> sampleItemUserIds;
public static void main(String[] args) {
SpringApplication.run(PostprocessingApplication.class, args);
}
@Bean
public CommandLineRunner postprocess() {
return (args) -> this.run();
}
public void run() {
loadParametersProperties();
loadSampleFilename();
analyzeSample();
}
void analyzeSample() {
Reader in = null;
try {
sampleItemIds = new HashSet<>();
sampleUserIds = new HashSet<>();
sampleItemUserIds = new HashMap<>();
//
in = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(dataDir + sampleFilename));
Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
for (CSVRecord record : records) {
Long itemId = Long.parseLong(record.get("itemId"));
Long userId = Long.parseLong(record.get("userId"));
sampleItemIds.add(itemId);
sampleUserIds.add(userId);
if (!sampleItemUserIds.containsKey(itemId)) {
Set<Long> set = sampleItemUserIds.get(itemId);
// NPE !!!
set.add(userId);
sampleItemUserIds.put(itemId, set);
} else {
Set<Long> set = new HashSet<>();
set.add(userId);
sampleItemUserIds.put(itemId, set);
}
}
logger.trace("Nombre d'objets recommandables {}", sampleItemIds.size());
logger.trace("Taille de la matrice item-user {}", sampleItemIds.size() * sampleUserIds.size());
int sampleCoupleCount = 0;
for (Long itemId : sampleItemIds) {
sampleCoupleCount += sampleItemUserIds.get(itemId).size();
}
logger.trace("Nombre de couples item-user dans l'échantillon {}", sampleCoupleCount);
} catch (IOException e) {
e.printStackTrace();
}
}
void loadSampleFilename() {
if (!properties.containsKey("ratings")) {
return;
} else {
logger.trace("ratings {}", properties.getProperty("ratings"));
if (Boolean.parseBoolean(properties.getProperty("ratings"))) {
sampleFilename = ratingSampleFilename;
} else {
sampleFilename = collectionSampleFilename;
}
logger.trace("sampleFilename {}", sampleFilename);
}
}
void loadParametersProperties() {
Properties properties = new Properties();
InputStream in = null;
try {
in = this.getClass().getClassLoader().getResourceAsStream(dataDir + parametersFilename);
// in = new FileInputStream(dataDir + parametersFilename);
properties.load(in);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.properties = properties;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.legrog" level="DEBUG"/>
<logger name="org.legrog.recommendation.postprocess" level="TRACE"/>
<root level="warn">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
......@@ -19,6 +19,7 @@
<module>grog-entities</module>
<module>grog-webapp</module>
<module>grog-db-generator</module>
<module>grog-recommendation</module>
</modules>
<properties>
......