Toggle navigation
Toggle navigation
This project
Loading...
Sign in
grogv3
/
grog-cubi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Francois Leveque
2017-04-04 16:53:55 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
880af9ef2ee1af3ed8c4dc69212f33a8376fc6e1
880af9ef
1 parent
16a857a3
Ajout des recommandations. Problème de packaging Spring. J'ai une NPE, je m'en occupe demain.
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
0 deletions
grog-recommendation/grog-recommendation-postprocess/pom.xml
grog-recommendation/grog-recommendation-postprocess/src/main/java/org/legrog/recommendation/postprocess/PostprocessingApplication.java
grog-recommendation/grog-recommendation-postprocess/src/main/resources/dumb/EchantillonCollection.csv
grog-recommendation/grog-recommendation-postprocess/src/main/resources/logback.xml
pom.xml
grog-recommendation/grog-recommendation-postprocess/pom.xml
View file @
880af9e
...
...
@@ -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>
...
...
grog-recommendation/grog-recommendation-postprocess/src/main/java/org/legrog/recommendation/postprocess/PostprocessingApplication.java
0 → 100644
View file @
880af9e
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
;
}
}
grog-recommendation/grog-recommendation-postprocess/src/main/resources/dumb/EchantillonCollection.csv
View file @
880af9e
itemId userId
1 1
2 2
...
...
grog-recommendation/grog-recommendation-postprocess/src/main/resources/logback.xml
0 → 100644
View file @
880af9e
<?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
pom.xml
View file @
880af9e
...
...
@@ -19,6 +19,7 @@
<module>
grog-entities
</module>
<module>
grog-webapp
</module>
<module>
grog-db-generator
</module>
<module>
grog-recommendation
</module>
</modules>
<properties>
...
...
Please
register
or
login
to post a comment