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-06 16:57:20 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7c44eeed9bf03a1ed9ad831b2b49694134b28857
7c44eeed
1 parent
3f06357b
Création d'interface de recommandation et de 4 implémentations
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
292 additions
and
0 deletions
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/CosineRecommender.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/FunkSVDRecommender.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/PearsonRecommender.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/Recommender.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/SlopeOneRecommender.java
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/CosineRecommender.java
0 → 100644
View file @
7c44eee
package
org
.
legrog
.
recommendation
.
process
;
import
org.grouplens.lenskit.GlobalItemScorer
;
import
org.grouplens.lenskit.ItemRecommender
;
import
org.grouplens.lenskit.ItemScorer
;
import
org.grouplens.lenskit.RecommenderBuildException
;
import
org.grouplens.lenskit.baseline.BaselineScorer
;
import
org.grouplens.lenskit.core.LenskitConfiguration
;
import
org.grouplens.lenskit.core.LenskitRecommender
;
import
org.grouplens.lenskit.data.dao.EventDAO
;
import
org.grouplens.lenskit.data.history.LikeCountUserHistorySummarizer
;
import
org.grouplens.lenskit.data.history.UserHistorySummarizer
;
import
org.grouplens.lenskit.data.pref.PreferenceDomain
;
import
org.grouplens.lenskit.data.text.DelimitedColumnEventFormat
;
import
org.grouplens.lenskit.data.text.Fields
;
import
org.grouplens.lenskit.data.text.LikeEventType
;
import
org.grouplens.lenskit.data.text.TextEventDAO
;
import
org.grouplens.lenskit.knn.item.ItemItemGlobalScorer
;
import
org.grouplens.lenskit.knn.item.ItemItemScorer
;
import
org.grouplens.lenskit.knn.item.ItemSimilarity
;
import
org.grouplens.lenskit.knn.item.ItemVectorSimilarity
;
import
org.grouplens.lenskit.scored.ScoredId
;
import
org.grouplens.lenskit.vectors.similarity.CosineVectorSimilarity
;
import
org.grouplens.lenskit.vectors.similarity.VectorSimilarity
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.util.List
;
public
class
CosineRecommender
implements
Recommender
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
LenskitConfiguration
config
;
DelimitedColumnEventFormat
delimitedColumnEventFormat
;
ItemRecommender
irec
;
@Override
public
void
Recommender
(
String
filePath
)
{
config
=
new
LenskitConfiguration
();
config
.
bind
(
ItemScorer
.
class
).
to
(
ItemItemScorer
.
class
);
config
.
bind
(
GlobalItemScorer
.
class
).
to
(
ItemItemGlobalScorer
.
class
);
config
.
bind
(
BaselineScorer
.
class
,
ItemScorer
.
class
).
to
(
ItemItemScorer
.
class
);
config
.
bind
(
PreferenceDomain
.
class
).
to
(
new
PreferenceDomain
(
0
,
1
));
config
.
bind
(
ItemSimilarity
.
class
).
to
(
ItemVectorSimilarity
.
class
);
config
.
bind
(
VectorSimilarity
.
class
).
to
(
CosineVectorSimilarity
.
class
);
config
.
bind
(
UserHistorySummarizer
.
class
).
to
(
LikeCountUserHistorySummarizer
.
class
);
delimitedColumnEventFormat
=
new
DelimitedColumnEventFormat
(
new
LikeEventType
());
delimitedColumnEventFormat
.
setDelimiter
(
"\t"
);
delimitedColumnEventFormat
.
setHeaderLines
(
1
);
delimitedColumnEventFormat
.
setFields
(
Fields
.
item
(),
Fields
.
user
());
TextEventDAO
textEventDAO
=
new
TextEventDAO
(
new
File
(
filePath
),
delimitedColumnEventFormat
);
config
.
bind
(
EventDAO
.
class
).
to
(
textEventDAO
);
LenskitRecommender
rec
;
try
{
rec
=
LenskitRecommender
.
build
(
config
);
irec
=
rec
.
getItemRecommender
();
}
catch
(
RecommenderBuildException
e
)
{
logger
.
error
(
"Recommender RecommenderBuildException {}"
,
e
.
getStackTrace
());
}
}
@Override
public
List
<
ScoredId
>
recommend
(
long
user
,
int
n
)
{
return
irec
.
recommend
(
user
,
n
);
}
}
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/FunkSVDRecommender.java
0 → 100644
View file @
7c44eee
package
org
.
legrog
.
recommendation
.
process
;
import
org.grouplens.lenskit.GlobalItemScorer
;
import
org.grouplens.lenskit.ItemRecommender
;
import
org.grouplens.lenskit.ItemScorer
;
import
org.grouplens.lenskit.RecommenderBuildException
;
import
org.grouplens.lenskit.baseline.BaselineScorer
;
import
org.grouplens.lenskit.core.LenskitConfiguration
;
import
org.grouplens.lenskit.core.LenskitRecommender
;
import
org.grouplens.lenskit.data.dao.EventDAO
;
import
org.grouplens.lenskit.data.history.RatingVectorUserHistorySummarizer
;
import
org.grouplens.lenskit.data.history.UserHistorySummarizer
;
import
org.grouplens.lenskit.data.pref.PreferenceDomain
;
import
org.grouplens.lenskit.data.text.DelimitedColumnEventFormat
;
import
org.grouplens.lenskit.data.text.Fields
;
import
org.grouplens.lenskit.data.text.RatingEventType
;
import
org.grouplens.lenskit.data.text.TextEventDAO
;
import
org.grouplens.lenskit.knn.item.ItemItemGlobalScorer
;
import
org.grouplens.lenskit.mf.funksvd.FunkSVDItemScorer
;
import
org.grouplens.lenskit.scored.ScoredId
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.util.List
;
public
class
FunkSVDRecommender
implements
Recommender
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
LenskitConfiguration
config
;
DelimitedColumnEventFormat
delimitedColumnEventFormat
;
ItemRecommender
irec
;
@Override
public
void
Recommender
(
String
filePath
)
{
config
=
new
LenskitConfiguration
();
config
.
bind
(
ItemScorer
.
class
).
to
(
FunkSVDItemScorer
.
class
);
config
.
bind
(
GlobalItemScorer
.
class
).
to
(
ItemItemGlobalScorer
.
class
);
config
.
bind
(
BaselineScorer
.
class
,
ItemScorer
.
class
).
to
(
FunkSVDItemScorer
.
class
);
config
.
bind
(
PreferenceDomain
.
class
).
to
(
new
PreferenceDomain
(
1.0
,
5.0
,
1.0
));
config
.
bind
(
UserHistorySummarizer
.
class
).
to
(
RatingVectorUserHistorySummarizer
.
class
);
delimitedColumnEventFormat
=
new
DelimitedColumnEventFormat
(
new
RatingEventType
());
delimitedColumnEventFormat
.
setDelimiter
(
"\t"
);
delimitedColumnEventFormat
.
setHeaderLines
(
1
);
delimitedColumnEventFormat
.
setFields
(
Fields
.
item
(),
Fields
.
user
(),
Fields
.
rating
());
TextEventDAO
textEventDAO
=
new
TextEventDAO
(
new
File
(
filePath
),
delimitedColumnEventFormat
);
config
.
bind
(
EventDAO
.
class
).
to
(
textEventDAO
);
LenskitRecommender
rec
;
try
{
rec
=
LenskitRecommender
.
build
(
config
);
irec
=
rec
.
getItemRecommender
();
}
catch
(
RecommenderBuildException
e
)
{
logger
.
error
(
"Recommender RecommenderBuildException {}"
,
e
.
getStackTrace
());
}
}
@Override
public
List
<
ScoredId
>
recommend
(
long
user
,
int
n
)
{
return
irec
.
recommend
(
user
,
n
);
}
}
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/PearsonRecommender.java
0 → 100644
View file @
7c44eee
package
org
.
legrog
.
recommendation
.
process
;
import
org.grouplens.lenskit.GlobalItemScorer
;
import
org.grouplens.lenskit.ItemRecommender
;
import
org.grouplens.lenskit.ItemScorer
;
import
org.grouplens.lenskit.RecommenderBuildException
;
import
org.grouplens.lenskit.baseline.BaselineScorer
;
import
org.grouplens.lenskit.core.LenskitConfiguration
;
import
org.grouplens.lenskit.core.LenskitRecommender
;
import
org.grouplens.lenskit.data.dao.EventDAO
;
import
org.grouplens.lenskit.data.history.LikeCountUserHistorySummarizer
;
import
org.grouplens.lenskit.data.history.UserHistorySummarizer
;
import
org.grouplens.lenskit.data.pref.PreferenceDomain
;
import
org.grouplens.lenskit.data.text.DelimitedColumnEventFormat
;
import
org.grouplens.lenskit.data.text.Fields
;
import
org.grouplens.lenskit.data.text.LikeEventType
;
import
org.grouplens.lenskit.data.text.TextEventDAO
;
import
org.grouplens.lenskit.knn.item.ItemItemGlobalScorer
;
import
org.grouplens.lenskit.knn.item.ItemItemScorer
;
import
org.grouplens.lenskit.knn.item.ItemSimilarity
;
import
org.grouplens.lenskit.knn.item.ItemVectorSimilarity
;
import
org.grouplens.lenskit.scored.ScoredId
;
import
org.grouplens.lenskit.vectors.similarity.PearsonCorrelation
;
import
org.grouplens.lenskit.vectors.similarity.VectorSimilarity
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.util.List
;
public
class
PearsonRecommender
implements
Recommender
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
LenskitConfiguration
config
;
DelimitedColumnEventFormat
delimitedColumnEventFormat
;
ItemRecommender
irec
;
@Override
public
void
Recommender
(
String
filePath
)
{
config
=
new
LenskitConfiguration
();
config
.
bind
(
ItemScorer
.
class
).
to
(
ItemItemScorer
.
class
);
config
.
bind
(
GlobalItemScorer
.
class
).
to
(
ItemItemGlobalScorer
.
class
);
config
.
bind
(
BaselineScorer
.
class
,
ItemScorer
.
class
).
to
(
ItemItemScorer
.
class
);
config
.
bind
(
PreferenceDomain
.
class
).
to
(
new
PreferenceDomain
(
0
,
1
));
config
.
bind
(
ItemSimilarity
.
class
).
to
(
ItemVectorSimilarity
.
class
);
config
.
bind
(
VectorSimilarity
.
class
).
to
(
PearsonCorrelation
.
class
);
config
.
bind
(
UserHistorySummarizer
.
class
).
to
(
LikeCountUserHistorySummarizer
.
class
);
delimitedColumnEventFormat
=
new
DelimitedColumnEventFormat
(
new
LikeEventType
());
delimitedColumnEventFormat
.
setDelimiter
(
"\t"
);
delimitedColumnEventFormat
.
setHeaderLines
(
1
);
delimitedColumnEventFormat
.
setFields
(
Fields
.
item
(),
Fields
.
user
());
TextEventDAO
textEventDAO
=
new
TextEventDAO
(
new
File
(
filePath
),
delimitedColumnEventFormat
);
config
.
bind
(
EventDAO
.
class
).
to
(
textEventDAO
);
LenskitRecommender
rec
;
try
{
rec
=
LenskitRecommender
.
build
(
config
);
irec
=
rec
.
getItemRecommender
();
}
catch
(
RecommenderBuildException
e
)
{
logger
.
error
(
"Recommender RecommenderBuildException {}"
,
e
.
getStackTrace
());
}
}
@Override
public
List
<
ScoredId
>
recommend
(
long
user
,
int
n
)
{
return
irec
.
recommend
(
user
,
n
);
}
}
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/Recommender.java
0 → 100644
View file @
7c44eee
package
org
.
legrog
.
recommendation
.
process
;
import
org.grouplens.lenskit.scored.ScoredId
;
import
java.util.List
;
public
interface
Recommender
{
void
Recommender
(
String
filePath
);
List
<
ScoredId
>
recommend
(
long
user
,
int
n
);
}
grog-recommendation/grog-recommendation-process/src/main/java/org/legrog/recommendation/process/SlopeOneRecommender.java
0 → 100644
View file @
7c44eee
package
org
.
legrog
.
recommendation
.
process
;
import
org.grouplens.lenskit.GlobalItemScorer
;
import
org.grouplens.lenskit.ItemRecommender
;
import
org.grouplens.lenskit.ItemScorer
;
import
org.grouplens.lenskit.RecommenderBuildException
;
import
org.grouplens.lenskit.baseline.BaselineScorer
;
import
org.grouplens.lenskit.core.LenskitConfiguration
;
import
org.grouplens.lenskit.core.LenskitRecommender
;
import
org.grouplens.lenskit.data.dao.EventDAO
;
import
org.grouplens.lenskit.data.history.RatingVectorUserHistorySummarizer
;
import
org.grouplens.lenskit.data.history.UserHistorySummarizer
;
import
org.grouplens.lenskit.data.pref.PreferenceDomain
;
import
org.grouplens.lenskit.data.text.*
;
import
org.grouplens.lenskit.knn.item.ItemItemGlobalScorer
;
import
org.grouplens.lenskit.scored.ScoredId
;
import
org.grouplens.lenskit.slopeone.SlopeOneItemScorer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.util.List
;
public
class
SlopeOneRecommender
implements
Recommender
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
LenskitConfiguration
config
;
DelimitedColumnEventFormat
delimitedColumnEventFormat
;
ItemRecommender
irec
;
@Override
public
void
Recommender
(
String
filePath
)
{
config
=
new
LenskitConfiguration
();
config
.
bind
(
ItemScorer
.
class
).
to
(
SlopeOneItemScorer
.
class
);
config
.
bind
(
GlobalItemScorer
.
class
).
to
(
ItemItemGlobalScorer
.
class
);
config
.
bind
(
BaselineScorer
.
class
,
ItemScorer
.
class
).
to
(
SlopeOneItemScorer
.
class
);
config
.
bind
(
PreferenceDomain
.
class
).
to
(
new
PreferenceDomain
(
1.0
,
5.0
,
1.0
));
config
.
bind
(
UserHistorySummarizer
.
class
).
to
(
RatingVectorUserHistorySummarizer
.
class
);
delimitedColumnEventFormat
=
new
DelimitedColumnEventFormat
(
new
RatingEventType
());
delimitedColumnEventFormat
.
setDelimiter
(
"\t"
);
delimitedColumnEventFormat
.
setHeaderLines
(
1
);
delimitedColumnEventFormat
.
setFields
(
Fields
.
item
(),
Fields
.
user
(),
Fields
.
rating
());
TextEventDAO
textEventDAO
=
new
TextEventDAO
(
new
File
(
filePath
),
delimitedColumnEventFormat
);
config
.
bind
(
EventDAO
.
class
).
to
(
textEventDAO
);
LenskitRecommender
rec
;
try
{
rec
=
LenskitRecommender
.
build
(
config
);
irec
=
rec
.
getItemRecommender
();
}
catch
(
RecommenderBuildException
e
)
{
logger
.
error
(
"Recommender RecommenderBuildException {}"
,
e
.
getStackTrace
());
}
}
@Override
public
List
<
ScoredId
>
recommend
(
long
user
,
int
n
)
{
return
irec
.
recommend
(
user
,
n
);
}
}
Please
register
or
login
to post a comment