As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

Types for Google Cloud Language v2 API

class google.cloud.language_v2.types.AnalyzeEntitiesRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The entity analysis request message.

document

Required. Input document.

Type

google.cloud.language_v2.types.Document

encoding_type

The encoding type used by the API to calculate offsets.

Type

google.cloud.language_v2.types.EncodingType

class google.cloud.language_v2.types.AnalyzeEntitiesResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The entity analysis response message.

entities

The recognized entities in the input document.

Type

MutableSequence[google.cloud.language_v2.types.Entity]

language_code

The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See [Document.language][] field for more details.

Type

str

language_supported

Whether the language is officially supported. The API may still return a response when the language is not supported, but it is on a best effort basis.

Type

bool

class google.cloud.language_v2.types.AnalyzeSentimentRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The sentiment analysis request message.

document

Required. Input document.

Type

google.cloud.language_v2.types.Document

encoding_type

The encoding type used by the API to calculate sentence offsets.

Type

google.cloud.language_v2.types.EncodingType

class google.cloud.language_v2.types.AnalyzeSentimentResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The sentiment analysis response message.

document_sentiment

The overall sentiment of the input document.

Type

google.cloud.language_v2.types.Sentiment

language_code

The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See [Document.language][] field for more details.

Type

str

sentences

The sentiment for all the sentences in the document.

Type

MutableSequence[google.cloud.language_v2.types.Sentence]

language_supported

Whether the language is officially supported. The API may still return a response when the language is not supported, but it is on a best effort basis.

Type

bool

class google.cloud.language_v2.types.AnnotateTextRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The request message for the text annotation API, which can perform multiple analysis types in one call.

document

Required. Input document.

Type

google.cloud.language_v2.types.Document

features

Required. The enabled features.

Type

google.cloud.language_v2.types.AnnotateTextRequest.Features

encoding_type

The encoding type used by the API to calculate offsets.

Type

google.cloud.language_v2.types.EncodingType

