Class: Google::Cloud::Language::Annotation::Token
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Annotation::Token
- Defined in:
- lib/google/cloud/language/annotation.rb
Overview
Represents the smallest syntactic building block of the text. Returned by syntactic analysis.
Instance Attribute Summary collapse
-
#head_token_index ⇒ Integer
readonly
Represents the head of this token in the dependency tree.
-
#label ⇒ Symbol
readonly
The parse label for the token.
-
#lemma ⇒ String
readonly
[Lemma](en.wikipedia.org/wiki/Lemma_(morphology)) of the token.
-
#part_of_speech ⇒ Symbol
readonly
Represents part of speech information for a token.
-
#text_span ⇒ TextSpan
readonly
The token text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text_span, part_of_speech, head_token_index, label, lemma) ⇒ Token
constructor
A new instance of Token.
- #offset ⇒ Object (also: #begin_offset)
- #text ⇒ Object (also: #content)
Constructor Details
#initialize(text_span, part_of_speech, head_token_index, label, lemma) ⇒ Token
Returns a new instance of Token.
283 284 285 286 287 288 289 290 |
# File 'lib/google/cloud/language/annotation.rb', line 283 def initialize text_span, part_of_speech, head_token_index, label, lemma @text_span = text_span @part_of_speech = part_of_speech @head_token_index = head_token_index @label = label @lemma = lemma end |
Instance Attribute Details
#head_token_index ⇒ Integer (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.
277 278 279 |
# File 'lib/google/cloud/language/annotation.rb', line 277 def head_token_index @head_token_index end |
#label ⇒ Symbol (readonly)
The parse label for the token.
277 278 279 |
# File 'lib/google/cloud/language/annotation.rb', line 277 def label @label end |
#lemma ⇒ String (readonly)
[Lemma](en.wikipedia.org/wiki/Lemma_(morphology)) of the token.
277 278 279 |
# File 'lib/google/cloud/language/annotation.rb', line 277 def lemma @lemma end |
#part_of_speech ⇒ Symbol (readonly)
Represents part of speech information for a token.
277 278 279 |
# File 'lib/google/cloud/language/annotation.rb', line 277 def part_of_speech @part_of_speech end |
#text_span ⇒ TextSpan (readonly)
The token text.
277 278 279 |
# File 'lib/google/cloud/language/annotation.rb', line 277 def text_span @text_span end |
Class Method Details
.from_grpc(grpc) ⇒ Object
304 305 306 307 308 309 |
# File 'lib/google/cloud/language/annotation.rb', line 304 def self.from_grpc grpc text_span = TextSpan.from_grpc grpc.text new text_span, grpc.part_of_speech.tag, grpc.dependency_edge.head_token_index, grpc.dependency_edge.label, grpc.lemma end |
Instance Method Details
#offset ⇒ Object Also known as: begin_offset
297 298 299 |
# File 'lib/google/cloud/language/annotation.rb', line 297 def offset @text_span.offset end |
#text ⇒ Object Also known as: content
292 293 294 |
# File 'lib/google/cloud/language/annotation.rb', line 292 def text @text_span.text end |