@SuppressWarnings("unused") private void fetchTweets(String company) { Twitter twitter = new TwitterFactory().getInstance(); Query query = new Query(company); query.setLang("en"); query.setRpp(100); try { List<TweetDTO> tweets = new ArrayList<TweetDTO>(); for (int i = 1; i < 10; i++) { query.setPage(i); QueryResult result = twitter.search(query); for (Tweet tweet : result.getTweets()) { TweetDTO dto = new TweetDTO(); dto.setTwitterId(Long.toString(tweet.getId())); dto.setText(tweet.getText()); dto.setDate(tweet.getCreatedAt()); dto.setCompanies(company); tweets.add(dto); } } new GoogleTweetDAO().storeTweet(tweets); } catch (TwitterException e) { } }
private void calculateSentiment( SentimentProcessingRequestDTO proreq, List<TweetDTO> list, int multiplicator) throws Exception { proreq.setTimestampDataFetched(System.currentTimeMillis()); if (list.size() > 0) { double i = 0; for (TweetDTO tweet : list) { for (int j = 0; j < multiplicator; j++) { i += wm.weightedClassify(tweet.getText()).getPolarity(); } } proreq.setSentiment(i / list.size() / multiplicator / 4); } else { proreq.setSentiment(0); } proreq.setNumberOfTweets(list.size() * multiplicator); proreq.setTimestampAnalyzed(System.currentTimeMillis()); GoogleProcessingRequestDAO.instance.saveRequest(proreq); }