Class: Google::Cloud::Language::Annotation::Token

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

Overview

Represents the smallest syntactic building block of the text. Returned by syntactic 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

annotation.tokens.count #=> 13
token = annotation.tokens.first

token.text_span.text #=> "Star"
token.text_span.offset #=> 0
token.part_of_speech.tag #=> :NOUN
token.part_of_speech.number #=> :SINGULAR
token.head_token_index #=> 1
token.label #=> :TITLE
token.lemma #=> "Star"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#head_token_indexInteger (readonly)

Represents the head of this token in the dependency tree. This is the index of the token which has an arc going to this token. The index is the position of the token in the array of tokens returned by the API method. If this token is a root token, then the headTokenIndex is its own index.

Returns:

  • (Integer)

    the current value of head_token_index



523
524
525
# File 'lib/google/cloud/language/annotation.rb', line 523

def head_token_index
  @head_token_index
end

#labelSymbol (readonly)

The parse label for the token.

Returns:

  • (Symbol)

    the current value of label



523
524
525
# File 'lib/google/cloud/language/annotation.rb', line 523

def label
  @label
end

#lemmaString (readonly)

Lemma of the token.

Returns:

  • (String)

    the current value of lemma



523
524
525
# File 'lib/google/cloud/language/annotation.rb', line 523

def lemma
  @lemma
end

#part_of_speechPartOfSpeech (readonly)

Represents part of speech information for a token.

Returns:



523
524
525
# File 'lib/google/cloud/language/annotation.rb', line 523

def part_of_speech
  @part_of_speech
end

#text_spanTextSpan (readonly)

The token text.

Returns:

  • (TextSpan)

    the current value of text_span



523
524
525
# File 'lib/google/cloud/language/annotation.rb', line 523

def text_span
  @text_span
end

Instance Method Details

#offsetObject Also known as: begin_offset



543
544
545
# File 'lib/google/cloud/language/annotation.rb', line 543

def offset
  @text_span.offset
end

#textObject Also known as: content



538
539
540
# File 'lib/google/cloud/language/annotation.rb', line 538

def text
  @text_span.text
end