|
| 1 | +# Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Definition for Google Cloud Natural Language API entities. |
| 16 | +
|
| 17 | +An entity is used to describe a proper name extracted from text. |
| 18 | +""" |
| 19 | + |
| 20 | + |
| 21 | +class EntityType(object): |
| 22 | + """List of possible entity types.""" |
| 23 | + |
| 24 | + UNKNOWN = 'UNKNOWN' |
| 25 | + """Unknown entity type.""" |
| 26 | + |
| 27 | + PERSON = 'PERSON' |
| 28 | + """Person entity type.""" |
| 29 | + |
| 30 | + LOCATION = 'LOCATION' |
| 31 | + """Location entity type.""" |
| 32 | + |
| 33 | + ORGANIZATION = 'ORGANIZATION' |
| 34 | + """Organization entity type.""" |
| 35 | + |
| 36 | + EVENT = 'EVENT' |
| 37 | + """Event entity type.""" |
| 38 | + |
| 39 | + WORK_OF_ART = 'WORK_OF_ART' |
| 40 | + """Work of art entity type.""" |
| 41 | + |
| 42 | + CONSUMER_GOOD = 'CONSUMER_GOOD' |
| 43 | + """Consumer good entity type.""" |
| 44 | + |
| 45 | + OTHER = 'OTHER' |
| 46 | + """Other entity type (i.e. known but not classified).""" |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +class Entity(object): |
| 51 | + """A Google Cloud Natural Language API entity. |
| 52 | +
|
| 53 | + Represents a phrase in text that is a known entity, such as a person, |
| 54 | + an organization, or location. The API associates information, such as |
| 55 | + salience and mentions, with entities. |
| 56 | +
|
| 57 | + See: |
| 58 | + https://cloud.google.com/natural-language/reference/rest/v1beta1/Entity |
| 59 | +
|
| 60 | + :type name: str |
| 61 | + :param name: The name / phrase identified as the entity. |
| 62 | +
|
| 63 | + :type entity_type: str |
| 64 | + :param entity_type: The type of the entity. See |
| 65 | + https://cloud.google.com/natural-language/\ |
| 66 | + reference/rest/v1beta1/Entity#Type |
| 67 | +
|
| 68 | + :type metadata: dict |
| 69 | + :param metadata: The metadata associated with the entity. |
| 70 | +
|
| 71 | + :type salience: float |
| 72 | + :param salience: The prominence of the entity / phrase within the text |
| 73 | + containing it. |
| 74 | +
|
| 75 | + :type mentions: list |
| 76 | + :param mentions: List of strings that mention the entity. |
| 77 | + """ |
| 78 | + |
| 79 | + def __init__(self, name, entity_type, metadata, salience, mentions): |
| 80 | + self.name = name |
| 81 | + self.entity_type = entity_type |
| 82 | + self.metadata = metadata |
| 83 | + self.salience = salience |
| 84 | + self.mentions = mentions |
0 commit comments