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 = "Darth Vader is the best villain in Star Wars."
document = language.document content
annotation = document.annotate

syntax = annotation.syntax

sentence = syntax.sentences.last
sentence.text #=> "Darth Vader is the best villain in Star Wars."
sentence.offset #=> 0

syntax.tokens.count #=> 10
token = syntax.tokens.first

token.text #=> "Darth"
token.offset #=> 0
token.part_of_speech #=> :NOUN
token.head_token_index #=> 1
token.label #=> :NN
token.lemma #=> "Darth"

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



590
591
592
# File 'lib/google/cloud/language/annotation.rb', line 590

def language
  @language
end

#sentencesArray<Sentence> (readonly)

The sentences returned by syntax analysis.

Returns:

  • (Array<Sentence>)

    the current value of sentences



590
591
592
# File 'lib/google/cloud/language/annotation.rb', line 590

def sentences
  @sentences
end

#tokensObject (readonly)

Returns the value of attribute tokens



591
592
593
# File 'lib/google/cloud/language/annotation.rb', line 591

def tokens
  @tokens
end