pyaiml21.utils.load_files.aiml_map_fromstring¶
- pyaiml21.utils.load_files.aiml_map_fromstring(s: str) Mapping[str, str][source][source]¶
Guess the format and parse AIML map from the given string.
The loaded keys are normalized – letters are uppercased and extra spaces removed.
Records with empty keys are discarded.
- Supported formats include:
ALICE format: key:value per each line,
Pandorabots format [json]: list of lists with 2 strings each
- To Alice format: the first (:) is the separator between words, that is
>>> text = "a:b:c" >>> aiml_map_fromstring(text) == dict(A="b:c") True
- Parameters
s – string representing AIML map
- Returns
parsed map
- Raises
ValueError if s does not represent an AIML map
- Examples:
>>> s = "a:1\nb:c\nd:e" >>> aiml_map_fromstring(s) == dict(A="1", B="c", D="e") True
>>> s = '[["key1", "val1"], ["key2 extra", "val2"]]' >>> aiml_map_fromstring(s) == { "KEY1": "val1", "KEY2 EXTRA": "val2"} True