From 5b495d441550cea4bd18d9987a4d4e2c6872c0e9 Mon Sep 17 00:00:00 2001 From: s119804 Date: Wed, 14 May 2014 12:59:20 +0200 Subject: --- nbproject/project.properties | 152 +++++++++++++++++++++---------------------- src/main/Analyzor.java | 22 ++++++- src/main/Main.java | 29 ++++++++- 3 files changed, 121 insertions(+), 82 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 361d440..19b5ca6 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,76 +1,76 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=Goldfarmer -application.vendor=maurice -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/Goldfarmer.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.7 -javac.target=1.7 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=main.Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -project.licensePath=./nbproject/licenseheader.txt -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Goldfarmer +application.vendor=maurice +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Goldfarmer.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=main.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.licensePath=./nbproject/licenseheader.txt +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test 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 unimap = new HashMap(); // Map for uni + HashMap bimap = new HashMap(); // 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(); + } + } } } -- cgit v1.2.1