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 (str | None) – 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 (str | 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]

Retrieves 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]

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

Parameters
  • document (dict | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • encoding_type (enums.EncodingType | None) – The encoding type used by the API to calculate offsets.

  • retry (Retry | _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 (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]

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

Parameters
  • document (dict | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • encoding_type (enums.EncodingType | None) – The encoding type used by the API to calculate offsets.

  • retry (Retry | _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 (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 | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • encoding_type (enums.EncodingType | None) – The encoding type used by the API to calculate offsets.

  • retry (Retry | _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 (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 and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other properties.

Parameters
  • document (dict | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • encoding_type (enums.EncodingType | None) – The encoding type used by the API to calculate offsets.

  • retry (Retry | _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 (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]

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

Parameters
  • document (dict | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • features (dict | 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 (Retry | _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 (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 | Document) – Input document. If a dict is provided, it must be of the same form as the protobuf message Document

  • retry (Retry | _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 (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.

Was this entry helpful?