Dictionary for Voice assistant


#1

At the request of one of the forum participants, I made a dictionary for dialogue with a voice assistant or chatbot.
The dictionary is loaded from a text file with the following contents:
Question1 # Answer1.1 | Answer1.2 …| Answer 1.N ;
Question2 # Answer2.1 | Answer2.2 …| Answer 2.N ;
………………………………………………………………………………………
QuestionN # AnswerN.1 | AnswerN.2 …| Answer N.N
‘#’,’|’,’;’ separators are required.
If the phrase from the question is contained in the dictionary, a random answer will be returned. Responses will not be repeated until all possible answers are returned.
If the dictionary has only one answer to a question, then this will function too.
Line feeds are ignored. The user can split the lines as he sees fit.
Of course, the same results can be achieved by standard means. My extension just makes it more convenient.

Version 1:
The method
LoadFromFile
allows you to load a dictionary from a text file. The rules for the file path are the same as for the standard File module
The event
LoadingComplete
occurs after the word is fully loaded. If the dictionary did not contain errors, then the result = true.
The method
GetRandomAnswer
returns one of the answers if the question is in the dictionary.
If the dictionary says “what is your first name what is your name # ……”, that method will give answers to the both question “what is your first name” and “what is your name". However, if the dictionary says only “what is your first name # ……”, and you ask “what is your name”, the method will answer with an empty string. Be careful when compiling a dictionary.
The question character ‘?’ can be used at your discretion. It is understood that a speech recognition system does not add a ‘?’ character at the end of a question sentence, unless you ask for it.

ScDictionaryV1.aix (17.6 KB)
ScDictionaryTestV1.aia (37.5 KB)
MyDialog.txt (259 Bytes)
For the example project to work, you must copy the MyDialog.txt file to the root SD directory of your smartphone.