Class: Google::Cloud::Language::Annotation::Sentiment

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/language/annotation.rb

Overview

Represents the result of sentiment analysis.

Examples:

require "google/cloud/language"

language = Google::Cloud::Language.new

content = "Star Wars is a great movie. The Death Star is fearsome."
document = language.document content
annotation = document.annotate

sentiment = annotation.sentiment
sentiment.score #=> 0.10000000149011612
sentiment.magnitude #=> 1.100000023841858
sentiment.language #=> "en"

Instance Attribute Summary collapse

Instance Attribute Details

#languageString (readonly)

The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are supported.

Returns:

  • (String)

    the current value of language



1014
1015
1016
# File 'lib/google/cloud/language/annotation.rb', line 1014

def language
  @language
end

#magnitudeFloat (readonly)

A non-negative number in the [0, +inf] range, which represents the overall strength of emotion regardless of score (positive or negative). Unlike score, magnitude is not normalized; each expression of emotion within the text (both positive and negative) contributes to the text's magnitude (so longer text blocks may have greater magnitudes).

Returns:

  • (Float)

    the current value of magnitude



1014
1015
1016
# File 'lib/google/cloud/language/annotation.rb', line 1014

def magnitude
  @magnitude
end

#scoreFloat (readonly)

The overall emotional leaning of the text in the [-1.0, 1.0] range. Larger numbers represent more positive sentiments.

Returns:

  • (Float)

    the current value of score



1014
1015
1016
# File 'lib/google/cloud/language/annotation.rb', line 1014

def score
  @score
end

#sentencesArray<Sentence> (readonly)

The sentences returned by sentiment analysis.

Returns:

  • (Array<Sentence>)

    the current value of sentences



1014
1015
1016
# File 'lib/google/cloud/language/annotation.rb', line 1014

def sentences
  @sentences
end