Sentiments Docs
Fall 2025
API

# SentimentAnalyzer

o1.sentiment.SentimentAnalyzer
See the SentimentAnalyzer companion object
class 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.

## Attributes

Companion
  object
Graph
Supertypes
  class Object
  trait Matchable
  class Any

## Members list

### 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.

## Parameters

wordOrPhrase

  a (short) piece of text to be analyzed

## Attributes

Returns

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