diff options
Diffstat (limited to 'src/main/Analyzor.java')
-rw-r--r-- | src/main/Analyzor.java | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 9c98a9d..5385a79 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -113,24 +113,33 @@ public class Analyzor { * @throws IOException */ public void sentimentAnalysis(String query) throws SQLException, IOException { - query(query); + NamedPreparedStatement tweetBrandStmt, updateRating; //read the lexicons readLexicon(); - //go to the start of te dataset - if (data == null) { - System.err.println("data is empty, try querying first"); - return; + // if you ever need to re-apply rating, use something like: + // UPDATE mentionsbrand SET rating = NULL WHERE ... + if (query.isEmpty()) { + query = "SELECT t.tweetid, t.text, b.brand FROM tweet t " + + "JOIN mentionsbrand b USING (tweetid) " + + "WHERE b.rating IS NULL"; } + tweetBrandStmt = new NamedPreparedStatement(connection, + query); + ResultSet tweetBrandResults = tweetBrandStmt.executeQuery(); + + updateRating = new NamedPreparedStatement(connection, + "UPDATE mentionsbrand SET rating = :rating " + + "WHERE tweetid = :tweetid AND brand = :brand"); Double value; String text; //for all tuples - while (data.next()) { + while (tweetBrandResults.next()) { //get the text - text = data.getString("text"); + text = tweetBrandResults.getString("text"); text = splitPunctToWords(text); // test is the tweet text you are going to analyze String[] words = text.split("\\s+"); // text splitted into separate words @@ -152,12 +161,10 @@ public class Analyzor { } } //insert the rating into the database - NamedPreparedStatement m_insertRating; - m_insertRating = new NamedPreparedStatement(connection, QueryUtils.insertRating); - QueryUtils.setInsertParams(m_insertRating, data.getLong("tweetid"), data.getString("brand"), (int) (positiverate * 10)); - m_insertRating.executeUpdate(); - //don't print the rate - //System.out.println(text + ": " + (int) (positiverate * 10)); + updateRating.setLong("tweetid", tweetBrandResults.getLong("tweetid")); + updateRating.setString("brand", tweetBrandResults.getString("brand")); + updateRating.setInt("rating", (int) (positiverate * 10)); + updateRating.executeUpdate(); } } |