La vaca saltó sobre la luna.
- ... - ... - ... """ - >>> document = language.types.Document( - ... content=html_content, - ... language='es', - ... type='HTML', - ... ) - -The ``language`` argument can be either ISO-639-1 or BCP-47 language -codes. The API reference page contains the full list of `supported languages`_. - -.. _supported languages: https://cloud.google.com/natural-language/docs/languages - - -In addition to supplying the text / HTML content, a document can refer -to content stored in `Google Cloud Storage`_. - - .. code-block:: python - - >>> document = language.types.Document( - ... gcs_content_uri='gs://my-text-bucket/sentiment-me.txt', - ... type=language.enums.HTML, - ... ) - -.. _analyzeEntities: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntities -.. _analyzeSentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeSentiment -.. _analyzeEntitySentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment -.. _annotateText: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/annotateText -.. _classifyText: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/classifyText -.. _Google Cloud Storage: https://cloud.google.com/storage/ - -Analyze Entities -**************** - -The :meth:`~.language_v1.LanguageServiceClient.analyze_entities` -method finds named entities (i.e. proper names) in the text. This method -returns a :class:`~.language_v1.types.AnalyzeEntitiesResponse`. - - .. code-block:: python - - >>> document = language.types.Document( - ... content='Michelangelo Caravaggio, Italian painter, is ' - ... 'known for "The Calling of Saint Matthew".', - ... type=language.enums.Document.Type.PLAIN_TEXT, - ... ) - >>> response = client.analyze_entities( - ... document=document, - ... encoding_type='UTF32', - ... ) - >>> for entity in response.entities: - ... print('=' * 20) - ... print(' name: {0}'.format(entity.name)) - ... print(' type: {0}'.format(entity.type)) - ... print(' metadata: {0}'.format(entity.metadata)) - ... print(' salience: {0}'.format(entity.salience)) - ==================== - name: Michelangelo Caravaggio - type: PERSON - metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/Caravaggio'} - salience: 0.7615959 - ==================== - name: Italian - type: LOCATION - metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/Italy'} - salience: 0.19960518 - ==================== - name: The Calling of Saint Matthew - type: EVENT - metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)'} - salience: 0.038798928 - -.. note:: - - It is recommended to send an ``encoding_type`` argument to Natural - Language methods, so they provide useful offsets for the data they return. - While the correct value varies by environment, in Python you *usually* - want ``UTF32``. - - -Analyze Sentiment -***************** - -The :meth:`~.language_v1.LanguageServiceClient.analyze_sentiment` method -analyzes the sentiment of the provided text. This method returns a -:class:`~.language_v1.types.AnalyzeSentimentResponse`. - - .. code-block:: python - - >>> document = language.types.Document( - ... content='Jogging is not very fun.', - ... type='PLAIN_TEXT', - ... ) - >>> response = client.analyze_sentiment( - ... document=document, - ... encoding_type='UTF32', - ... ) - >>> sentiment = response.document_sentiment - >>> print(sentiment.score) - -1 - >>> print(sentiment.magnitude) - 0.8 - -.. note:: - - It is recommended to send an ``encoding_type`` argument to Natural - Language methods, so they provide useful offsets for the data they return. - While the correct value varies by environment, in Python you *usually* - want ``UTF32``. - - -Analyze Entity Sentiment -************************ - -The :meth:`~.language_v1.LanguageServiceClient.analyze_entity_sentiment` -method is effectively the amalgamation of -:meth:`~.language_v1.LanguageServiceClient.analyze_entities` and -:meth:`~.language_v1.LanguageServiceClient.analyze_sentiment`. -This method returns a -:class:`~.language_v1.types.AnalyzeEntitySentimentResponse`. - -.. code-block:: python - - >>> document = language.types.Document( - ... content='Mona said that jogging is very fun.', - ... type='PLAIN_TEXT', - ... ) - >>> response = client.analyze_entity_sentiment( - ... document=document, - ... encoding_type='UTF32', - ... ) - >>> entities = response.entities - >>> entities[0].name - 'Mona' - >>> entities[1].name - 'jogging' - >>> entities[1].sentiment.magnitude - 0.8 - >>> entities[1].sentiment.score - 0.8 - -.. note:: - - It is recommended to send an ``encoding_type`` argument to Natural - Language methods, so they provide useful offsets for the data they return. - While the correct value varies by environment, in Python you *usually* - want ``UTF32``. - - -Annotate Text -************* - -The :meth:`~.language_v1.LanguageServiceClient.annotate_text` method -analyzes a document and is intended for users who are familiar with -machine learning and need in-depth text features to build upon. This method -returns a :class:`~.language_v1.types.AnnotateTextResponse`. diff --git a/google/cloud/language/__init__.py b/google/cloud/language/__init__.py deleted file mode 100644 index 4426b53c..00000000 --- a/google/cloud/language/__init__.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.cloud.language_v1.services.language_service.async_client import ( - LanguageServiceAsyncClient, -) -from google.cloud.language_v1.services.language_service.client import ( - LanguageServiceClient, -) -from google.cloud.language_v1.types.language_service import AnalyzeEntitiesRequest -from google.cloud.language_v1.types.language_service import AnalyzeEntitiesResponse -from google.cloud.language_v1.types.language_service import ( - AnalyzeEntitySentimentRequest, -) -from google.cloud.language_v1.types.language_service import ( - AnalyzeEntitySentimentResponse, -) -from google.cloud.language_v1.types.language_service import AnalyzeSentimentRequest -from google.cloud.language_v1.types.language_service import AnalyzeSentimentResponse -from google.cloud.language_v1.types.language_service import AnalyzeSyntaxRequest -from google.cloud.language_v1.types.language_service import AnalyzeSyntaxResponse -from google.cloud.language_v1.types.language_service import AnnotateTextRequest -from google.cloud.language_v1.types.language_service import AnnotateTextResponse -from google.cloud.language_v1.types.language_service import ClassificationCategory -from google.cloud.language_v1.types.language_service import ClassifyTextRequest -from google.cloud.language_v1.types.language_service import ClassifyTextResponse -from google.cloud.language_v1.types.language_service import DependencyEdge -from google.cloud.language_v1.types.language_service import Document -from google.cloud.language_v1.types.language_service import EncodingType -from google.cloud.language_v1.types.language_service import Entity -from google.cloud.language_v1.types.language_service import EntityMention -from google.cloud.language_v1.types.language_service import PartOfSpeech -from google.cloud.language_v1.types.language_service import Sentence -from google.cloud.language_v1.types.language_service import Sentiment -from google.cloud.language_v1.types.language_service import TextSpan -from google.cloud.language_v1.types.language_service import Token - -__all__ = ( - "AnalyzeEntitiesRequest", - "AnalyzeEntitiesResponse", - "AnalyzeEntitySentimentRequest", - "AnalyzeEntitySentimentResponse", - "AnalyzeSentimentRequest", - "AnalyzeSentimentResponse", - "AnalyzeSyntaxRequest", - "AnalyzeSyntaxResponse", - "AnnotateTextRequest", - "AnnotateTextResponse", - "ClassificationCategory", - "ClassifyTextRequest", - "ClassifyTextResponse", - "DependencyEdge", - "Document", - "EncodingType", - "Entity", - "EntityMention", - "LanguageServiceAsyncClient", - "LanguageServiceClient", - "PartOfSpeech", - "Sentence", - "Sentiment", - "TextSpan", - "Token", -) diff --git a/google/cloud/language/py.typed b/google/cloud/language/py.typed deleted file mode 100644 index c0acc99a..00000000 --- a/google/cloud/language/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-language package uses inline types. diff --git a/google/cloud/language_v1/__init__.py b/google/cloud/language_v1/__init__.py deleted file mode 100644 index ba3826be..00000000 --- a/google/cloud/language_v1/__init__.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from .services.language_service import LanguageServiceClient -from .types.language_service import AnalyzeEntitiesRequest -from .types.language_service import AnalyzeEntitiesResponse -from .types.language_service import AnalyzeEntitySentimentRequest -from .types.language_service import AnalyzeEntitySentimentResponse -from .types.language_service import AnalyzeSentimentRequest -from .types.language_service import AnalyzeSentimentResponse -from .types.language_service import AnalyzeSyntaxRequest -from .types.language_service import AnalyzeSyntaxResponse -from .types.language_service import AnnotateTextRequest -from .types.language_service import AnnotateTextResponse -from .types.language_service import ClassificationCategory -from .types.language_service import ClassifyTextRequest -from .types.language_service import ClassifyTextResponse -from .types.language_service import DependencyEdge -from .types.language_service import Document -from .types.language_service import EncodingType -from .types.language_service import Entity -from .types.language_service import EntityMention -from .types.language_service import PartOfSpeech -from .types.language_service import Sentence -from .types.language_service import Sentiment -from .types.language_service import TextSpan -from .types.language_service import Token - - -__all__ = ( - "AnalyzeEntitiesRequest", - "AnalyzeEntitiesResponse", - "AnalyzeEntitySentimentRequest", - "AnalyzeEntitySentimentResponse", - "AnalyzeSentimentRequest", - "AnalyzeSentimentResponse", - "AnalyzeSyntaxRequest", - "AnalyzeSyntaxResponse", - "AnnotateTextRequest", - "AnnotateTextResponse", - "ClassificationCategory", - "ClassifyTextRequest", - "ClassifyTextResponse", - "DependencyEdge", - "Document", - "EncodingType", - "Entity", - "EntityMention", - "PartOfSpeech", - "Sentence", - "Sentiment", - "TextSpan", - "Token", - "LanguageServiceClient", -) diff --git a/google/cloud/language_v1/proto/language_service.proto b/google/cloud/language_v1/proto/language_service.proto deleted file mode 100644 index 304eab07..00000000 --- a/google/cloud/language_v1/proto/language_service.proto +++ /dev/null @@ -1,1122 +0,0 @@ -// Copyright 2019 Google LLC. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -syntax = "proto3"; - -package google.cloud.language.v1; - -import "google/api/annotations.proto"; -import "google/api/client.proto"; -import "google/api/field_behavior.proto"; - -option go_package = "google.golang.org/genproto/googleapis/cloud/language/v1;language"; -option java_multiple_files = true; -option java_outer_classname = "LanguageServiceProto"; -option java_package = "com.google.cloud.language.v1"; - - -// Provides text analysis operations such as sentiment analysis and entity -// recognition. -service LanguageService { - option (google.api.default_host) = "language.googleapis.com"; - option (google.api.oauth_scopes) = - "https://www.googleapis.com/auth/cloud-language," - "https://www.googleapis.com/auth/cloud-platform"; - // Analyzes the sentiment of the provided text. - rpc AnalyzeSentiment(AnalyzeSentimentRequest) returns (AnalyzeSentimentResponse) { - option (google.api.http) = { - post: "/v1/documents:analyzeSentiment" - body: "*" - }; - option (google.api.method_signature) = "document,encoding_type"; - option (google.api.method_signature) = "document"; - } - - // Finds named entities (currently proper names and common nouns) in the text - // along with entity types, salience, mentions for each entity, and - // other properties. - rpc AnalyzeEntities(AnalyzeEntitiesRequest) returns (AnalyzeEntitiesResponse) { - option (google.api.http) = { - post: "/v1/documents:analyzeEntities" - body: "*" - }; - option (google.api.method_signature) = "document,encoding_type"; - option (google.api.method_signature) = "document"; - } - - // Finds entities, similar to [AnalyzeEntities][google.cloud.language.v1.LanguageService.AnalyzeEntities] in the text and analyzes - // sentiment associated with each entity and its mentions. - rpc AnalyzeEntitySentiment(AnalyzeEntitySentimentRequest) returns (AnalyzeEntitySentimentResponse) { - option (google.api.http) = { - post: "/v1/documents:analyzeEntitySentiment" - body: "*" - }; - option (google.api.method_signature) = "document,encoding_type"; - option (google.api.method_signature) = "document"; - } - - // Analyzes the syntax of the text and provides sentence boundaries and - // tokenization along with part of speech tags, dependency trees, and other - // properties. - rpc AnalyzeSyntax(AnalyzeSyntaxRequest) returns (AnalyzeSyntaxResponse) { - option (google.api.http) = { - post: "/v1/documents:analyzeSyntax" - body: "*" - }; - option (google.api.method_signature) = "document,encoding_type"; - option (google.api.method_signature) = "document"; - } - - // Classifies a document into categories. - rpc ClassifyText(ClassifyTextRequest) returns (ClassifyTextResponse) { - option (google.api.http) = { - post: "/v1/documents:classifyText" - body: "*" - }; - option (google.api.method_signature) = "document"; - } - - // A convenience method that provides all the features that analyzeSentiment, - // analyzeEntities, and analyzeSyntax provide in one call. - rpc AnnotateText(AnnotateTextRequest) returns (AnnotateTextResponse) { - option (google.api.http) = { - post: "/v1/documents:annotateText" - body: "*" - }; - option (google.api.method_signature) = "document,features,encoding_type"; - option (google.api.method_signature) = "document,features"; - } -} - - -// -// Represents the input to API methods. -message Document { - // The document types enum. - enum Type { - // The content type is not specified. - TYPE_UNSPECIFIED = 0; - - // Plain text - PLAIN_TEXT = 1; - - // HTML - HTML = 2; - } - - // Required. If the type is not set or is `TYPE_UNSPECIFIED`, - // returns an `INVALID_ARGUMENT` error. - Type type = 1; - - // The source of the document: a string containing the content or a - // Google Cloud Storage URI. - oneof source { - // The content of the input in string format. - // Cloud audit logging exempt since it is based on user data. - string content = 2; - - // The Google Cloud Storage URI where the file content is located. - // This URI must be of the form: gs://bucket_name/object_name. For more - // details, see https://cloud.google.com/storage/docs/reference-uris. - // NOTE: Cloud Storage object versioning is not supported. - string gcs_content_uri = 3; - } - - // The language of the document (if not specified, the language is - // automatically detected). Both ISO and BCP-47 language codes are - // accepted.number – the actual number, broken down into
- // sections as per local conventionnational_prefix
- // – country code, if detectedarea_code –
- // region or area code, if detectedextension –
- // phone extension (to be dialed after connection), if detectedstreet_number – street numberlocality – city or townstreet_name – street/route name, if detectedpostal_code – postal code, if detectedcountry – country, if detectedbroad_region – administrative area, such as the
- // state, if detectednarrow_region – smaller
- // administrative area, such as county, if detectedsublocality – used in Asian addresses to demark a
- // district within a city, if detectedyear – four digit year, if detectedmonth – two digit month number, if detectedday – two digit day number, if detectedvalue and currency.
- PRICE = 13;
- }
-
- // The representative name for the entity.
- string name = 1;
-
- // The entity type.
- Type type = 2;
-
- // Metadata associated with the entity.
- //
- // For most entity types, the metadata is a Wikipedia URL (`wikipedia_url`)
- // and Knowledge Graph MID (`mid`), if they are available. For the metadata
- // associated with other entity types, see the Type table below.
- map