Skip to content

Commit b7710c8

Browse files
committed
added entity recommender engine
1 parent 9d54720 commit b7710c8

11 files changed

+72
-162
lines changed

src/engine/BaseLevelLearningEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void loadFile(String filename) throws Exception {
8989
resetStructures(userMaps, resMaps, reader, topTags, matrix, userCounts, resCounts);
9090
}
9191

92-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm) {
92+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
9393
if (count == null || count.doubleValue() < 1) {
9494
count = 10;
9595
}
@@ -112,7 +112,7 @@ public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, S
112112
resultMap.put(entry.getKey(), entry.getValue().doubleValue());
113113
}
114114
}
115-
if (algorithm == null || algorithm == Algorithm.BLLac || algorithm == Algorithm.BLLacMPr) {
115+
if (resCountMap != null && (algorithm == null || algorithm == Algorithm.BLLac || algorithm == Algorithm.BLLacMPr)) {
116116
Map<Integer, Double> associativeValues = this.rMatrix.calculateAssociativeComponentsWithTagAssosiation(userCountMap, resCountMap, false, true, false);
117117
for (Map.Entry<Integer, Double> entry : associativeValues.entrySet()) {
118118
Double val = resultMap.get(entry.getKey());

src/engine/EngineInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ public interface EngineInterface {
2727

2828
public void loadFile(String filename) throws Exception;
2929

30-
public Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm);
30+
public Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type);
3131
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package engine;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
public class EntityRecommenderEngine implements EngineInterface {
7+
8+
private EngineInterface tagRecommender;
9+
private EngineInterface resourceRecommender;
10+
private EngineInterface userRecommender;
11+
12+
public void loadFile(String filename) throws Exception {
13+
this.tagRecommender = new TagRecommenderEvalEngine();
14+
this.tagRecommender.loadFile(filename);
15+
this.resourceRecommender = new ResourceRecommenderEngine();
16+
this.resourceRecommender.loadFile(filename);
17+
this.userRecommender = new UserRecommenderEngine();
18+
this.userRecommender.loadFile(filename);
19+
}
20+
21+
public Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
22+
if (type == EntityType.TAG) {
23+
return tagRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
24+
} else if (type == EntityType.RESOURCE) {
25+
return resourceRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
26+
} else if (type == EntityType.USER) {
27+
return userRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
28+
}
29+
return null;
30+
}
31+
}

src/engine/LanguageModelEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void loadFile(String filename) throws Exception {
7474
resetStructures(userMaps, resMaps, reader, topTags);
7575
}
7676

77-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm) {
77+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
7878
if (count == null || count.doubleValue() < 1) {
7979
count = 10;
8080
}

src/engine/ResourceRecommenderEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void loadFile(String filename) throws Exception {
6060
resetStructure(reader, calculator, tagCalculator, cbCalculator, resCFCalculator, topResources);
6161
}
6262

63-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm) {
63+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
6464
if (count == null || count.doubleValue() < 1) {
6565
count = 10;
6666
}

src/engine/TagRecommenderEngine.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/engine/TagRecommenderEvalEngine.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@ public class TagRecommenderEvalEngine implements EngineInterface {
3333

3434
private EngineInterface lmEngine;
3535
private EngineInterface bllEngine;
36-
//private EngineInterface threelEngine;
37-
36+
//private EngineInterface threelEngine;
3837
//private Random random;
3938
private BufferedWriter bw;
4039

4140
public TagRecommenderEvalEngine() {
4241
this.lmEngine = null;
4342
this.bllEngine = null;
4443
//this.threelEngine = null;
45-
this.bw = null;
4644
//this.random = new Random();
45+
this.bw = null;
4746

4847
try {
4948
FileWriter writer = new FileWriter(new File("./data/tagrec_log.txt"), true);
@@ -74,7 +73,7 @@ public void loadFile(String filename) throws Exception {
7473
}
7574

7675
@Override
77-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm) {
76+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
7877
Map<String, Double> returnMap = null;
7978
String algorithmString = null;
8079

@@ -87,13 +86,13 @@ public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, S
8786
algorithmString = "BLL";
8887
}
8988
if (algorithmString != null) {
90-
returnMap = this.bllEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm);
89+
returnMap = this.bllEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
9190
}
9291
}
9392

9493
if (algorithmString == null) {
9594
algorithmString = "MPur";
96-
returnMap = this.lmEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm);
95+
returnMap = this.lmEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
9796
}
9897

