Class: Google::Cloud::Language::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Language::Project
- Defined in:
- lib/google/cloud/language/project.rb
Overview
Project
Google Cloud Natural Language API reveals the structure and meaning of text by offering powerful machine learning models in an easy to use REST API. You can analyze text uploaded in your request or integrate with your document storage on Google Cloud Storage.
Instance Method Summary collapse
-
#annotate(content, sentiment: false, entities: false, syntax: false, format: nil, language: nil, encoding: nil) ⇒ Annotation
(also: #mark, #detect)
Analyzes the content and returns sentiment, entity, and syntactic feature results, depending on the option flags.
-
#document(content, format: nil, language: nil) ⇒ Document
(also: #doc)
Returns a new document from the given content.
-
#entities(content, format: :text, language: nil, 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.
-
#html(content, language: nil) ⇒ Document
Returns a new document from the given content with the
format
value:html
. -
#project ⇒ Object
The Language project connected to.
-
#sentiment(content, format: :text, language: nil, 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(content, format: nil, language: nil, 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(content, language: nil) ⇒ Document
Returns a new document from the given content with the
format
value:text
.
Instance Method Details
#annotate(content, sentiment: false, entities: false, syntax: false, format: nil, language: nil, encoding: nil) ⇒ Annotation Also known as: mark, detect
Analyzes the content 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.
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/google/cloud/language/project.rb', line 228 def annotate content, sentiment: false, entities: false, syntax: false, format: nil, language: nil, encoding: nil ensure_service! doc = document content, language: language, format: format grpc = service.annotate doc.to_grpc, sentiment: sentiment, entities: entities, syntax: syntax, encoding: encoding Annotation.from_grpc grpc end |
#document(content, format: nil, language: nil) ⇒ Document Also known as: doc
Returns a new document from the given content. No API call is made.
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/google/cloud/language/project.rb', line 134 def document content, format: nil, language: nil content = content.to_gs_url if content.respond_to? :to_gs_url if content.is_a? Document # Create new document with the provided format and language Document.from_source content.source, @service, format: (format || content.format), language: (language || content.language) else Document.from_source content, @service, format: format, language: language end end |
#entities(content, format: :text, language: nil, 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.
320 321 322 323 324 325 |
# File 'lib/google/cloud/language/project.rb', line 320 def entities content, format: :text, language: nil, encoding: nil ensure_service! doc = document content, language: language, format: format grpc = service.entities doc.to_grpc, encoding: encoding Annotation::Entities.from_grpc grpc end |
#html(content, language: nil) ⇒ Document
Returns a new document from the given content with the format
value
:html
. No API call is made.
180 181 182 |
# File 'lib/google/cloud/language/project.rb', line 180 def html content, language: nil document content, format: :html, language: language end |
#project ⇒ Object
The Language project connected to.
72 73 74 |
# File 'lib/google/cloud/language/project.rb', line 72 def project service.project end |
#sentiment(content, format: :text, language: nil, 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.
365 366 367 368 369 370 |
# File 'lib/google/cloud/language/project.rb', line 365 def sentiment content, format: :text, language: nil, encoding: nil ensure_service! doc = document content, language: language, format: format grpc = service.sentiment doc.to_grpc, encoding: encoding Annotation::Sentiment.from_grpc grpc end |
#syntax(content, format: nil, language: nil, 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.
285 286 287 288 289 290 |
# File 'lib/google/cloud/language/project.rb', line 285 def syntax content, format: nil, language: nil, encoding: nil ensure_service! doc = document content, language: language, format: format grpc = service.syntax doc.to_grpc, encoding: encoding Annotation::Syntax.from_grpc grpc end |
#text(content, language: nil) ⇒ Document
Returns a new document from the given content with the format
value
:text
. No API call is made.
162 163 164 |
# File 'lib/google/cloud/language/project.rb', line 162 def text content, language: nil document content, format: :text, language: language end |