Class: Google::Cloud::Language::Annotation::TextSpan

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

sentence = annotation.sentences.last
text_span = sentence.text_span
sentence.text #=> "The Death Star is fearsome."
sentence.offset #=> 28

Instance Attribute Summary collapse

Instance Attribute Details

#offsetInteger (readonly) Also known as: begin_offset

The beginning offset of the content in the original document.

The API calculates the beginning offset according to the client system's default encoding. In Ruby this defaults to UTF-8. To change the offset calculation you will need to change Ruby's default encoding. This is commonly done by setting Encoding.default_internal to Encoding::UTF_16 or Encoding::UTF_32. If the system is configured to use an encoding other than UTF-16 or UTF-32 the offset will be calculated using UTF-8.

Returns:

  • (Integer)

    the current value of offset



270
271
272
# File 'lib/google/cloud/language/annotation.rb', line 270

def offset
  @offset
end

#textString (readonly) Also known as: content

The content of the output text.

Returns:

  • (String)

    the current value of text



270
271
272
# File 'lib/google/cloud/language/annotation.rb', line 270

def text
  @text
end