rasa.shared.nlu.training_data.util
You are viewing documentation for our open source project which is maintained by the community. If you want to get started building assistants with Rasa please check out our latest documentation here.
transform_entity_synonyms
def transform_entity_synonyms(
synonyms: List[Dict[Text, Any]],
known_synonyms: Optional[Dict[Text, Any]] = None
) -> Dict[Text, Any]:
Transforms the entity synonyms into a text->value dictionary.
get_file_format_extension
def get_file_format_extension(resource_name: Text) -> Text:
Get the file extension based on training data format. It supports both a folder and a file, and tries to guess the format as follows:
- if the resource is a file and has a known format, return this format's extension
- if the resource is a folder and all the resources have the same known format, return its extension
- otherwise, default to DEFAULT_FILE_FORMAT (yml).
Arguments:
resource_name- The name of the resource, can be a file or a folder.
Returns:
The resource file format.
remove_untrainable_entities_from
def remove_untrainable_entities_from(example: Dict[Text, Any]) -> None:
Remove untrainable entities from serialized training example example.
Entities with an untrainable extractor will be removed. Untrainable extractors are defined in rasa.nlu.constants.PRETRAINED_EXTRACTORS.
Arguments:
example- Serialized training example to inspect.
intent_response_key_to_template_key
def intent_response_key_to_template_key(intent_response_key: Text) -> Text:
Resolve the response template key for a given intent response key.
Arguments:
intent_response_key- retrieval intent with the response key suffix attached.- Returns - The corresponding response template.
template_key_to_intent_response_key
def template_key_to_intent_response_key(template_key: Text) -> Text:
Resolve the intent response key for the given response template.
Arguments:
template_key- Name of the response template.- Returns - The corresponding intent response key.
has_string_escape_chars
def has_string_escape_chars(s: Text) -> bool:
Checks whether there are any escape characters in the string.
encode_string
def encode_string(s: Text) -> Text:
Return an encoded python string.
decode_string
def decode_string(s: Text) -> Text:
Return a decoded python string.
build_entity
def build_entity(start: int,
end: int,
value: Text,
entity_type: Text,
role: Optional[Text] = None,
group: Optional[Text] = None,
**kwargs: Any) -> Dict[Text, Any]:
Builds a standard entity dictionary.
Adds additional keyword parameters.
Arguments:
start- start position of entityend- end position of entityvalue- text value of the entityentity_type- name of the entity typerole- role of the entitygroup- group of the entity**kwargs- additional parameters
Returns:
an entity dictionary
sparse_matrix_to_string
def sparse_matrix_to_string(m: scipy.sparse.spmatrix) -> Text:
Turns a sparse matrix into a string.
Will return a line "(i,j) v" for each value in the matrix.
Taken from official scipy source to operate on full sparse matrix to not have to change the maxprint property in-place.
https://github.com/scipy/scipy/blob/v1.7.0/scipy/sparse/base.py#L258