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.
The method:
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
New method in V2:
Allows you to load the dictionary as a text string obtained by any means. This also raises the LoadingComplete event. The event:
occurs after the word is fully loaded. If the dictionary did not contain errors, then the result = true . The method:
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.
Text example:
hellow # Hi! | good afternoon | Do we know each other? | Hi, my name is Eva;
how are you # thanks, I’m fine | perfectly! | I was fine until you asked me about it;
do you love me # I love you | I would go to the cinema with you | Do not tell me about love!
Good day Contact off topic, do not scold ScorpioNormal, you get the extensions you need. Maybe you can make a convenient extension for transforming a number from HEX to DEC indicating the digit capacity of the number to be translated? Using standard mathematical tools, this procedure takes too many blocks. It would be great if you just set the value and bit width and get a number … Once again litter for being out of topic.
To read from a specific file on the SD card (for example, /myFile.txt will read the file /sdcard/myFile.txt ). To read assets packaged with an application (also works for the Companion) start the fileName with // (two slashes). If a fileName does not start with a slash, it will be read from the application’s private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
is it possible to get that file from the server? (means can we use server file path instead of the local file path. )So we don’t need to update our app. We can directly update our questions and answers in the text file.
Thank You
Okay, that’s good because of the capital letters. Too bad, there is no possibility of having capital letters at the beginning of the sentence, or for proper nouns?
Also added a method to load a dictionary from a string variable.
Thus, you can update from dictionary located in the cloud storage using Kodular methods or third-party extensions.