airflow.providers.google.cloud.hooks.natural_language
¶
This module contains a Google Cloud Natural Language Hook.
Module Contents¶
Classes¶
Hook for Google Cloud Natural Language Service. |
- class airflow.providers.google.cloud.hooks.natural_language.CloudNaturalLanguageHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
Bases:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook
Hook for Google Cloud Natural Language Service.
- Parameters
gcp_conn_id (str) – The connection ID to use when fetching connection info.
impersonation_chain (str | collections.abc.Sequence[str] | None) – Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account.
- get_conn()[source]¶
Retrieve connection to Cloud Natural Language service.
- Returns
Cloud Natural Language service object
- Return type
google.cloud.language_v1.LanguageServiceClient
- analyze_entities(document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
Find named entities in the text along with various properties.
Examples properties: entity types, salience, mentions for each entity, and others.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
encoding_type (google.cloud.language_v1.EncodingType | None) – The encoding type used by the API to calculate offsets.
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- analyze_entity_sentiment(document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
Similar to AnalyzeEntities, also analyzes sentiment associated with each entity and its mentions.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
encoding_type (google.cloud.language_v1.EncodingType | None) – The encoding type used by the API to calculate offsets.
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- analyze_sentiment(document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
Analyzes the sentiment of the provided text.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
encoding_type (google.cloud.language_v1.EncodingType | None) – The encoding type used by the API to calculate offsets.
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- analyze_syntax(document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
Analyzes the syntax of the text.
Provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
encoding_type (google.cloud.language_v1.EncodingType | None) – The encoding type used by the API to calculate offsets.
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- annotate_text(document, features, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]¶
Provide all features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
features (dict | google.cloud.language_v1.types.AnnotateTextRequest.Features) – The enabled features. If a dict is provided, it must be of the same form as the protobuf message Features
encoding_type (google.cloud.language_v1.EncodingType | None) – The encoding type used by the API to calculate offsets.
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- classify_text(document, retry=DEFAULT, timeout=None, metadata=())[source]¶
Classifies a document into categories.
- Parameters
document (dict | google.cloud.language_v1.types.Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document
retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (collections.abc.Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.