Class: Google::Cloud::Language::Annotation::Sentence

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

Overview

Represents a piece of text including relative location.

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

annotation.sentences.count #=> 2
sentence = annotation.sentences.first
sentence.text #=> "Star Wars is a great movie."
sentence.offset #=> 0

Defined Under Namespace

Classes: Sentiment

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sentimentSentence::Sentiment (readonly)

The sentence sentiment.

Returns:



366
367
368
# File 'lib/google/cloud/language/annotation.rb', line 366

def sentiment
  @sentiment
end

#text_spanTextSpan (readonly)

The sentence text.

Returns:

  • (TextSpan)

    the current value of text_span



366
367
368
# File 'lib/google/cloud/language/annotation.rb', line 366

def text_span
  @text_span
end

Instance Method Details

#magnitudeFloat

A non-negative number in the [0, +inf] range, which represents the absolute magnitude of sentiment regardless of score (positive or negative). See Google::Cloud::Language::Annotation::Sentence::Sentiment#magnitude.

Returns:

  • (Float)


423
424
425
426
# File 'lib/google/cloud/language/annotation.rb', line 423

def magnitude
  return nil unless sentiment?
  sentiment.magnitude
end

#offsetInteger Also known as: begin_offset

The API calculates the beginning offset of the content in the original document according to the encoding specified in the API request. See TextSpan#offset.

Returns:

  • (Integer)


393
394
395
# File 'lib/google/cloud/language/annotation.rb', line 393

def offset
  text_span.offset
end

#scoreFloat

Returns:

  • (Float)


411
412
413
414
# File 'lib/google/cloud/language/annotation.rb', line 411

def score
  return nil unless sentiment?
  sentiment.score
end

#sentiment?Boolean

Returns true if the Sentence has a Sentiment.

Returns:

  • (Boolean)


402
403
404
# File 'lib/google/cloud/language/annotation.rb', line 402

def sentiment?
  !sentiment.nil?
end

#textString Also known as: content

The content of the output text. See TextSpan#text.

Returns:

  • (String)


381
382
383
# File 'lib/google/cloud/language/annotation.rb', line 381

def text
  text_span.text
end