Class: Google::Cloud::Language::Annotation::Sentence::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"

sentence = sentiment.sentences.first
sentence.sentiment.score #=> 0.699999988079071
sentence.sentiment.magnitude #=> 0.699999988079071

Instance Attribute Summary collapse

Instance Attribute Details

#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



485
486
487
# File 'lib/google/cloud/language/annotation.rb', line 485

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



485
486
487
# File 'lib/google/cloud/language/annotation.rb', line 485

def score
  @score
end