Wroclaw 6.16.2008
PROJEKT:
Methods and algorithms of artificial intelligence
TEMAT:
The bot with which we can have basic talk about Cracov
Instructor:
dr inż. Witold Paluszyński
Student:
Łukasz Wroński (140437)
1. Introduction
AIML (Artificial Intelligence Markup Language) – is a language based on XML dialect for creating natural language software agents. It was develope by hacker, dr Richard S. Wallace, and a worldwide free software community ALICE between the years of 1995 and 2000.
Chatbot (or chatterbot) – computer program that simulates human, thet we can talk with, using natural language and text interface. The main challenge for a chatterbot is to answer all the questions in the way making user (person who chat with bot) belive he or she talks to a human
2. About the project
I've made the CHATBOT – Jaropelk, that can be used as a guide-book about Krakow. Jaropelks' base of informations has a basic informations about Krakow, for example: population, area, date of rise, president etc., basic informations about college's in Krakow and informations about monuments. Chatbot was made on www site pandorabots.com, where everyone can create a Chatbot on his own and then load to it a base of informations. Project was written in AIML language.
3. Opis języka AIML
AIML as a type of XML is build of tags, special strings starting with ''< and ending with ''>'' .I don’t want to describe XML language itself, you can check it in separate documentation about it. Every AIML document starts with <aiml> tag and ends with </aiml>, so the smallest complete AILM document is shown below:
< aiml >
</aiml >
As mentioned above, AIML document contains any number of objects (called categories) described by pair of tags <category> </category>. Each object contains one <pattern> and one <template> element. All AIML interpreters should return an error in case category doesn’t have both of mentioned elements. <pattern> tag refers to the user’s dialog/sentence, and <template> tag defines chatterbot reaction to that dialog/sentence. For example, this simple AIML document has only one category, making chatterbot to answer ''Witaj, jak sie masz?'' for ''Czesc'' pattern.
< aiml >
< category >
< pattern >CZESC< /pattern >
< template >Witaj, jak się masz?< /template >
< /category >
< /aiml >
Everything between tags <pattern> and </pattern>is a simple regular expression of the AIML, so it is all uppercase letters plus special characters ''*'' and/or ''_'' what means ''anything''. In example:
< aiml >
< category >
< pattern >CZESC *< /pattern >
< template >Witaj, jak się masz?< /template >
< /category >
< /aiml >
Chatterbot with defined database as above, will answer ''Witaj, jak sie masz?'' for any sentence starting with word ‘Czesc’, like ''Czesc cokolwiek'', ''Czesc co slychac'', etc… So the word ‘Czesc’ can be followed by any number of letters, numbers, and even by whole sentence…
In that kind of strings only letters and digits matter… Any other characters are simply ignored… Please notice, that chatterbot will ignore string ''Czesc'', because ''*'' and ''_'' can’t stand for empty string…
In theory, introduced so far tags are enough to build simple chatterbot, but AIML provide many extra tags that allow for easier design and better functionality. I will describe the most important of them below.
<srai>
<srai> tag allows to define synonyms for some of the patterns. Thanks to that user prevents defining the same reactions for different patterns. For example, if we want our chatterbot to answer for more than one hello pattern, we define few categories, one for each pattern, but we specify template reaction only ones:
< aiml >
< category >
< pattern >CZESC< /pattern >
< template >Witaj, jak się masz?< /template >
< /category >
< category >
< pattern >WITAJ< /pattern >
< template >< srai >CZESC< /srai >< /template >
< /category >
< category >
< pattern >CZESC *< /pattern >
< template ><srai>CZESC< /srai >< /template >
< /category >
< category >
< pattern >WITAJ *< /pattern >
< template >< srai >CZESC< /srai >< /template >
< /category >
< /aiml >
< srai > tag means, the chatterbot will answer for the pattern in the same way as for pattern defined between <srai> tags.
In the example above, the chatterbot will answer ''Witaj, jak sie masz?'' for any of four patterns: ''Czesc'', ''Czesc cokolwiek'', ''Witaj'' ''Witaj cokolwiek''. It seems to be unnecessary feature in AIML language, but only when we have very simple template elements… But because template tags can be more complex and because we get ability to change chatterbot reaction in one place of code without doing recursive changes it is really great utlity!
<random >
Another helpful and interesting tag is <random>, which makes our chatterbot more humanistic (if that is possible). Nested in <template> tag, makes our chatterbot to randomly chose one of few possible answers. We define answers as a list of elements between <li> and </li> tags.
< aiml >
< category >
< pattern >CZESC< /pattern >
< template >
< random >
< li >Witaj, jak się masz?< /li>
< li >No hej.< /li >
< li >Dzień dobry.< /li >
< /random >
< /template >
< /category >
< /aiml >
ode described above will make our chatterbot to chose one of three possible answers (''Witaj, jak sie masz?'', ''No hej'' or ''Dzien dobry'') for any ''Czesc'' urer’s input.
<star/>
<star/> tag nested inside of <template> makes chatterbot to paste string corresponding to asterisk (''*'') in pattern tag:
< aiml >
< category >
< pattern >CO TO JEST *< /pattern >
< template >Wiesz, nie mam pojęcia co może oznaczać słowo <star />.< /template >
< /category >
< /aiml >
In that example, for pattern ''Co to jest kot?'' chatterbot will answer: ''Wiesz, nie mam pojecia co moze oznaczac slowo kot''. In addition we can extend this tag to get the index of ''*'' from our pattern, like:
< aiml >
< category >
< pattern >* JEST *< /pattern >
< template >Nie byłbym taki pewien, może jednak < star/ > nie jest < starindex=''2''/ >.< /template >
< /category >
< /aiml >
< that >
<that> tag gives some more flexibility to <template> tag, by introducing possibility to check one of the previous chatterbot answers…It goes between <pattern> and <template> tags. Except checking if the user’s sentence match to the expression between <pattern> and </pattern>, application checks if the last chatterbot’s response matches expression between <this> and </this>. <this> tag can has also index attribute.
< aiml >
< category >
< pattern >*< /pattern >
< that >JAK MASZ NA IMIE< /that >
< template >Hmm, < star/ >. Calkiem ladne imie.< /template >
< /category >
< /aiml >
Example above makes chatterbot to repeat urer’s response to question : „Jak masz na imie?”
< think >
tags ‘comment’ text inside of <template> tags… Everything between <think> and </think> will not be printed to the screen.
< aiml >
< category >
< pattern >CO TO JEST KOT< /pattern >
< template >
Hmmm, < think >Ile on ma lat, ze nie wie co to kot? < /think >kot to zwierzę futerkowe, czworonożny ssak.
< /template >
< /category >
< /aiml >
The most important reason of having <think>, is to use it together with other tags that except of printing output to the screen have other functions (I will describe them later).
< get/ > i < set >
AIML Chatterbots are able to store information in variables that can be used later on…Programmer can achieve that with <get/> and <set> tags, what is shown below:
< aiml >
< category >
< pattern >MAM NA IMIE *< /pattern >
< template >
< set name=''userName'' >< star/ >< /set >
Hmm. To ładne imię.
< /template >
< /category >
< category >
< pattern >OPOWIEDZ MI DOWCIP</pattern >
< template >
OK. < get name=''userName''/ >. Spróbuję co¶ sobie przypomnieć, w tym czasie
Ty opowiedz jaki¶ mi.
< /template >
< /category >
< /aiml >
In the example above, first category stores name given by the user, and chatterbot will save it in variable called userName. Here, everything following string „Mam na imie” is considered as user’s name. In example, if user writes „Mam na imię Michal”, the uresName will be saved as “Michal”.
While <set> tag has corresponding closing tag </set>, the <get> tag is standalone tag. That means we don’t have closing version of <get>, and we use it as in category two in the example above.
Both <get> and <set> tags have ‘name’ attribute, which stands for variable’s name.
<set> tag except of setting the value of the variable, also prints it out to the screen, so in the example above chatterbot will print out the name and then add extra sentence after that.
To avoid that we might want to use <think> tag like in example below, where we store user’s name but we don’t print it out:
< aiml >
< category >
< pattern >MAM NA IMIE *< /pattern >
< template >
< think >< set name=''userName'' >< star/ >< /set >< /think >
Hmm. Ładne imię
< /template >
< /category >
< /aiml >
If the variable is not set, <get/> tag returns empty string of characters.
<topic>
<topic> is a very interesting, the only one outside of <category>, which can be placed directly between <aiml> tags, and it has to contain at least one <category> tag.
<topic> allows our application to keep control on the talk. In case the chatterbot is not able to answer to the user’s question, it can always use other answer but still connected to the topic.
We can set a variable responsible to keep a record about present topic. That variable has to be set during the design by <set> tag.
Check the example above:
< aiml >
< category >
< pattern >WITAJ< /pattern >
< template >
< think >< set name=“topic“ >powitanie< /set >< /think >
Dzień dobry
< /template >
< /category >
< topic name=''POWITANIE'' >
< category >
< pattern >*< /pattern >
< template >Jaka jest u Ciebie pogoda?< /template >
< /category >
< /topic >
< /aiml >
In example above, out chatterbot after pattern WITAJ will recognize it is in a topic “POWITANIE”. So it will not only answer to the user, but also remember what could be used to move nice talk forward…
In case the user asks something what is undefined in the chatterbot, our application will disregard the question and will find some response from categories in section <topic> that contain attribute name equal “POWITANIE”. Attribute is a simple regular expression, so it can contain “*” and “_”.
4. Examples
4.1. Little inteligent conversation:
Human: hej
Przewodnik po Krakowie: siema.
Human: jak masz na imie
Przewodnik po Krakowie: mam na imie Jaropelk, a Ty?
Human: Lukasz
Przewodnik po Krakowie: milo mi Cie poznac Lukasz.
Human: w jakim panstwie jest krakow
Przewodnik po Krakowie: Krakow jest krakow w Polsce.
Human: w jakim wojewodztwie lezy krakow
Przewodnik po Krakowie: Krakow lezy krakow w Malopolskim.
Human: ile osob mieszka w krakowie
Przewodnik po Krakowie: w Krakowie mieszka 756 267 osob.
Human: to duzo
Przewodnik po Krakowie: ano duzo, drugie co do liczby ludnosci miejsce w Polsce.
Human: jakie jest najwieksze
Przewodnik po Krakowie: najwieksza jest warszawa.
Human: nie lubie warszawy
Przewodnik po Krakowie: A nie sadzisz ze mielismy rozmawiac o Krakowie.
Human: tak
Przewodnik po Krakowie: Krakow to piekne miasto.
Human: jaka powierzchnie zajmuje krakow
Przewodnik po Krakowie: Krakow zajmuje 327 metrow kwadratowych.
Human: jakie sa najciekawsze miejsca w krakowie
Przewodnik po Krakowie: mysle ze, aby zobaczyc najciekawsze miejsca w Krakowie, nalezy sie wybrac na ''Droge krolewska''.
Human: co to jest droga krolewska
Przewodnik po Krakowie: Droga Krolewska, jest to trasa na ktorej znajduje sie wiele ciekawych i wartych zobaczenia miejsc.
Human: opowiedz mi o niej
Przewodnik po Krakowie: Droga Krolewska zaczyna sie w kosciele sw. Floriana przy Placu Matejki, gdzie Rektor wraz z Senatem Uniwersytetu witali niegdys nowego krola. Przechodzi nastepnie obok Barbakanu i resztek dawnych fortyfikacji miejskich i poprzez glowna brama wjazdowa ?Brame Florianska ?wkracza w obreb Starego Miasta.
Przez ulice Florianska, gdzie mozemy podziwiac szereg obiektow o ciekawej historii ( Dom Jana Matejki, hotel ''Pod Roza'', Jama Michalika) trasa wiedzie na Rynek Glowny, najwiekszy plac sredniowiecznej Europy, zdominowany przez gotycki Kosciol Mariacki.
W Bazylice Mariackiej znajduje sie olsniewajace dzielo Wita Stwosza ?najwiekszy gotycki oltarz w Europie. Z wyzszej wiezy kosciola co godzine grany jest hejnal. Niemalze naprzeciwko fasady kosciola stoi pomnik Adama Mickiewicza, bedacy popularnym miejscem spotkan zarowno krakowian, jak i turystow.
Centralne miejsce na Rynku zajmuja Sukiennice, rzadko spotykany przyklad sredniowiecznej budowli od wiekow sluzacej kupcom. Obecnie pierwsze pietro zajmuje Galeria Malarstwa Polskiego, a arkadowy parter liczne stoiska z pamiatkami i wyrobami rekodzielniczymi. Nad poludniowa czescia Rynku goruje wieza dawnego ratusza z roztaczajacym sie z niej wspanialym widokiem.
Z Rynku trasa kieruje sie obok malutkiego romanskiego kosciolka sw. Wojciecha oraz restauracji Wierzynek w ulice Grodzka. Po drodze na Wawel podziwiac mozemy gotyckie koscioly i zespoly klasztorne Dominikanow i Franciszkanow. Ten ostatni zdobia polichromia i witraze Stanislawa Wyspianskiego. Obok kosciola widnieje Palac Wielopolskich, dzis siedziba krakowskiego magistratu. Kontynuujac spacer ul. Grodzka, odwiedzic mozemy romanski kosciol sw. Andrzeja oraz sasiadujacy z nim barokowy kosciol ss. Piotra i Pawla z postaciami Apostolow na postumentach, we wnetrzu ktorego znajduje sie grobowiec ks. Piotra Skargi, zas pare metrow dalej ewangelicki kosciol sw. Marcina i kosciolek sw. Idziego.
Rownolegle do ul. Grodzkiej biegnie przesliczna ul. Kanonicza z niedawno odnowionymi kamienicami i niepowtarzalna atmosfera. Obie ulice prowadza prosto do stop Wzgorza Wawelskiego ?religijnego, duchowego i patriotycznego serca Polski, z Zamkiem Krolewskim, ktory uznawany jest za jedna z najwspanialszych rezydencji renesansowych w Europie. Szczegolnie oryginalna jest sala Poselska zwana takze ''Pod Glowami'', gdyz w kasetonowym stropie znajdowaly sie 194 rzezbione drewniane glowy; dzis pozostalo ich juz tylko 30. Najcenniejszym ze zbiorow wawelskich jest unikatowa kolekcja 137 arrasow, zdobiacych komnaty wykonano we Flandrii na zamowienie krola Zygmunta II Augusta.
Human: opowiedz mi o kosciele mariackim
Przewodnik po Krakowie: najwiekszy i najwazniejszy, po Katedrze Wawelskiej, kosciol Krakowa; od 1963 roku Bazylika. Nalezy do najbardziej znanych zabytkow Krakowa i Polski. Polozony jest przy polnocno_wschodnim narozniku Rynku Glownego, na Placu Mariackim. Zbudowano go w XIV w.
Human: gdzie jest kosciol mariacki
Przewodnik po Krakowie: Polozony jest przy polnocno_wschodnim narozniku Rynku Glownego, na Placu Mariackim.
Human: gdzie jest brama florianska
Przewodnik po Krakowie: Brama Florianska znajduje sie, na ulicy Florianskiej, przy wejsciu do Starego Miasta od Placu Matejki.
Human: opowiedz mi o bramie florianskiej
Przewodnik po Krakowie: pochodzi z poczatku XIV w. Liczy od galki helmu 34,5 m wysokosci. Nad brama wejsciowa znajdowal sie kiedys orzel zastapiony w 1882 r. orlem piastowskim wedlug projektu Jana Matejki wykonany przez Zygmunta Langmana. Wewnatrz znajduje sie klasycystyczny oltarz z poczatku XIX w. z poznobarokowa kopia cudownego obrazu Matki Boskiej Piaskowej. Od strony miasta widnieje plaskorzezba z XVIII w. wyobrazajaca sw. Floriana. Przy portalu bramnym do dzis zachowaly sie tez prowadnice na krate. Brame zbudowano ok. 1300 r., miesci sie ona w kwadratowej baszcie z dzikiego kamienia. W latach 1565_1566 w poblizu Bramy Florianskiej zbudowany zostal Arsenal Miejski. W XVI w. miescily sie w Bramie stajnie miejskie, nazywane wowczas nastella. Zwienczenie Bramy Florianskiej zostalo wykonane w 1660 r. W 1694 r. przeprowadzony zostal jej gruntowny remont. Na poczatku XIX w. rozwijajacy sie Krakow zaczal zajmowac tereny starych i zniszczonych murow obronnych. Prof. Feliks Radwanski wywalczyl 13 stycznia 1817 w senacie Rzeczypospolitej Krakowskiej decyzje o pozostawieniu dla potomnych fragmentow sredniowiecznej fortyfikacji. Zachowaly sie wiec czesci murow, a mianowicie Barbakan i Brama Florianska.
Human: jak dostac sie na zamek krolewski
Przewodnik po Krakowie: nalezy isc od rynku, ulica florianska, na poludniowe. Nastepnie skrecic w prawo, w ulice kanoniczna, obok placu Wita Stwosza. Isc prosto, az do wzgorza Wawelskiego, na ktorym jest Zamek.
Human: jakie sa szkoly wyzsze
Przewodnik po Krakowie: W Krakowie sa: Uniwersytety, Akademie, Politechnika; ktore Cie interesuja?
Human: akademie
Przewodnik po Krakowie: Akademia: Pedagogiczna, Sztuk Pieknych, Gorniczo_Hutnicza, Muzyczna, Wychowania Fizycznego, Teologiczna?
Human: sztuk pieknych
Przewodnik po Krakowie: co chcesz wiedziec o akademii sztuk pieknych.
Human: kto jest rektorem
Przewodnik po Krakowie: Jan Pamula.
Human: gdzie to jest
Przewodnik po Krakowie: pl. Jana Matejki 13.
Human: kiedy zalozono krakow
Przewodnik po Krakowie: Krakow zalozono przed IX wiekiem.
Human: jaki jest numer kierunkowy
Przewodnik po Krakowie: (+48) 12.
Human: jakie sa numery rejestracyjne
Przewodnik po Krakowie: Numery rejestracyjne zaczynaja sie od ''KR''.
Human: dzieki, czesc
Przewodnik po Krakowie: nie ma za co, czesc.
4.2. Not intelligent conversation and off topic:
Human: czesc
Przewodnik po Krakowie: witaj szefie.
Human: witaj
Przewodnik po Krakowie: dzien dobry.
Human: po co mowisz mi dzien dobry
Przewodnik po Krakowie: Moze chcesz sie dowiedziec ciekawych rzeczy?
Human: nie
Przewodnik po Krakowie: A moze jednak nie?
Human: moze
Przewodnik po Krakowie: Cos mi sie wydaje ze nie masz racji.
Human: dlaczego
Przewodnik po Krakowie: Moge Ci powiedziec kilka ciekawych informacji.
Human: co mnie to interesuje
Przewodnik po Krakowie: Ladna mamy pogode, prawda?
Human: nie
Przewodnik po Krakowie: Moge Ci powiedziec kilka ciekawych informacji.
Human: juz to slyszalem
Przewodnik po Krakowie: Moze chcesz sie dowiedziec ciekawych rzeczy?
Human: nie
Przewodnik po Krakowie: Naprawde?
Human: naprawde
Przewodnik po Krakowie: Powiedziec Ci cos ciekawego o Krakowie?
Human: tak
Przewodnik po Krakowie: co chcesz wiedziec?
Human: kto jest prezydentem
Przewodnik po Krakowie: Przezydentem Krakowa jest Jacek Majchrowski
Human: no i co z tego
Przewodnik po Krakowie: Moze chcesz wiedziec ilu jest mieszkancow?
Human: tak
Przewodnik po Krakowie: w Krakowie mieszka 756 267 osob.
Human: blee
Przewodnik po Krakowie: Moze chcesz wiedziec kto jest prezydentem?
Human: wiem juz
Przewodnik po Krakowie: A nie sadzisz ze mielismy rozmawiac o Krakowie.
Human: nie
Przewodnik po Krakowie: no to sie mylisz.
5. Conclusions
Chatbot project is very interestin, but if we want to create a bot, that doesn't have any problems in conversation with everyone on Earth, so we have to spend many hours to do it. As we know, chatbot isn't inteligent, it has only a base of informations. It uses algorithms to take good answer for gived question. The main problem is, that two peoples can ask two other question about this same thing. If we take, that on the Earth is six billions peoples, so we can see how difficult it is to create so big base, that everyone person can talk freely with a chatbot.
6. Literature
Wprowadzenie do AIML - Piotr Dobrowolski; http://docs.jedenpies.pl/files/AIML.pdf
Site of ALICE project; http://alicebot.org/
Sites about Krako:
http://www.krakow.pl
http://pl.wikipedia.org/wiki/Krak%C3%B3w
7. Bot www site
Bot is avaible at: http://pandorabots.com/pandora/talk?botid=de54adfaae36bc0d