dialogy.types.entity.base_entity package¶
Module contents¶
Module provides access to a base class to create other entities.
- class BaseEntity(body, dim=None, parsers=NOTHING, score=None, alternative_index=None, alternative_indices=None, latent=False, values=NOTHING, value=None, entity_type=None, *, range, type='value')[source]¶
Bases:
object
Base Entity Type.
This class is meant for subclassing. Its intended purpose is to define a base for all entity types.
- add_parser(plugin)[source]¶
Update parsers with the postprocessor function name
This is to identify the progression in which the plugins were applied to an entity. This only helps in debugging and has no production utility.
- Parameters
plugin (Plugin) – The class that modifies this instance. Preferably should be a plugin.
- Returns
Calling instance with modifications to
parsers
attribute.- Return type
- alternative_index: Optional[int]¶
- alternative_indices: Optional[List[int]]¶
- body: str¶
- copy()[source]¶
Create a deep copy of the instance and return.
This is needed to prevent mutation of an original entity. :return: A copy of BaseEntity that calls this method. :rtype: BaseEntity
- dim: Optional[str]¶
- entity_type: Optional[str]¶
- classmethod from_duckling(d, alternative_index, **kwargs)[source]¶
- Return type
Optional
[BaseEntity
]
- get_value()[source]¶
Get value of an entity.
The structure of an entity conceals the value in different data structures. This is sugar for access.
- Parameters
reference (Any) – Picking value/values from a reference object.
- Raises
IndexError – If values is not a list.
KeyError – If each element in values is not a dict.
- Returns
Arbitrary instance, subclasses should override and return specific types.
- Return type
- json(skip=None, add=None)[source]¶
Convert the object to a dictionary.
Applies some expected filters to prevent information bloat.
Add section for skipping more properties using const.SKIP_ENTITY_ATTRS + [“”]
- Parameters
skip (Optional[List[str]]) – Names of attributes that should not be included while converting to a dict. Defaults to None.
add (Optional[List[str]]) – Names of attributes that should be included while converting to a dict. Defaults to None.
- Returns
Dictionary representation of the object
- Return type
Dict[str, Any]
- latent: bool¶
- parsers: List[str]¶
- range: Dict[str, int]¶
- score: Optional[float]¶
- type: str¶
- value: Any¶
- values: List[Dict[str, Any]]¶
- entity_synthesis(entity, property_, value)[source]¶
Update a property=`property_` of a BaseEntity, with a given value=`value`.
Warning
This is an unsafe method. Use with caution as it doesn’t check the type of the new value being type safe.
- Parameters
entity (BaseEntity) – A BaseEntity instance.
property (str) – An attribute of BaseEntity that should be changed.
value (Any) – The value to replace within a BaseEntity instance.
- Returns
A copy of BaseEntity instance used in this function with modifications.
- Return type