def loadScoreTs(stock, wordCounterTsFilename=TS_FILENAME): if wordCounterTsFilename not in wordCounters: wordCounters[wordCounterTsFilename] = Preprocess.loadTs(wordCounterTsFilename) wordCounterTs = wordCounters[wordCounterTsFilename] topicWordCountTs = wordCounterTs.getTopicTs(stock) return sent.getScoreTimeseries(topicWordCountTs)
def getDayScore(self, wordCount): positiveScore = 0 negativeScore = 0 for word, count in wordCount.iteritems(): # print word.encode(ignore), count wordDict = self.wl.getWordDict(word) if wordDict != None: if wordDict['polarity'] == POLARITY['positive']: positiveScore += count elif wordDict['polarity'] == POLARITY['negative']: negativeScore += count if negativeScore == 0: return float(positiveScore) return float(positiveScore) / negativeScore # Return the score timeseries as a list def getScoreTimeseries(self, wordCounterTs): return wordCounterTs.mapValues(self.getDayScore) if __name__ == '__main__': ts = Preprocess.loadTs() sent = SentimentAnalysis() t = time.clock() a = sent.getScoreTimeseries(TimeSeries(ts.getTopicTs('msft'))) print time.clock() - t