From a39323f583e1878d3cdafed8de99b4614dab7682 Mon Sep 17 00:00:00 2001 From: s123188 Date: Sat, 31 May 2014 15:44:18 +0200 Subject: made a method for the posnegVisualizer --- nbproject/project.properties | 162 +++++++++++++++++++++---------------------- src/main/Analyzor.java | 78 +++++++++++++++++++-- 2 files changed, 152 insertions(+), 88 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index ab8ae05..b262ab6 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,81 +1,81 @@ -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= -file.reference.joda-time-2.3.jar=lib/joda-time-2.3.jar -file.reference.postgresql-9.3-1101.jdbc41.jar=lib/postgresql-9.3-1101.jdbc41.jar -includes=** -jar.compress=false -javac.classpath=\ - ${file.reference.joda-time-2.3.jar}:\ - ${file.reference.postgresql-9.3-1101.jdbc41.jar} -# 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}:\ - ${libs.junit_4.classpath} -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= +file.reference.joda-time-2.3.jar=lib/joda-time-2.3.jar +file.reference.postgresql-9.3-1101.jdbc41.jar=lib/postgresql-9.3-1101.jdbc41.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.joda-time-2.3.jar}:\ + ${file.reference.postgresql-9.3-1101.jdbc41.jar} +# 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}:\ + ${libs.junit_4.classpath} +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 b896f62..89a8403 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -188,7 +188,7 @@ public class Analyzor { while (data.next()) { //get brand - brand=data.getString("brand"); + brand = data.getString("brand"); //make hashmap for each brand if(!wordcloud.containsKey(brand)){ wordcloud.put(brand, new HashMap()); @@ -216,7 +216,7 @@ public class Analyzor { } } //print the words and their frequency in a csv file - mapToCSV(wordcloud, "wordcloud.csv", "brand,word,count"); + ssiMapToCSV(wordcloud, "wordcloud.csv", "brand,word,count"); } //generate csv for disco from the query @@ -284,8 +284,6 @@ public class Analyzor { } } - - //hashmap timezone, brand, amount HashMap> timeMap = new HashMap<>(); String timezone; @@ -299,6 +297,7 @@ public class Analyzor { timezone="other"; } brand = data.getString("brand"); + //if the timezone is already in the map if(timeMap.containsKey(timezone)){ //if the brand for that timezone is already in the map @@ -320,9 +319,55 @@ public class Analyzor { } } - //make the CSV out of the map - mapToCSV(timeMap, "timezone.csv", "timezone,brand,count"); + ssiMapToCSV(timeMap, "timezone.csv", "timezone,brand,count"); + } + + //gets the positivity of the tweets about a brand + //makes a csv file for posnegVisualizer + void posNeg(String query) throws SQLException, FileNotFoundException, UnsupportedEncodingException{ + query(query); + + String brand; + int rating; + int ratingInterval; + + int intervalSize = 10; + //brand, ratingInterval, amount + HashMap> posnegMap = new HashMap<>(); + /* + the rating interval is given by an integer, which is the result of the + tweets sentiment value divided by interval size rounded down. + This puts all data in boxes for the histogram. + */ + + while(data.next()){ + + brand = data.getString("brand"); + rating = data.getInt("rating"); + ratingInterval = rating/intervalSize; + + //if the brand is already in the map + if(posnegMap.containsKey(brand)){ + //if the brand for that brand is already in the map + if(posnegMap.get(brand).containsKey(ratingInterval)){ + //increment the amount + posnegMap.get(brand).put(ratingInterval, posnegMap.get(brand).get(ratingInterval) + 1); + } + //if the brand for that brand is not yet in the map + else{ + //make a new entry for that brand with amount = 1 + posnegMap.get(brand).put(ratingInterval, 1); + } + } + //if the brand is not yet in the map + else{ + //make a new hashmap for this map and fill it with the brand and the amount + posnegMap.put(brand, new HashMap()); + posnegMap.get(brand).put(ratingInterval, 1); + } + } + siiMapToCSV(posnegMap, "posneg.csv", "brand,ratingInterval,count"); } //replaces punctuation so it will be splitted @@ -347,7 +392,26 @@ public class Analyzor { //prints a hashmap into a csv for a html application //Hashmap> becomes key1, key2, value //only for String, String, Integer - void mapToCSV(HashMap> map, String fileName, String firstLine) + void ssiMapToCSV(HashMap> map, String fileName, String firstLine) + throws FileNotFoundException, UnsupportedEncodingException{ + + PrintWriter writer = new PrintWriter(fileName, "UTF-8"); + + writer.println(firstLine); + + //loop over brands + for(Entry en : map.entrySet()){ + //loop over words + for(Entry e : map.get(en.getKey()).entrySet()){ + writer.println(en.getKey() + "," + e.getKey() + "," + e.getValue()); + } + } + + writer.close(); + System.out.println("csv file made, please put it next to html file and run this"); + } + + void siiMapToCSV(HashMap> map, String fileName, String firstLine) throws FileNotFoundException, UnsupportedEncodingException{ PrintWriter writer = new PrintWriter(fileName, "UTF-8"); -- cgit v1.2.1