Natural Language Response Classes#

Entity#

Definition for Google Cloud Natural Language API entities.

An entity is used to describe a proper name extracted from text.

class google.cloud.language.entity.Entity(name, entity_type, metadata, salience, mentions)[source]#

Bases: object

A Google Cloud Natural Language API entity.

Represents a phrase in 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.

The only supported metadata (as of August 2016) is wikipedia_url, so this value will be removed from the passed in metadata and put in its own property.

See Entity message.

Parameters:
  • name (str) – The name / phrase identified as the entity.
  • entity_type (str) – The type of the entity. See EntityType enum.
  • metadata (dict) – The metadata associated with the entity.
  • salience (float) – The prominence of the entity / phrase within the text containing it.
  • mentions (list) – List of strings that mention the entity.
classmethod from_api_repr(payload)[source]#

Convert an Entity from the JSON API into an Entity.

Parameters:payload (The value from the backend.) – dict
Return type:Entity
Returns:The entity parsed from the API representation.
class google.cloud.language.entity.EntityType[source]#

Bases: object

List of possible entity types.

CONSUMER_GOOD = 'CONSUMER_GOOD'#

Consumer good entity type.

EVENT = 'EVENT'#

Event entity type.

LOCATION = 'LOCATION'#

Location entity type.

ORGANIZATION = 'ORGANIZATION'#

Organization entity type.

OTHER = 'OTHER'#

Other entity type (i.e. known but not classified).

PERSON = 'PERSON'#

Person entity type.

UNKNOWN = 'UNKNOWN'#

Unknown entity type.

WORK_OF_ART = 'WORK_OF_ART'#

Work of art entity type.

Sentiment#

Definition for Google Cloud Natural Language API sentiment.

Sentiment is the response to an analyzeSentiment request.

class google.cloud.language.sentiment.Sentiment(polarity, magnitude)[source]#

Bases: object

A Google Cloud Natural Language API sentiment object.

See Sentiment message and Sentiment basics.

Parameters:
  • polarity (float) – Polarity of the sentiment in the [-1.0, 1.0] range. Larger numbers represent more positive sentiments.
  • magnitude (float) – A non-negative number in the [0, +inf) range, which represents the absolute magnitude of sentiment regardless of polarity (positive or negative).
classmethod from_api_repr(payload)[source]#

Convert a Sentiment from the JSON API into a Sentiment.

Parameters:payload (The value from the backend.) – dict
Return type:Sentiment
Returns:The sentiment parsed from the API representation.

Syntax#

Google Cloud Natural Language API helpers for tokenized text.

The annotateText method, when used with the “syntax” feature, breaks a document down into tokens and sentences.

class google.cloud.language.syntax.PartOfSpeech[source]#

Bases: object

Part of speech of a Token.

ADJECTIVE = 'ADJ'#

Part of speech: Adjective.

ADPOSITION = 'ADP'#

Adposition (preposition and postposition).

ADVERB = 'ADV'#

Adverb.

AFFIX = 'AFFIX'#

Affix.

CARDINAL_NUMBER = 'NUM'#

Cardinal number.

CONJUNCTION = 'CONJ'#

Conjunction.

DETERMINER = 'DET'#

Determiner.

NOUN = 'NOUN'#

Noun (common and proper).

OTHER = 'X'#

Other: foreign words, typos, abbreviations.

PARTICIPLE = 'PRT'#

Particle or other function word.

PRONOUN = 'PRON'#

Pronoun.

PUNCTUATION = 'PUNCT'#

Punctuation.

UNKNOWN = 'UNKNOWN'#

Unknown part of speech.

VERB = 'VERB'#

Verb (all tenses and modes).

classmethod reverse(tag)[source]#

Reverses the API’s enum name for the one on this class.

For example:

>>> PartOfSpeech.OTHER
'X'
>>> PartOfSpeech.reverse('X')
'OTHER'
Return type:str
Returns:The attribute name corresponding to the API part of speech enum.
class google.cloud.language.syntax.Sentence(content, begin)[source]#

Bases: object

A Google Cloud Natural Language API sentence object.

See Sentence message.

Parameters:
  • content (str) – The text that the sentence is composed of.
  • begin (int) – The beginning offset of the sentence in the original document according to the encoding type specified in the API request.
classmethod from_api_repr(payload)[source]#

Convert a sentence from the JSON API into a Sentiment.

Parameters:payload (The value from the backend.) – dict
Return type:Sentence
Returns:The sentence parsed from the API representation.
class google.cloud.language.syntax.Token(text_content, text_begin, part_of_speech, edge_index, edge_label, lemma)[source]#

Bases: object

A Google Cloud Natural Language API token object.

See Token message.

Parameters:
  • text_content (str) – The text that the token is composed of.
  • text_begin (int) – The beginning offset of the content in the original document according to the encoding type specified in the API request.
  • part_of_speech (str) – The part of speech of the token. See PartOfSpeech for possible values.
  • edge_index (int) – 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 edge_index is its own index.
  • edge_label (str) – See Label enum.
  • lemma (str) – The Lemma of the token.
classmethod from_api_repr(payload)[source]#

Convert a token from the JSON API into a Sentiment.

Parameters:payload (The value from the backend.) – dict
Return type:Token
Returns:The token parsed from the API representation.