towhee.functional.entity.Entity

class towhee.functional.entity.Entity(**kwargs)[source]

Bases: object

Entity is the basic data type in DataCollection.

Users can create an Entity with free schema, which means there is no limit on attribute name and type.

Exampels:
>>> from towhee import Entity
>>> e = Entity(a=1, b=2)
>>> e
<Entity dict_keys(['a', 'b'])>
>>> e.a
1
>>> e.b
2

Methods

combine

Combine entities.

from_dict

Create an Entity from a dict.

__init__(**kwargs)[source]

Create an Entity with given attributes.

__repr__()[source]

Define the representation of the Entity.

Returns (str):

The repr of the entity.

Examples

>>> from towhee import Entity
>>> e = Entity(a = 1, b = 2)
>>> e
<Entity dict_keys(['a', 'b'])>
combine(*entities)[source]

Combine entities.

Parameters:

entities (Entity) – The entities to be added into self.

Examples

>>> from towhee import Entity
>>> e = Entity(a = 1, b = 2)
>>> b = Entity(c = 3, d = 4)
>>> c = Entity(e = 5, f = 6)
>>> e.combine(b, c)
>>> str(e)
"{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}"
classmethod from_dict(tar: Dict[str, Any])[source]

Create an Entity from a dict.

Parameters:

tar (Dict[str, Any]) – The dict to create the Entity.

Examples:

>>> from towhee import Entity
>>> d = {'a': 1, 'b': 2}
>>> str(Entity.from_dict(d))
"{'a': 1, 'b': 2}"