class Features(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

All available features. Setting each one to true will enable that specific analysis for the input.

extract_entities

Optional. Extract entities.

Type

bool

extract_document_sentiment

Optional. Extract document-level sentiment.

Type

bool

classify_text

Optional. Classify the full document into categories.

Type

bool

moderate_text

Optional. Moderate the document for harmful and sensitive categories.

Type

bool

class google.cloud.language_v2.types.AnnotateTextResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The text annotations response message.

sentences

Sentences in the input document. Populated if the user enables [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].

Type

MutableSequence[google.cloud.language_v2.types.Sentence]

entities

Entities, along with their semantic information, in the input document. Populated if the user enables [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities] or [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].

Type

MutableSequence[google.cloud.language_v2.types.Entity]

document_sentiment

The overall sentiment for the document. Populated if the user enables [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].

Type

google.cloud.language_v2.types.Sentiment

language_code

The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See [Document.language][] field for more details.

Type

str

categories

Categories identified in the input document.

Type

MutableSequence[google.cloud.language_v2.types.ClassificationCategory]

moderation_categories

Harmful and sensitive categories identified in the input document.

Type

MutableSequence[google.cloud.language_v2.types.ClassificationCategory]

language_supported

Whether the language is officially supported by all requested features. The API may still return a response when the language is not supported, but it is on a best effort basis.

Type

bool

class google.cloud.language_v2.types.ClassificationCategory(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents a category returned from the text classifier.

name

The name of the category representing the document.

Type

str

confidence

The classifier’s confidence of the category. Number represents how certain the classifier is that this category represents the given text.

Type

float

class google.cloud.language_v2.types.ClassifyTextRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The document classification request message.

document

Required. Input document.

Type

google.cloud.language_v2.types.Document

class google.cloud.language_v2.types.ClassifyTextResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The document classification response message.

categories

Categories representing the input document.

Type

MutableSequence[google.cloud.language_v2.types.ClassificationCategory]

language_code

The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See [Document.language][] field for more details.

Type

str

language_supported

Whether the language is officially supported. The API may still return a response when the language is not supported, but it is on a best effort basis.

Type

bool

class google.cloud.language_v2.types.Document(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents the input to API methods.

This message has oneof fields (mutually exclusive fields). For each oneof, at most one member field can be set at the same time. Setting any member of the oneof automatically clears all other members.

type_

Required. If the type is not set or is TYPE_UNSPECIFIED, returns an INVALID_ARGUMENT error.

Type

google.cloud.language_v2.types.Document.Type

content

The content of the input in string format. Cloud audit logging exempt since it is based on user data.

This field is a member of oneof source.

Type

str

gcs_content_uri

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.

This field is a member of oneof source.

Type

str

language_code

Optional. The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are accepted. Language Support lists currently supported languages for each API method. If the language (either specified by the caller or automatically detected) is not supported by the called API method, an INVALID_ARGUMENT error is returned.

Type

str

class Type(value)[source]

Bases: proto.enums.Enum

The document types enum.

Values:
TYPE_UNSPECIFIED (0):

The content type is not specified.

PLAIN_TEXT (1):

Plain text

HTML (2):

HTML

class google.cloud.language_v2.types.EncodingType(value)[source]

Bases: proto.enums.Enum

Represents the text encoding that the caller uses to process the output. Providing an EncodingType is recommended because the API provides the beginning offsets for various outputs, such as tokens and mentions, and languages that natively use different text encodings may access offsets differently.

Values:
NONE (0):

If EncodingType is not specified, encoding-dependent information (such as begin_offset) will be set at -1.

UTF8 (1):

Encoding-dependent information (such as begin_offset) is calculated based on the UTF-8 encoding of the input. C++ and Go are examples of languages that use this encoding natively.

UTF16 (2):

Encoding-dependent information (such as begin_offset) is calculated based on the UTF-16 encoding of the input. Java and JavaScript are examples of languages that use this encoding natively.

UTF32 (3):

Encoding-dependent information (such as begin_offset) is calculated based on the UTF-32 encoding of the input. Python is an example of a language that uses this encoding natively.

class google.cloud.language_v2.types.Entity(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as probability and mentions, with entities.

name

The representative name for the entity.

Type

str

type_

The entity type.

Type

google.cloud.language_v2.types.Entity.Type

metadata

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.

Type

MutableMapping[str, str]

mentions

The mentions of this entity in the input document. The API currently supports proper noun mentions.

Type

MutableSequence[google.cloud.language_v2.types.EntityMention]

sentiment

For calls to [AnalyzeEntitySentiment][] or if [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment] is set to true, this field will contain the aggregate sentiment expressed for this entity in the provided document.

Type

google.cloud.language_v2.types.Sentiment

class MetadataEntry(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Bases: proto.message.Message

class Type(value)[source]

Bases: proto.enums.Enum

The type of the entity. For most entity types, the associated metadata is a Wikipedia URL (wikipedia_url) and Knowledge Graph MID (mid). The table below lists the associated fields for entities that have different metadata.

Values:
UNKNOWN (0):

Unknown

PERSON (1):

Person

LOCATION (2):

Location

ORGANIZATION (3):

Organization

EVENT (4):

Event

WORK_OF_ART (5):

Artwork

CONSUMER_GOOD (6):

Consumer product

OTHER (7):

Other types of entities

PHONE_NUMBER (9):

Phone number

The metadata lists the phone number, formatted according to local convention, plus whichever additional elements appear in the text:

  • number - the actual number, broken down into sections as per local convention

  • national_prefix - country code, if detected

  • area_code - region or area code, if detected

  • extension - phone extension (to be dialed after connection), if detected

ADDRESS (10):

Address

The metadata identifies the street number and locality plus whichever additional elements appear in the text:

  • street_number - street number

  • locality - city or town

  • street_name - street/route name, if detected

  • postal_code - postal code, if detected

  • country - country, if detected<

  • broad_region - administrative area, such as the state, if detected

  • narrow_region - smaller administrative area, such as county, if detected

  • sublocality - used in Asian addresses to demark a district within a city, if detected

DATE (11):

Date

The metadata identifies the components of the date:

  • year - four digit year, if detected

  • month - two digit month number, if detected

  • day - two digit day number, if detected

NUMBER (12):

Number The metadata is the number itself.

PRICE (13):

Price

The metadata identifies the value and currency.

class google.cloud.language_v2.types.EntityMention(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents a mention for an entity in the text. Currently, proper noun mentions are supported.

text

The mention text.

Type

google.cloud.language_v2.types.TextSpan

type_

The type of the entity mention.

Type

google.cloud.language_v2.types.EntityMention.Type

sentiment

For calls to [AnalyzeEntitySentiment][] or if [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment] is set to true, this field will contain the sentiment expressed for this mention of the entity in the provided document.

Type

google.cloud.language_v2.types.Sentiment

probability

Probability score associated with the entity.

The score shows the probability of the entity mention being the entity type. The score is in (0, 1] range.

Type

float

class Type(value)[source]

Bases: proto.enums.Enum

The supported types of mentions.

Values:
TYPE_UNKNOWN (0):

Unknown

PROPER (1):

Proper name

COMMON (2):

Common noun (or noun compound)

class google.cloud.language_v2.types.ModerateTextRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The document moderation request message.

document

Required. Input document.

Type

google.cloud.language_v2.types.Document

class google.cloud.language_v2.types.ModerateTextResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

The document moderation response message.

moderation_categories

Harmful and sensitive categories representing the input document.

Type

MutableSequence[google.cloud.language_v2.types.ClassificationCategory]

language_code

The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See [Document.language][] field for more details.

Type

str

language_supported

Whether the language is officially supported. The API may still return a response when the language is not supported, but it is on a best effort basis.

Type

bool

class google.cloud.language_v2.types.Sentence(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents a sentence in the input document.

text

The sentence text.

Type

google.cloud.language_v2.types.TextSpan

sentiment

For calls to [AnalyzeSentiment][] or if [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment] is set to true, this field will contain the sentiment for the sentence.

Type

google.cloud.language_v2.types.Sentiment

class google.cloud.language_v2.types.Sentiment(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents the feeling associated with the entire text or entities in the text.

magnitude

A non-negative number in the [0, +inf) range, which represents the absolute magnitude of sentiment regardless of score (positive or negative).

Type

float

score

Sentiment score between -1.0 (negative sentiment) and 1.0 (positive sentiment).

Type

float

class google.cloud.language_v2.types.TextSpan(mapping=None, *, ignore_unknown_fields=False, **kwargs)[source]

Bases: proto.message.Message

Represents a text span in the input document.

content

The content of the text span, which is a substring of the document.

Type

str

begin_offset

The API calculates the beginning offset of the content in the original document according to the [EncodingType][google.cloud.language.v2.EncodingType] specified in the API request.

Type

int