summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors119804 <s119804@S119804.campus.tue.nl>2014-05-14 12:59:20 +0200
committers119804 <s119804@S119804.campus.tue.nl>2014-05-14 12:59:20 +0200
commit5b495d441550cea4bd18d9987a4d4e2c6872c0e9 (patch)
tree750498a424c72158b618eede4e6bdf9b6a863573 /src
parent4fb6f7f9ca022b9a9106f60dfbf64600cff610b2 (diff)
downloadGoldfarmer-5b495d441550cea4bd18d9987a4d4e2c6872c0e9.tar.gz
Diffstat (limited to 'src')
-rw-r--r--src/main/Analyzor.java22
-rw-r--r--src/main/Main.java29
2 files changed, 45 insertions, 6 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java
index 73acd64..bc81440 100644
--- a/src/main/Analyzor.java
+++ b/src/main/Analyzor.java
@@ -11,7 +11,23 @@ package main;
* @author s123188
*/
public class Analyzor {
- //TODO: make botfilter
-
- //TODO: make sentiment analysis
+ // test is the tweet text you are going to analyze
+ String[] testlist = test.split("\\s+"); // text splitted into separate words
+ double positiverate = 0; // positive rating
+
+ for (String word : testlist) { // Rate the text with each word with uni
+ if (unimap.containsKey(word)) {
+ positiverate += unimap.get(word);
+ }
+ }
+
+ for (int i = 0; i < testlist.length-1; i++) { // Rate text with pair words with bi
+ String pair = testlist[i] + " " + testlist[i+1];
+ if (bimap.containsKey(pair)) {
+ positiverate += bimap.get(pair);
+ }
+ }
+
+ System.out.println(test + ": " + (int) (positiverate * 10));
+ // print rate as int. Alter to return if you like
}
diff --git a/src/main/Main.java b/src/main/Main.java
index 8155387..81b6df9 100644
--- a/src/main/Main.java
+++ b/src/main/Main.java
@@ -1,5 +1,10 @@
package main;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Scanner;
+
/**
* The main class containing the main method.
*
@@ -18,10 +23,28 @@ public class Main {
*/
- public static void main(String[] args) {
- // TODO: read lexicon
+public static void main(String[] args) throws FileNotFoundException {
+ HashMap<String, Double> unimap = new HashMap<String, Double>(); // Map for uni
+ HashMap<String, Double> bimap = new HashMap<String, Double>(); // Map for bi
+
+ File uniFile = new File("unigrams-pmilexicon.txt"); // scan uni
+ Scanner uniScanner = new Scanner(uniFile);
+ File biFile = new File("bigrams-pmilexicon.txt"); // scan bi
+ Scanner biScanner = new Scanner(biFile);
- // TODO: choose query
+ while (uniScanner.hasNext()) { // Set up map with uni
+ unimap.put(uniScanner.next(), Double.parseDouble(uniScanner.next()));
+ if (uniScanner.hasNextLine()) {
+ uniScanner.nextLine();
+ }
+ }
+
+ while (biScanner.hasNext()) { // Set up map with bi
+ bimap.put(biScanner.next() + " " + biScanner.next(), Double.parseDouble(biScanner.next()));
+ if (biScanner.hasNextLine()) {
+ biScanner.nextLine();
+ }
+ }
}
}