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 = "I love dogs. I hate cats."
document = language.document content
annotation = document.annotate

text_span = annotation.sentences.last
text_span.text #=> "I hate cats."
text_span.offset #=> 13

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, offset) ⇒ TextSpan

Returns a new instance of TextSpan.



230
231
232
233
# File 'lib/google/cloud/language/annotation.rb', line 230

def initialize text, offset
  @text   = text
  @offset = offset
end

Instance Attribute Details

#offsetInteger (readonly) 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.

Returns:

  • (Integer)

    the current value of offset



223
224
225
# File 'lib/google/cloud/language/annotation.rb', line 223

def offset
  @offset
end

#textString (readonly) Also known as: content

The content of the output text.

Returns:

  • (String)

    the current value of text



223
224
225
# File 'lib/google/cloud/language/annotation.rb', line 223

def text
  @text
end

Class Method Details

.from_grpc(grpc) ⇒ Object



237
238
239
# File 'lib/google/cloud/language/annotation.rb', line 237

def self.from_grpc grpc
  new grpc.content, grpc.begin_offset
end