9998
if (this.bw != null) {

src/engine/ThreeLayersEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void loadFile(String filename) throws Exception {
5454
resetStructure(reader, calculator, topTags);
5555
}
5656

57-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm) {
57+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
5858
if (count == null || count.doubleValue() < 1) {
5959
count = 10;
6060
}

src/engine/UserRecommenderEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void loadFile(String filename) throws Exception {
5959
resetStructure(reader, calculator, tagCalculator, cbCalculator, topUsers);
6060
}
6161

62-
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count,
63-
Boolean filterOwnEntities, Algorithm algorithm) {
62+
public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, String resource, List<String> topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
6463

6564
if (count == null || count.doubleValue() < 1) {
6665
count = 10;

src/processing/MalletCalculator.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public static BookmarkReader predictSample(String filename, int trainSize, int s
332332
return reader;
333333
}
334334

335-
public static void createSample(String filename, short numTopics, boolean tagRec, Integer creationTrainSize) {
335+
public static void createSample(String filename, short numTopics, boolean tagRec, int trainSize, boolean personalizedTopicCreation) {
336336
Timer timerThread = new Timer();
337337
MemoryThread memoryThread = new MemoryThread();
338338
timerThread.schedule(memoryThread, 0, MemoryThread.TIME_SPAN);
@@ -344,7 +344,8 @@ public static void createSample(String filename, short numTopics, boolean tagRec
344344
} else {
345345
TOPIC_THRESHOLD = 0.01;
346346
}
347-
347+
Integer creationTrainSize = (personalizedTopicCreation ? trainSize : null);
348+
348349
BookmarkReader reader = new BookmarkReader(creationTrainSize == null ? 0 : creationTrainSize.intValue(), false);
349350
reader.readFile(filename);
350351
int size = reader.getBookmarks().size();
@@ -360,14 +361,14 @@ public static void createSample(String filename, short numTopics, boolean tagRec
360361
}
361362
List<Bookmark> userSample = reader.getBookmarks().subList(0, size);
362363
BookmarkSplitter.writeSample(reader, userSample, outputFile, predictionValues);
363-
if (creationTrainSize != null) {
364-
List<Bookmark> trainUserSample = reader.getBookmarks().subList(0, creationTrainSize.intValue());
365-
List<int[]> trainPredictionValues = predictionValues.subList(0, creationTrainSize.intValue());
366-
List<Bookmark> testUserSample = reader.getBookmarks().subList(creationTrainSize.intValue(), size);
367-
List<int[]> testPredictionValues = predictionValues.subList(creationTrainSize.intValue(), size);
364+
//if (creationTrainSize != null) {
365+
List<Bookmark> trainUserSample = reader.getBookmarks().subList(0, trainSize);
366+
List<int[]> trainPredictionValues = predictionValues.subList(0, trainSize);
367+
List<Bookmark> testUserSample = reader.getBookmarks().subList(trainSize, size);
368+
List<int[]> testPredictionValues = predictionValues.subList(trainSize, size);
368369
BookmarkSplitter.writeSample(reader, trainUserSample, outputFile + "_train", trainPredictionValues);
369370
BookmarkSplitter.writeSample(reader, testUserSample, outputFile + "_test", testPredictionValues);
370-
}
371+
//}
371372

372373
timeString = PerformanceMeasurement.addMemoryMeasurement(timeString, false, memoryThread.getMaxMemory());
373374
timerThread.cancel();

0 commit comments

Comments
 (0)