Skip to content

Commit 70c93c2

Browse files
committed
updated eval engine for bits and pieces study
1 parent f7b8951 commit 70c93c2

4 files changed

Lines changed: 59 additions & 58 deletions

File tree

src/engine/TagRecommenderEvalEngine.java

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,34 @@ License, or (at your option) any later version.
3131

3232
public class TagRecommenderEvalEngine implements EngineInterface {
3333

34-
//private EngineInterface mpEngine;
34+
private EngineInterface lmEngine;
3535
private EngineInterface bllEngine;
36-
//private EngineInterface threelEngine;
36+
private EngineInterface threelEngine;
37+
private EngineInterface mpEngine;
38+
3739
//private Random random;
3840
private BufferedWriter bw;
3941

4042
public TagRecommenderEvalEngine() {
41-
//this.mpEngine = null;
43+
this.lmEngine = null;
4244
this.bllEngine = null;
43-
//this.threelEngine = null;
45+
this.threelEngine = null;
46+
this.mpEngine = null;
47+
4448
//this.random = new Random();
4549
this.bw = null;
4650
}
4751

4852
@Override
4953
public void loadFile(String path, String filename) throws Exception {
50-
//this.lmEngine = null;
51-
//this.bllEngine = null;
52-
//this.threelEngine = null;
53-
54-
//BookmarkReader reader = new BookmarkReader(0, false);
55-
//reader.readFile(filename);
56-
//if (reader.getCategories().size() > 0) {
57-
// this.threelEngine = new ThreeLayersEngine();
58-
// this.threelEngine.loadFile(filename);
59-
//}
60-
//if (reader.hasTimestamp()) {
61-
this.bllEngine = new BaseLevelLearningEngine();
62-
this.bllEngine.loadFile(path, filename);
63-
//}
64-
//this.lmEngine = new LanguageModelEngine();
65-
//this.lmEngine.loadFile(filename);
66-
67-
/* KnowBrain
68-
//if (filename.contains("group1") || filename.contains("group3")) {
69-
this.threelEngine = new ThreeLayersCollectiveEngine();
70-
this.threelEngine.loadFile(filename);
71-
//} else {
72-
this.bllEngine = new BaseLevelLearningCollectiveEngine();
73-
this.bllEngine.loadFile(filename);
74-
//}
75-
this.mpEngine = new MostPopularCollectiveEngine();
76-
this.mpEngine.loadFile(filename);
77-
*/
54+
this.lmEngine = new LanguageModelEngine();
55+
this.lmEngine.loadFile(path, filename);
56+
this.bllEngine = new BaseLevelLearningEngine();
57+
this.bllEngine.loadFile(path, filename);
58+
this.threelEngine = new ThreeLayersCollectiveEngine();
59+
this.threelEngine.loadFile(path, filename);
60+
this.mpEngine = new MostPopularCollectiveEngine();
61+
this.mpEngine.loadFile(path, filename);
7862

7963
try {
8064
String logFile = "";
@@ -95,23 +79,34 @@ public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, S
9579
Map<String, Double> returnMap = null;
9680
String algorithmString = null;
9781

98-
99-
if (this.bllEngine != null) {
100-
if (algorithm == null || algorithm == Algorithm.BLLacMPr) {
101-
algorithmString = "BLLacMPr";
102-
} else if (algorithm == Algorithm.BLLac) {
103-
algorithmString = "BLLac";
104-
} else if (algorithm == Algorithm.BLL) {
105-
algorithmString = "BLL";
106-
}
107-
if (algorithmString != null) {
82+
if (algorithm == Algorithm.BLLacMPr) {
83+
if (this.bllEngine != null) {
84+
algorithmString = Algorithm.BLLacMPr.name();
10885
returnMap = this.bllEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
10986
}
110-
}
111-
//if (algorithmString == null) {
112-
// algorithmString = "MPur";
113-
// returnMap = this.lmEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
114-
//}
87+
} else if (algorithm == Algorithm.MPur) {
88+
if (this.lmEngine != null) {
89+
algorithmString = Algorithm.MPur.name();
90+
returnMap = this.lmEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
91+
}
92+
} else if (algorithm == Algorithm.THREELcoll) {
93+
if (topics != null && topics.size() > 0) {
94+
if (this.threelEngine != null) {
95+
algorithmString = Algorithm.THREELcoll.name();
96+
returnMap = this.threelEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
97+
}
98+
} else {
99+
if (this.mpEngine != null) {
100+
algorithmString = Algorithm.THREELcoll.name();
101+
returnMap = this.mpEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
102+
}
103+
}
104+
} else {
105+
if (this.mpEngine != null) {
106+
algorithmString = Algorithm.MP.name();
107+
returnMap = this.mpEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
108+
}
109+
}
115110

116111
/* KnowBrain study
117112
if (algorithm == null || algorithm == Algorithm.THREELcoll || algorithm == Algorithm.THREEL) {

src/engine/ThreeLayersCollectiveEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, S
4444
if (user != null && userID != -1) {
4545
tagIDs = this.calculator.getRankedTagList(userID, -1, topicIDs, System.currentTimeMillis() / 1000.0, count.intValue(), false, false, true);
4646
} else {
47-
new LinkedHashMap<String, Double>();
47+
return new LinkedHashMap<String, Double>();
4848
}
4949
}
5050

src/processing/MetricsCalculator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ public static void writeAverageMetrics(String outputFile, int k, double size, bo
268268
bw.write(Double.toString((serendipitySum / size)).replace('.', ','));
269269
//}
270270

271+
if (k == 10) {
272+
System.out.println("nDCG@10: " + (nDCGSum / size));
273+
}
271274
if (endLine) {
272275
bw.write("\n");
273276
}

src/test/Pipeline.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public class Pipeline {
9191
// placeholder for the topic posfix
9292
private static String TOPIC_NAME = null;
9393
// placeholder for the used dataset
94-
private final static String DATASET = "lastfm";
95-
private final static String SUBDIR = "/core1";
94+
private final static String DATASET = "twitter";
95+
private final static String SUBDIR = "/researchers";
9696

9797
public static void main(String[] args) {
9898
System.out.println("TagRecommender:\n" + "" +
@@ -116,7 +116,7 @@ public static void main(String[] args) {
116116
//TOPIC_NAME = "lda_500";
117117
//startCfResourceCalculator(dir, path, 1, 20, false, true, false, false, Features.TOPICS);
118118

119-
//startSolrHashtagCalculator(dir, "http://kti-social:8938", "researcher", true, true, 24);
119+
//startSolrHashtagCalculator(dir, "http://kti-social:8938", "researcher", false, true, 24);
120120

121121
//BibsonomyProcessor.processUnsortedFile("dc09_core/test_core/", "tas", "dc09_sample_test");
122122
//MovielensProcessor.processFile("000_dataset_dump/tags.dat", "000_dataset_dump/movielens", "000_dataset_dump/ratings.dat");
@@ -134,13 +134,13 @@ public static void main(String[] args) {
134134
//startAllTagRecommenderApproaches(dir, path, true);
135135
//getTrainTestStatistics(path);
136136
//BookmarkSplitter.splitSample(dir + "/tweets", dir + "/twitter_sample", 1, 0, true, false, true, dir + "/white_user.txt");
137-
//try { getStatistics(path, false); } catch (Exception e) { e.printStackTrace(); }
137+
//try { getStatistics("sss-eval", false); } catch (Exception e) { e.printStackTrace(); }
138138
//BookmarkSplitter.drawUserPercentageSample("bib_core/vedran/bib_bibtex", 5);
139139
//createLdaSamples("ml_core/resource/ml_sample", 1, 500, true, true);
140140

141141
// Method Testing -> just uncomment the methods you want to test
142142
// Test the BLL and BLL+MP_r algorithms (= baseline to beat :))
143-
//startActCalculator(dir, path, 1, -5, -5, false, CalculationType.NONE, false);
143+
//startActCalculator(dir, path, 1, 15, -5, false, CalculationType.NONE, false);
144144

145145
// Test the BLL_AC and BLL_AC+MP_r algorithms (could take a while)
146146

@@ -191,7 +191,7 @@ public static void main(String[] args) {
191191
//startSustainApproach(dir, path, 2.845, 0.5, 6.396, 0.0936, 0, 0, 20, 0.5);
192192

193193
// Engine Testing
194-
//startEngineTest("C:/", "sss_recomm.txt");
194+
//startEngineTest(null, "sss_recomm");
195195
//startKnowBrainTest("ml_group2");
196196

197197
// Commandline Arguments
@@ -554,10 +554,13 @@ private static void startEngineTest(String path, String filename) {
554554
} catch (Exception e) {
555555
e.printStackTrace();
556556
}
557-
System.out.println("Tags for user and resource: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", "http://sss.eu/31116473812357491143/", null, 10, false, null, EntityType.TAG)); // BLLac+MPr
558-
System.out.println("Tags for user: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", null, null, 10, false, null, EntityType.TAG)); // BLL
559-
System.out.println("Tags for resource: " + recEngine.getEntitiesWithLikelihood(null, "http://sss.eu/31116473812357491143/", null, 10, false, null, EntityType.TAG)); // MPr
560-
System.out.println("Tags MostPopular: " + recEngine.getEntitiesWithLikelihood(null, null, null, 10, false, null, EntityType.TAG)); // MP
557+
System.out.println("Tags for user and resource with BLLac+MPr: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", "http://sss.eu/31116473812357491143/", null, 10, false, Algorithm.BLLacMPr, EntityType.TAG)); // BLLac+MPr
558+
System.out.println("Tags for user and resource with MPur: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", "http://sss.eu/31116473812357491143/", null, 10, false, Algorithm.MPur, EntityType.TAG)); // MPur
559+
System.out.println("Tags with 3Lcoll: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", "http://sss.eu/31116473812357491143/", null, 10, false, Algorithm.THREELcoll, EntityType.TAG)); // BLLac+MPr
560+
System.out.println("Tags with MP: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", "http://sss.eu/31116473812357491143/", null, 10, false, Algorithm.MP, EntityType.TAG)); // MPur
561+
//System.out.println("Tags for user: " + recEngine.getEntitiesWithLikelihood("http://sss.eu/302875752153271240/", null, null, 10, false, null, EntityType.TAG)); // BLL
562+
//System.out.println("Tags for resource: " + recEngine.getEntitiesWithLikelihood(null, "http://sss.eu/31116473812357491143/", null, 10, false, null, EntityType.TAG)); // MPr
563+
//System.out.println("Tags MostPopular: " + recEngine.getEntitiesWithLikelihood(null, null, null, 10, false, null, EntityType.TAG)); // MP
561564

562565
System.out.println("LD - Resources for user (Tags):" + recEngine.getEntitiesWithLikelihood("http://sss.eu/207091058105385/", null, null, 10, false, Algorithm.RESOURCETAGCB, EntityType.RESOURCE)); // CBtags
563566
System.out.println("Resources for user (CF): " + recEngine.getEntitiesWithLikelihood("http://sss.eu/207091058105385/", null, null, 10, false, null , EntityType.RESOURCE)); // CF

0 commit comments

Comments
 (0)