Skip to content

Commit bac74d3

Browse files
committed
fixed 3L for bits and pieces study
1 parent 515b083 commit bac74d3

14 files changed

+213
-55
lines changed

src/common/SolrConnector.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.apache.solr.common.SolrDocumentList;
1818
import org.apache.solr.common.params.MoreLikeThisParams;
1919

20+
import processing.hashtag.Tweet;
21+
2022
public class SolrConnector {
2123

2224
private SolrServer server;
@@ -47,6 +49,27 @@ public Map<String, Set<String>> getTweets() {
4749
return tweets;
4850
}
4951

52+
@SuppressWarnings("unchecked")
53+
public List<Tweet> getTweetObjects() {
54+
List<Tweet> tweetObjects = new ArrayList<Tweet>();
55+
56+
SolrQuery solrParams = new SolrQuery();
57+
solrParams.set("q", "*:*");
58+
solrParams.set("rows", Integer.MAX_VALUE);
59+
QueryResponse r = null;
60+
try {
61+
r = this.server.query(solrParams);
62+
SolrDocumentList docs = r.getResults();
63+
for (SolrDocument d : docs) {
64+
tweetObjects.add(new Tweet((String) d.get("id"), (String) d.get("userid"), (String) d.get("text"), (String) d.get("timestamp"), new HashSet<String>((List<String>) d.get("hashtags"))));
65+
}
66+
} catch (SolrServerException e) {
67+
e.printStackTrace();
68+
}
69+
70+
return tweetObjects;
71+
}
72+
5073
@SuppressWarnings("unchecked")
5174
public Map<String, Set<String>> getUserIDs() {
5275
Map<String, Set<String>> tweetIDs = new LinkedHashMap<String, Set<String>>();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package processing;
1+
package common;
22

33
public class TimeUtil {
44

src/engine/EngineUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class EngineUtils {
3939

4040
public static BookmarkReader getSortedBookmarkReader(String path, String filename) {
4141
BookmarkReader reader = new BookmarkReader(0, false);
42-
reader.readFile(path, filename);
42+
reader.readFile(path, filename);
4343
Collections.sort(reader.getBookmarks());
4444

4545
String sortedFile = filename + "_sorted";

src/engine/ThreeLayersCollectiveEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public synchronized Map<String, Double> getEntitiesWithLikelihood(String user, S
3030
List<Integer> topicIDs = new ArrayList<>();
3131
if (topics != null) {
3232
for (String t : topics) {
33-
int tID = this.reader.getCategories().indexOf(t);
33+
List<String> categories = this.reader.getCategories();
34+
int tID = categories.indexOf(t.toLowerCase());
3435
if (tID != -1) {
3536
topicIDs.add(tID);
3637
}

src/file/BookmarkReader.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ private boolean doReadFile(String path, String filename) {
131131
if (lineParts.length > 4) { // are there categories
132132
for (String cat : lineParts[4].replace("\"", "").split(",")) {
133133
if (!cat.isEmpty()) {
134-
if (cat.contains("_")) {
135-
categories.add(cat.substring(0, cat.indexOf("_")).toLowerCase());
136-
} else {
134+
//if (cat.contains("_")) {
135+
// categories.add(cat.substring(0, cat.indexOf("_")).toLowerCase());
136+
//} else {
137137
categories.add(cat.toLowerCase());
138-
}
138+
//}
139139
}
140140
}
141141
}
@@ -290,6 +290,10 @@ public List<Integer> getTagCounts() {
290290
return this.tagCounts;
291291
}
292292

293+
public Map<String, Integer> getTagMap() {
294+
return this.tagMap;
295+
}
296+
293297
public List<String> getResources() {
294298
return this.resources;
295299
}
@@ -306,6 +310,10 @@ public List<Integer> getUserCounts() {
306310
return this.userCounts;
307311
}
308312

313+
public Map<String, Integer> getUserMap() {
314+
return this.userMap;
315+
}
316+
309317
public int getCountLimit() {
310318
return this.countLimit;
311319
}

src/file/BookmarkWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private static boolean doWriteSample(BookmarkReader reader, List<Bookmark> userS
5151
i = 0;
5252
for (int cat : userCats) {
5353
//bw.write(URLEncoder.encode((catPredictions == null ? reader.getCategories().get(cat).replace("\"", "") : reader.getTags().get(cat)).replace("\"", ""), "UTF-8"));
54-
bw.write("t" + cat);
54+
String catName = (realValues ? reader.getCategories().get(cat).replace("\"", "") : "t" + cat);
55+
bw.write(catName);
5556
if (++i < userCats.size()) {
5657
bw.write(',');
5758
}

src/processing/MetricsCalculator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public MetricsCalculator(PredictionFileReader reader, String outputFile, int k,
7070
}
7171
BufferedWriter bw = null;
7272
//TODO: Enable if you need data for statistical tests
73+
/*
7374
if ((recommTags && (k == 5 || k == 10)) || (!recommTags && k == 20)) {
7475
try {
7576
FileWriter writer = new FileWriter(new File(outputFile + "_" + k + ".txt"), true);
@@ -78,6 +79,7 @@ public MetricsCalculator(PredictionFileReader reader, String outputFile, int k,
7879
e.printStackTrace();
7980
}
8081
}
82+
*/
8183

8284
//double count = this.reader.getPredictionCount(); // only user where there are recommendations
8385
double count = this.reader.getPredictionData().size(); // all users

src/processing/ThreeLTCalculator.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,24 @@ public Map<Integer, Double> getRankedTagList(int userID, int resID, List<Integer
179179

180180
public Map<Integer, Double> getCollectiveRankedTagList(List<Integer> testCats, double testTimestamp, int limit, boolean tagBLL, boolean topicBLL) {
181181
Map<Integer, Double> collectiveTagMap = new LinkedHashMap<Integer, Double>();
182-
for (int id = 0; id < this.reader.getUsers().size(); id++) {
183-
Map<Integer, Double> tagMap = getRankedTagList(id, -1, testCats, testTimestamp, limit, tagBLL, topicBLL, false);
184-
for (Map.Entry<Integer, Double> entry : tagMap.entrySet()) {
185-
Double val = collectiveTagMap.get(entry.getKey());
186-
collectiveTagMap.put(entry.getKey(), val == null ? entry.getValue() : val.doubleValue() + entry.getValue());
182+
183+
List<Bookmark> bookmarks = this.reader.getBookmarks();
184+
List<Map<Integer, Integer>> resTopics = Utilities.getResTopics(bookmarks);
185+
for (Bookmark b : bookmarks) {
186+
if (b.getResourceID() < resTopics.size()) {
187+
double sim = Utilities.getCosineSimList(testCats, new ArrayList<Integer>(resTopics.get(b.getResourceID()).keySet()));
188+
Double ajhid = Math.pow(sim, 3);
189+
if (ajhid.isNaN() || ajhid.isInfinite()) {
190+
ajhid = 0.0;
191+
System.out.println("Cos - NAN");
192+
}
193+
for (int t : b.getTags()) {
194+
Double tVal = collectiveTagMap.get(t);
195+
collectiveTagMap.put(t, tVal == null ? ajhid : tVal.doubleValue() + ajhid);
196+
}
187197
}
188198
}
189-
199+
190200
Map<Integer, Double> sortedResultMap = new TreeMap<Integer, Double>(new DoubleMapComparator(collectiveTagMap));
191201
sortedResultMap.putAll(collectiveTagMap);
192202
Map<Integer, Double> returnMap = new LinkedHashMap<Integer, Double>();

src/processing/ProcessFrequencyRecency.java renamed to src/processing/hashtag/ProcessFrequencyRecency.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package processing;
1+
package processing.hashtag;
22

33
import java.io.BufferedWriter;
44
import java.io.File;
@@ -10,6 +10,8 @@
1010
import java.util.HashSet;
1111
import java.util.List;
1212

13+
import common.TimeUtil;
14+
1315
/**
1416
* @author spujari
1517
*

src/processing/ProcessFrequencyRecencySocial.java renamed to src/processing/hashtag/ProcessFrequencyRecencySocial.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package processing;
1+
package processing.hashtag;
22

33
import java.io.BufferedWriter;
44
import java.io.File;
@@ -11,6 +11,8 @@
1111
import java.util.Collections;
1212
import java.util.HashMap;
1313

14+
import common.TimeUtil;
15+
1416
public class ProcessFrequencyRecencySocial {
1517

1618
private String sampleDir;

0 commit comments

Comments
 (0)