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-05-18 11:58:44 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
689bd081d62c3db2c833f44f780fe242b8e4389d
689bd081
1 parent
3aa413f5
En cas d'annotation, calcul de recommandation seulement pour les utilisateurs annotés.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletions
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/ProcessingRunner.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/ProcessingRunner.java
View file @
689bd08
...
...
@@ -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"
);
...
...
Please
register
or
login
to post a comment