Class: Google::Cloud::Language::Document
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Document
- Defined in:
- lib/google/cloud/language/document.rb
Overview
Document
Represents a document for the Language service.
Cloud Natural Language API supports UTF-8, UTF-16, and UTF-32 encodings. (Ruby uses UTF-8 natively, which is the default sent to the API, so unless you're working with text processed in different platform, you should not need to set the encoding type.)
Be aware that only English, Spanish, and Japanese language content are supported.
See Project#document.
Instance Method Summary collapse
-
#annotate(sentiment: false, entities: false, syntax: false, encoding: nil) ⇒ Annotation
(also: #mark, #detect)
Analyzes the document and returns sentiment, entity, and syntactic feature results, depending on the option flags.
-
#entities(encoding: nil) ⇒ Annotation::Entities
Entity analysis inspects the given text for known entities (proper nouns such as public figures, landmarks, etc.) and returns information about those entities.
-
#format ⇒ Symbol
The document's format.
-
#format=(new_format) ⇒ Object
Sets the document's format.
-
#html! ⇒ Object
Sets the document to the
HTML
format. -
#html? ⇒ Boolean
Whether the document is the
HTML
format. -
#language ⇒ String
The document's language.
-
#language=(new_language) ⇒ Object
Sets the document's language.
-
#sentiment(encoding: nil) ⇒ Annotation::Sentiment
Sentiment analysis inspects the given text and identifies the prevailing emotional opinion within the text, especially to determine a writer's attitude as positive, negative, or neutral.
-
#syntax(encoding: nil) ⇒ Annotation::Syntax
Syntactic analysis extracts linguistic information, breaking up the given text into a series of sentences and tokens (generally, word boundaries), providing further analysis on those tokens.
-
#text! ⇒ Object
Sets the document to the
TEXT
format. -
#text? ⇒ Boolean
Whether the document is the
TEXT
format.
Instance Method Details
#annotate(sentiment: false, entities: false, syntax: false, encoding: nil) ⇒ Annotation Also known as: mark, detect
Analyzes the document and returns sentiment, entity, and syntactic
feature results, depending on the option flags. Calling annotate
with no arguments will perform all analysis features. Each feature
is priced separately. See Pricing
for details.
216 217 218 219 220 221 222 223 224 |
# File 'lib/google/cloud/language/document.rb', line 216 def annotate sentiment: false, entities: false, syntax: false, encoding: nil ensure_service! grpc = service.annotate to_grpc, sentiment: sentiment, entities: entities, syntax: syntax, encoding: encoding Annotation.from_grpc grpc end |
#entities(encoding: nil) ⇒ Annotation::Entities
Entity analysis inspects the given text for known entities (proper nouns such as public figures, landmarks, etc.) and returns information about those entities.
292 293 294 295 296 |
# File 'lib/google/cloud/language/document.rb', line 292 def entities encoding: nil ensure_service! grpc = service.entities to_grpc, encoding: encoding Annotation::Entities.from_grpc grpc end |
#format ⇒ Symbol
The document's format.
90 91 92 93 |
# File 'lib/google/cloud/language/document.rb', line 90 def format return :text if text? return :html if html? end |
#format=(new_format) ⇒ Object
Sets the document's format.
105 106 107 108 109 |
# File 'lib/google/cloud/language/document.rb', line 105 def format= new_format @grpc.type = :PLAIN_TEXT if new_format.to_s == "text" @grpc.type = :HTML if new_format.to_s == "html" @grpc.type end |
#html! ⇒ Object
Sets the document to the HTML
format.
139 140 141 |
# File 'lib/google/cloud/language/document.rb', line 139 def html! @grpc.type = :HTML end |
#html? ⇒ Boolean
Whether the document is the HTML
format.
132 133 134 |
# File 'lib/google/cloud/language/document.rb', line 132 def html? @grpc.type == :HTML end |
#language ⇒ String
The document's language. ISO and BCP-47 language codes are supported.
148 149 150 |
# File 'lib/google/cloud/language/document.rb', line 148 def language @grpc.language end |
#language=(new_language) ⇒ Object
Sets the document's language.
162 163 164 |
# File 'lib/google/cloud/language/document.rb', line 162 def language= new_language @grpc.language = new_language.to_s end |
#sentiment(encoding: nil) ⇒ Annotation::Sentiment
Sentiment analysis inspects the given text and identifies the prevailing emotional opinion within the text, especially to determine a writer's attitude as positive, negative, or neutral. Currently, only English is supported for sentiment analysis.
328 329 330 331 332 |
# File 'lib/google/cloud/language/document.rb', line 328 def sentiment encoding: nil ensure_service! grpc = service.sentiment to_grpc, encoding: encoding Annotation::Sentiment.from_grpc grpc end |
#syntax(encoding: nil) ⇒ Annotation::Syntax
Syntactic analysis extracts linguistic information, breaking up the given text into a series of sentences and tokens (generally, word boundaries), providing further analysis on those tokens.
262 263 264 265 266 |
# File 'lib/google/cloud/language/document.rb', line 262 def syntax encoding: nil ensure_service! grpc = service.syntax to_grpc, encoding: encoding Annotation::Syntax.from_grpc grpc end |
#text! ⇒ Object
Sets the document to the TEXT
format.
123 124 125 |
# File 'lib/google/cloud/language/document.rb', line 123 def text! @grpc.type = :PLAIN_TEXT end |
#text? ⇒ Boolean
Whether the document is the TEXT
format.
116 117 118 |
# File 'lib/google/cloud/language/document.rb', line 116 def text? @grpc.type == :PLAIN_TEXT end |