diff options
author | unknown <s123188@S123188.campus.tue.nl> | 2014-05-19 14:32:10 +0200 |
---|---|---|
committer | unknown <s123188@S123188.campus.tue.nl> | 2014-05-19 14:32:10 +0200 |
commit | f6e17a9aef795d196435fb559585f2ce60f4fa43 (patch) | |
tree | d72d9fdd4605c6a5d225a2e7552be0ea6efd65a6 | |
parent | 10a32f00d3bbe4b73adccdd522d4925e9e494582 (diff) | |
parent | c27cf394d7fca31d020eca39e311896338338819 (diff) | |
download | Goldfarmer-f6e17a9aef795d196435fb559585f2ce60f4fa43.tar.gz |
Merge branch 'master' of git@git.lekensteyn.nl:tue/2IOC0-DBL/Goldfarmer.git
Conflicts:
src/main/Analyzor.java
-rw-r--r-- | src/main/Analyzor.java | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 914fced..22ea6ec 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -12,6 +12,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; import java.util.HashMap; import java.util.Map.Entry; import java.util.Scanner; @@ -36,14 +37,14 @@ public class Analyzor { * The results of a query, maybe return from query(). */ private ResultSet data; - + /** * The persistent connection to the database. */ private final Connection connection; /** - * @param connection An open connection to the database. + * @param connection An open connection to the database. */ public Analyzor(Connection connection) { this.connection = connection; @@ -51,8 +52,8 @@ public class Analyzor { /** * Read the unigram and bigram lexica. - * - * @throws FileNotFoundException + * + * @throws FileNotFoundException */ public void readLexicon() throws FileNotFoundException { if (!unimap.isEmpty()) { @@ -66,18 +67,23 @@ public class Analyzor { try (Scanner uniScanner = new Scanner(new File("unigrams-pmilexicon.txt")); Scanner biScanner = new Scanner(new File("bigrams-pmilexicon.txt"));) { //Fill the map of unigrams + int lineno = 1; while (uniScanner.hasNext()) { + String words = uniScanner.next(); - unimap.put(words.toLowerCase(), uniScanner.nextDouble()); + Double d = Double.valueOf(uniScanner.next()); + unimap.put(words.toLowerCase(), d); if (uniScanner.hasNextLine()) { uniScanner.nextLine(); } + lineno++; + } //fill the map of bigrams while (biScanner.hasNext()) { String words = biScanner.next() + " " + biScanner.next(); - bimap.put(words.toLowerCase(), biScanner.nextDouble()); + bimap.put(words.toLowerCase(), Double.valueOf(biScanner.next())); if (biScanner.hasNextLine()) { biScanner.nextLine(); } @@ -157,11 +163,11 @@ public class Analyzor { /** * Make a wordcloud of the results of some query. - * + * * @param query The sql text for a query. * @throws SQLException * @throws FileNotFoundException - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException */ public void makeWordCloud(String query) throws SQLException, FileNotFoundException, UnsupportedEncodingException { @@ -223,7 +229,7 @@ public class Analyzor { writer.print(data.getObject(i).toString().replaceAll("[,\n]", " ") + ", "); } } - if(data.getObject(data.getMetaData().getColumnCount())==null){ + if (data.getObject(data.getMetaData().getColumnCount()) == null) { writer.println("0"); } else { writer.println(data.getObject(data.getMetaData().getColumnCount()).toString().replace(",", " ")); @@ -231,8 +237,8 @@ public class Analyzor { } writer.close(); } - - public void getBrands() throws SQLException{ + + public void getBrands() throws SQLException { PreparedStatement statement; //make a connection to the database and execute the query statement = connection.prepareStatement("delete from mentionsbrand"); @@ -240,11 +246,18 @@ public class Analyzor { BrandChecker checker = new BrandChecker("brandrules.txt"); query("select * from tweet"); NamedPreparedStatement m_insertBrand = new NamedPreparedStatement(connection, QueryUtils.insertBrand); - while(data.next()){ - for(String brand:checker.getBrands(data.getString("text"))){ - QueryUtils.setInsertBrandParams(m_insertBrand, data.getLong("tweetid"), brand); + while (data.next()) { + List<String> brands = checker.getBrands(data.getString("text")); + if (brands.isEmpty()) { + QueryUtils.setInsertBrandParams(m_insertBrand, data.getLong("tweetid"), "no"); m_insertBrand.executeUpdate(); + } else { + for (String brand : brands) { + QueryUtils.setInsertBrandParams(m_insertBrand, data.getLong("tweetid"), brand); + m_insertBrand.executeUpdate(); + } } + } } |