airflow.providers.google.cloud.hooks.natural_language

This module contains a Google Cloud Natural Language Hook.

Module Contents

class airflow.providers.google.cloud.hooks.natural_language.CloudNaturalLanguageHook(gcp_conn_id: str = 'google_cloud_default', delegate_to: Optional[str] = None, impersonation_chain: Optional[Union[str, Sequence[str]]] = 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 (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 (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: Union[dict, Document], encoding_type: Optional[enums.EncodingType] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

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

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

  • retry (google.api_core.retry.Retry) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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: Union[dict, Document], encoding_type: Optional[enums.EncodingType] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

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

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

  • retry (google.api_core.retry.Retry) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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: Union[dict, Document], encoding_type: Optional[enums.EncodingType] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

Analyzes the sentiment of the provided text.

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

  • retry (google.api_core.retry.Retry) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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: Union[dict, Document], encoding_type: Optional[enums.EncodingType] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[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 (dict or 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.enums.EncodingType) -- The encoding type used by the API to calculate offsets.

  • retry (google.api_core.retry.Retry) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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: Union[dict, Document], features: Union[dict, AnnotateTextRequest.Features], encoding_type: enums.EncodingType = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

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

Parameters
  • document (dict or 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 or 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 (google.api_core.retry.Retry) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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: Union[dict, Document], retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]

Classifies a document into categories.

Parameters
  • document (dict or 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) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (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?