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 v1 API

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

Represents the input to API methods.

type_

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

Type

Type

content

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

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.

Type

str

language

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[source]

The document types enum.

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

Represents a sentence in the input document.

text

The sentence text.

Type

TextSpan

sentiment

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

Type

Sentiment

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

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 salience and mentions, with entities.

name

The representative name for the entity.

Type

str

type_

The entity type.

Type

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

Sequence[MetadataEntry]

salience

The salience score associated with the entity in the [0, 1.0] range.

The salience score for an entity provides information about the importance or centrality of that entity to the entire document text. Scores closer to 0 are less salient, while scores closer to 1.0 are highly salient.

Type

float

mentions

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

Type

Sequence[EntityMention]

sentiment

For calls to [AnalyzeEntitySentiment][] or if [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.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

Sentiment

class MetadataEntry(mapping=None, **kwargs)
class Type[source]

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.

class google.cloud.language_v1.types.Token(mapping=None, **kwargs)[source]

Represents the smallest syntactic building block of the text.

text

The token text.

Type

TextSpan

part_of_speech

Parts of speech tag for this token.

Type

PartOfSpeech

dependency_edge

Dependency tree parse for this token.

Type

DependencyEdge

lemma

Lemma of the token.

Type

str

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

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_v1.types.PartOfSpeech(mapping=None, **kwargs)[source]

Represents part of speech information for a token. Parts of speech are as defined in http://www.lrec-conf.org/proceedings/lrec2012/pdf/274_Paper.pdf

tag

The part of speech tag.

Type

Tag

aspect

The grammatical aspect.

Type

Aspect

case

The grammatical case.

Type

Case

form

The grammatical form.

Type

Form

gender

The grammatical gender.

Type

Gender

mood

The grammatical mood.

Type

Mood

number

The grammatical number.

Type

Number

person

The grammatical person.

Type

Person

proper

The grammatical properness.

Type

Proper

reciprocity

The grammatical reciprocity.

Type

Reciprocity

tense

The grammatical tense.

Type

Tense

voice

The grammatical voice.

Type

Voice

class Aspect[source]

The characteristic of a verb that expresses time flow during an event.

class Case[source]

The grammatical function performed by a noun or pronoun in a phrase, clause, or sentence. In some languages, other parts of speech, such as adjective and determiner, take case inflection in agreement with the noun.

class Form[source]

Depending on the language, Form can be categorizing different forms of verbs, adjectives, adverbs, etc. For example, categorizing inflected endings of verbs and adjectives or distinguishing between short and long forms of adjectives and participles

class Gender[source]

Gender classes of nouns reflected in the behaviour of associated words.

class Mood[source]

The grammatical feature of verbs, used for showing modality and attitude.

class Number[source]

Count distinctions.

class Person[source]

The distinction between the speaker, second person, third person, etc.

class Proper[source]

This category shows if the token is part of a proper name.

class Reciprocity[source]

Reciprocal features of a pronoun.

class Tag[source]

The part of speech tags enum.

class Tense[source]

Time reference.

class Voice[source]

The relationship between the action that a verb expresses and the participants identified by its arguments.

class google.cloud.language_v1.types.DependencyEdge(mapping=None, **kwargs)[source]

Represents dependency parse tree information for a token. (For more information on dependency labels, see http://www.aclweb.org/anthology/P13-2017

head_token_index

Represents the head of this token in the dependency tree. This is the index of the token which has an arc going to this token. The index is the position of the token in the array of tokens returned by the API method. If this token is a root token, then the head_token_index is its own index.

Type

int

label

The parse label for the token.

Type

Label

class Label[source]

The parse label enum for the token.

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

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

text

The mention text.

Type

TextSpan

type_

The type of the entity mention.

Type

Type

sentiment

For calls to [AnalyzeEntitySentiment][] or if [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v1.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

Sentiment

class Type[source]

The supported types of mentions.

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

Represents an output piece of text.

content

The content of the output text.

Type

str

begin_offset

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

Type

int

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

Represents a category returned from the text classifier.

name

The name of the category representing the document, from the predefined taxonomy.

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_v1.types.AnalyzeSentimentRequest(mapping=None, **kwargs)[source]

The sentiment analysis request message.

document

Input document.

Type

Document

encoding_type

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

Type

EncodingType

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

The sentiment analysis response message.

document_sentiment

The overall sentiment of the input document.

Type

Sentiment

language

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][google.cloud.language.v1.Document.language] field for more details.

Type

str

sentences

The sentiment for all the sentences in the document.

Type

Sequence[Sentence]

class google.cloud.language_v1.types.AnalyzeEntitySentimentRequest(mapping=None, **kwargs)[source]

The entity-level sentiment analysis request message.

document

Input document.

Type

Document

encoding_type

The encoding type used by the API to calculate offsets.

Type

EncodingType

class google.cloud.language_v1.types.AnalyzeEntitySentimentResponse(mapping=None, **kwargs)[source]

The entity-level sentiment analysis response message.

entities

The recognized entities in the input document with associated sentiments.

Type

Sequence[Entity]

language

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][google.cloud.language.v1.Document.language] field for more details.

Type

str

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

The entity analysis request message.

document

Input document.

Type

Document

encoding_type

The encoding type used by the API to calculate offsets.

Type

EncodingType

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

The entity analysis response message.

entities

The recognized entities in the input document.

Type

Sequence[Entity]

language

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][google.cloud.language.v1.Document.language] field for more details.

Type

str

class google.cloud.language_v1.types.AnalyzeSyntaxRequest(mapping=None, **kwargs)[source]

The syntax analysis request message.

document

Input document.

Type

Document

encoding_type

The encoding type used by the API to calculate offsets.

Type

EncodingType

class google.cloud.language_v1.types.AnalyzeSyntaxResponse(mapping=None, **kwargs)[source]

The syntax analysis response message.

sentences

Sentences in the input document.

Type

Sequence[Sentence]

tokens

Tokens, along with their syntactic information, in the input document.

Type

Sequence[Token]

language

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][google.cloud.language.v1.Document.language] field for more details.

Type

str

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

The document classification request message.

document

Input document.

Type

Document

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

The document classification response message.

categories

Categories representing the input document.

Type

Sequence[ClassificationCategory]

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

The request message for the text annotation API, which can perform multiple analysis types (sentiment, entities, and syntax) in one call.

document

Input document.

Type

Document

features

The enabled features.

Type

Features

encoding_type

The encoding type used by the API to calculate offsets.

Type

EncodingType

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

All available features for sentiment, syntax, and semantic analysis. Setting each one to true will enable that specific analysis for the input.

extract_syntax

Extract syntax information.

Type

bool

extract_entities

Extract entities.

Type

bool

extract_document_sentiment

Extract document-level sentiment.

Type

bool

extract_entity_sentiment

Extract entities and their associated sentiment.

Type

bool

classify_text

Classify the full document into categories.

Type

bool

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

The text annotations response message.

sentences

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

Type

Sequence[Sentence]

tokens

Tokens, along with their syntactic information, in the input document. Populated if the user enables [AnnotateTextRequest.Features.extract_syntax][google.cloud.language.v1.AnnotateTextRequest.Features.extract_syntax].

Type

Sequence[Token]

entities

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

Type

Sequence[Entity]

document_sentiment

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

Type

Sentiment

language

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][google.cloud.language.v1.Document.language] field for more details.

Type

str

categories

Categories identified in the input document.

Type

Sequence[ClassificationCategory]