Class: Google::Cloud::Language::Annotation::Syntax

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

Overview

Represents the result of syntax 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

syntax = annotation.syntax

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

syntax.tokens.count #=> 13
token = syntax.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 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



633
634
635
# File 'lib/google/cloud/language/annotation.rb', line 633

def language
  @language
end

#sentencesArray<Sentence> (readonly)

The sentences returned by syntax analysis.

Returns:

  • (Array<Sentence>)

    the current value of sentences



633
634
635
# File 'lib/google/cloud/language/annotation.rb', line 633

def sentences
  @sentences
end

#tokensObject (readonly)

Returns the value of attribute tokens



634
635
636
# File 'lib/google/cloud/language/annotation.rb', line 634

def tokens
  @tokens
end