airflow.providers.google.cloud.hooks.natural_language

This module contains a Google Cloud Natural Language Hook.

Module Contents

Classes

CloudNaturalLanguageHook

Hook for Google Cloud Natural Language Service.

class airflow.providers.google.cloud.hooks.natural_language.CloudNaturalLanguageHook(gcp_conn_id='google_cloud_default', delegate_to=None, impersonation_chain=None)[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.

  • delegate_to (Optional[str]) -- The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled.

  • impersonation_chain (Optional[Union[str, Sequence[str]]]) -- 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(self)[source]

Retrieves connection to Cloud Natural Language service.

Returns

Cloud Natural Language service object

Return type

google.cloud.language_v1.LanguageServiceClient

analyze_entities(self, document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]

Finds named entities in the text along with entity types, salience, mentions for each entity, and other properties.

Parameters
  • document (Union[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 (Optional[google.cloud.language_v1.enums.EncodingType]) -- The encoding type used by the API to calculate offsets.

  • retry (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.AnalyzeEntitiesResponse

analyze_entity_sentiment(self, document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]

Finds entities, similar to AnalyzeEntities in the text and analyzes sentiment associated with each entity and its mentions.

Parameters
  • document (Union[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 (Optional[google.cloud.language_v1.enums.EncodingType]) -- The encoding type used by the API to calculate offsets.

  • retry (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.AnalyzeEntitiesResponse

analyze_sentiment(self, document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]

Analyzes the sentiment of the provided text.

Parameters
  • document (Union[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 (Optional[google.cloud.language_v1.enums.EncodingType]) -- The encoding type used by the API to calculate offsets.

  • retry (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.AnalyzeSentimentResponse

analyze_syntax(self, document, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]

Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.

Parameters
  • document (Union[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 (Optional[google.cloud.language_v1.enums.EncodingType]) -- The encoding type used by the API to calculate offsets.

  • retry (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.AnalyzeSyntaxResponse

annotate_text(self, document, features, encoding_type=None, retry=DEFAULT, timeout=None, metadata=())[source]

A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call.

Parameters
  • document (Union[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 (Union[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.enums.EncodingType) -- The encoding type used by the API to calculate offsets.

  • retry (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.AnnotateTextResponse

classify_text(self, document, retry=DEFAULT, timeout=None, metadata=())[source]

Classifies a document into categories.

Parameters
  • document (Union[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 (Union[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 (Optional[float]) -- 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 (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Return type

google.cloud.language_v1.types.ClassifyTextResponse

Was this entry helpful?