This short post illustrates implementation of the base entity formatter. Entity formatter is requred for formatting values of mentioned named entities, masking them.
AREkit proposes an internal type OpinionEntityType
, which describes all the possible
types that opinion participants (subject/object) might be.
This enumeration type includes the following types:
class OpinionEntityType(Enum):
Object = 1
Subject = 2
SynonymSubject = 3
SynonymObject = 4
Other = 5
Implementation of the base class of the entities formatting illustrated in a snippet below:
class StringEntitiesFormatter(object):
def to_string(self, original_value, entity_type):
raise NotImplementedError()
Inherited versions of the base class illustrated below:
class CustomEntitiesFormatter(StringEntitiesFormatter):
def __init__(self, subject_fmt="[subject]", object_fmt="[object]"):
self.__subj_fmt = subject_fmt
self.__obj_fmt = object_fmt
def to_string(self, original_value, entity_type):
assert(isinstance(original_value, Entity))
if entity_type == OpinionEntityType.Other:
return original_value.Value
elif entity_type == OpinionEntityType.Object or
entity_type == OpinionEntityType.SynonymObject:
return self.__obj_fmt
elif entity_type == OpinionEntityType.Subject or
entity_type == OpinionEntityType.SynonymSubject:
return self.__subj_fmt
return None
List of the other entity formatters provided out-of-the-box is as follows:
RussianEntitiesCasedFormatter
– supports russian cases forsubject
(субъект
) andobject
(объект
).
NOTE It was decided not to mention other adapters since they are related to
CustomEntitiesFormatter
described above.