SentimentAnalyzer

An instance of this class is a “sentiment analyzer” taught on a corpus of texts whose sentiments have been appraised and annotated by a human. Given a roughly similar piece of text as those that appear in its training data, the analyzer can assign the text a numerical rating that reflects how positive or negative it is; see the rate method.

The SentimentAnalyzer companion object provides methods for initializing analyzer objects from training data.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def rate(wordOrPhrase: String): Option[Double]

Given a short piece of text, returns a numerical estimate of how positive or negative it is. The estimate is based on whether the words in the given text tend to appear in positive or negative texts previously familiar to the analyzer from its training data.

Given a short piece of text, returns a numerical estimate of how positive or negative it is. The estimate is based on whether the words in the given text tend to appear in positive or negative texts previously familiar to the analyzer from its training data.

The analysis method is quite straightforward: the rating assigned to the given sentiment is simply the average of the rating of each individual word in it. Those word ratings in turn are the averages of the human-rated texts in which they appear in the training data.

Value parameters:
wordOrPhrase

a (short) piece of text to be analyzed

Returns:

a numerical rating between -2.0 and +2.0. Positive values suggest positive sentiments. None is returned in case none of the words in wordOrPhrase appear in the training data and no rating can therefore be determined.