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 = "Darth Vader is the best villain in Star Wars."
document = language.document content
annotation = document.annotate

sentiment = annotation.sentiment
sentiment.polarity #=> 1.0
sentiment.magnitude #=> 0.8999999761581421
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



597
598
599
# File 'lib/google/cloud/language/annotation.rb', line 597

def language
  @language
end

#magnitudeFloat (readonly)

A non-negative number in the [0, +inf] range, which represents the absolute magnitude of sentiment regardless of polarity (positive or negative).

Returns:

  • (Float)

    the current value of magnitude



597
598
599
# File 'lib/google/cloud/language/annotation.rb', line 597

def magnitude
  @magnitude
end

#polarityFloat (readonly)

Polarity of the sentiment in the [-1.0, 1.0] range. Larger numbers represent more positive sentiments.

Returns:

  • (Float)

    the current value of polarity



597
598
599
# File 'lib/google/cloud/language/annotation.rb', line 597

def polarity
  @polarity
end