Class: Google::Cloud::Language::Annotation
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Annotation
- Defined in:
- lib/google/cloud/language/annotation.rb
Overview
# Annotation
The results of all requested document analysis features.
See Project#annotate and Document#annotate.
Defined Under Namespace
Classes: Entities, Entity, Sentiment, TextSpan, Token
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#entities ⇒ Entities
The entities returned by entity analysis.
-
#initialize ⇒ Annotation
constructor
A new instance of Annotation.
- #inspect ⇒ Object
-
#language ⇒ String
The language of the document (if not specified, the language is automatically detected).
-
#sentences ⇒ Array<TextSpan>
The sentences returned by syntactic analysis.
-
#sentiment ⇒ Sentiment
The result of sentiment analysis.
- #to_s ⇒ Object
-
#tokens ⇒ Array<Token>
The tokens returned by syntactic analysis.
Constructor Details
#initialize ⇒ Annotation
Returns a new instance of Annotation.
50 51 52 |
# File 'lib/google/cloud/language/annotation.rb', line 50 def initialize @grpc = nil end |
Instance Attribute Details
#grpc ⇒ Object
46 47 48 |
# File 'lib/google/cloud/language/annotation.rb', line 46 def grpc @grpc end |
Class Method Details
.from_grpc(grpc) ⇒ Object
198 199 200 |
# File 'lib/google/cloud/language/annotation.rb', line 198 def self.from_grpc grpc new.tap { |a| a.instance_variable_set :@grpc, grpc } end |
Instance Method Details
#entities ⇒ Entities
The entities returned by entity analysis.
134 135 136 |
# File 'lib/google/cloud/language/annotation.rb', line 134 def entities @entities ||= Entities.from_grpc @grpc end |
#inspect ⇒ Object
192 193 194 |
# File 'lib/google/cloud/language/annotation.rb', line 192 def inspect "#<#{self.class.name} #{self}>" end |
#language ⇒ String
The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are supported.
179 180 181 |
# File 'lib/google/cloud/language/annotation.rb', line 179 def language @grpc.language end |
#sentences ⇒ Array<TextSpan>
The sentences returned by syntactic analysis.
73 74 75 76 77 |
# File 'lib/google/cloud/language/annotation.rb', line 73 def sentences @sentences ||= begin Array(grpc.sentences).map { |g| TextSpan.from_grpc g.text } end end |
#sentiment ⇒ Sentiment
The result of sentiment analysis.
157 158 159 160 |
# File 'lib/google/cloud/language/annotation.rb', line 157 def sentiment return nil if @grpc.document_sentiment.nil? @sentiment ||= Sentiment.from_grpc @grpc end |
#to_s ⇒ Object
184 185 186 187 188 189 |
# File 'lib/google/cloud/language/annotation.rb', line 184 def to_s tmplt = "(sentences: %i, tokens: %i, entities: %i," \ " sentiment: %s, language: %s)" format tmplt, sentences.count, tokens.count, entities.count, !sentiment.nil?, language.inspect end |