📜 ⬆️ ⬇️

Creating a simple interactive assistant


Hi, Habr! Inspired by the latest achievements in the field of applied AI and personal assistants (Siri, Google Now and the like), I decided to write an assistant for myself, though not as advanced as commercial counterparts, but with my blackjack and my twist.

Meet Susie




')
The main highlight of my pseudo-AI is a very simple implementation and quick learning of a large number of phrases. This is achieved as follows:



Logic Susy



In the folder with the executable file there are (at the moment) three files: sinonims.txt, faq.txt, and phrases.txt. They are filled by me, in the future I plan to add the function of filling with a voice and / or some kind of self-study.

sinonims.txt
- base of the original words of their replacements
hi = hi
hello = hi
hi = hi
...
affairs = state
life = state
...

faq.txt
- base question-answer. The response may contain text, command or variable.
* hi * = {& hi}, {% name}
* as * state * = {& state}
...
* off * debug * = {@ dbg0} {& ok}
The right side contains a mask, under which the text with synonyms is substituted, the left answer. The special characters "@", "%" and "&" indicate that you need to insert instead of a construction - a command, variable or phrase, respectively.

phrases.txt
- base of frequent phrases in several versions
hi1 = hello
hi2 = welcome
...
state1 = good
state2 = normal
state3 = everything is OK
...

If there is a desire to fill in the database - write in the comments, I will lay out the database, source code, exe.

Request Processing Example

Source code: hello, how are you -> We clear the line, replace dictionary synonyms: hi as state -> We look under what masks it gets: * hi * and * as * state * -> Parsim answer: replace {& hi} and {& state } randomly on the options present in the database of phrases, and {% name} on the variable curusr -> Result: welcome, Sir, everything is normal (You probably would have thought that Suzi was not very literate, but she did not need literacy, my plans are to fasten speech recognition and TTS to her, and in this case she will not need to put punctuation marks and write words with capital letters)



The insides susi



Initialization procedure
procedure init; var path: string; begin canspeak := true; path := extractfilepath(application.ExeName) + '\brains\'; //   faq := tstringlist.Create; //      words := tstringlist.Create; words.LoadFromFile(path + 'phrases.txt'); faq.LoadFromFile(path + 'faq.txt'); sins := tstringlist.Create; sins.LoadFromFile(path + 'sinonims.txt'); curusr := 'dysha'; //   name := sino(curusr); //       say(' '); say('        ' + inttostr(faq.Count * sins.Count) + '    ' + inttostr(faq.Count * words.Count)); end; 


Parsing procedure
 procedure parce(s: string); var p, o, i, t, i1: Integer; t1: string; str: tstringlist; begin str := tstringlist.Create; said := false; s := ansilowercase(s); //   trim(s); stringtowords(s, str); s := ''; for i := 0 to str.Count - 1 do //      s := s + sino(str[i]) + ' '; delete(s, length(s), 1); s := answ(s); //       ,   , , ={%cname} d(s); //   tparce := s; rootcmdparce; //      faqparce; //     end; 


I did not give the rest of the code because I am too lazy to comment on it, it does not carry much semantic meaning, and it is also no different to beauty.

Conclusion


I have a lot of plans for Susi, I want to add speech recognition and synthesizing to it (but this exercise is long, and the time is short - the session, students and sympathizers will understand), the ability to memorize what the operator says, analyze it, save reminders, notes . I want to put this whole system on a separate machine, the blessing at their cottage is a heap, to fasten a good speaker to it, a microphone, a motion sensor, relays through a com port so that I can enter the room and say: “Suzi, close the door, cut air conditioning and put my favorite song "or something like that ... Oh, how cool it is, damn it.

While I was looking for a picture for the topic, I came across this, who knows, he will understand.


UPD
I spread the source code with exe: docs.google.com/file/d/0B1vVuifL615WVzNmQllOUGEwd00/edit?usp=sharing . If there are those who fill the bases before, I will be very grateful if you drop them to me. For the possible presence of bydlokoda please understand and forgive.

Source: https://habr.com/ru/post/181998/


All Articles