Created
May 9, 2022 10:44
-
-
Save jcabot/b855c0f2f054296dfa168ccf709f22ca to your computer and use it in GitHub Desktop.
Extension of chatbot dsl representation with custom ners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity: | |
"""An entity to be recognized as part of the matching process""" | |
def __init__(self, name: str): | |
self.name: str = name | |
class CustomEntityEntry: | |
"""Each one of the entries (and its synonyms) a CustomEntity consists of""" | |
def __init__(self, value: str, synonyms: list[str] = None): | |
self.value: str = value | |
self.synonyms: list[str] = synonyms | |
class CustomEntity(Entity): | |
""" A custom entity, adhoc for the bot """ | |
def __init__(self, name: str, entries: list[CustomEntityEntry] = None): | |
super().__init__(name) | |
if (entries is not None): | |
self.entries: list[CustomEntityEntry] = entries | |
else: | |
self.entries = [] | |
class EntityReference: | |
"""A parameter of an Intent, representing an entity that is expected to be matched""" | |
def __init__(self, name: str, fragment:str, entity: Entity): | |
self.entity: Entity = entity # Entity type to be matched | |
self.name: str = name # name of the parameter | |
self.fragment: str = fragment # fragment of the text representing the entity ref in a training sentence | |
class Intent: | |
"""A chatbot intent""" | |
def __init__(self, name: str, training_sentences: list[str]): | |
self.name: str = name | |
self.training_sentences: list[str] = training_sentences | |
self.processed_training_sentences: list[str] = [] | |
self.training_sequences: list[int] = [] | |
# list of references to entities used in the Intent | |
# we are going to assume that two intents in the same context do not have parameters with the same name unless they refer to the same entity type | |
self.entity_parameters: list[EntityReference] = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment