This is the repository of the Python (3.7+) implementation of AD-CASPAR (Abductive-Deductive Cognitive Architecture System Planned and Reactive) referred to the paper AD-CASPAR: Abductive-Deductive Cognitive Architecture based on Natural Language and First Order Logic Reasoning, presented in the 4th Workshop on Natural Language for Artificial Intelligence (NL4AI 2020) co-located with the 19th International Conference of the Italian Association for Artificial Intelligence (AI*IA 2020). This architecture inherits all the features of his predecessor CASPAR, extending them with a two-level Clauses Knowledge Base, an abductive inference as pre-phase of deduction, and a Telegram chatbot prototype implementing Question Answering tecniques for Polar and Wh-Questions. Such chatbot can have both goal-oriented and conversational features.
This repository has been tested on Pycharm 2019.1.2 x64 with the following packages versions:
- Phidias (release 1.3.4.alpha)
- SpaCy (ver. 2.2.4)
- Natural Language Toolkit (ver. 3.5)
- python-telegram-bot (ver. 12.8)
- pymongo (ver. 3.10.1)
The address of a MongoDB server must be specified by changing the value of HOST (section LKB) in config.ini.
> git clone https://github.com/corradosantoro/phidias
> python setup.py install
> pip install readline
> pip install parse
> python -m pip install pyreadline
> python -m pip install parse
> python -m pip install spacy
> python -m spacy download en_core_web_lg
from prompt:
> python -m pip install nltk
from python console:
> import nltk
> nltk.download('wordnet')
> nltk.download('omw-1.4')
> python -m pip install python-telegram-bot
In the case of using a mongoDB container, the latter can be accessed by the link: http://localhost:8087/ (user/password are set in config.ini).
> docker-compose -f mongo.yaml up
> python -m pip install pymongo
Before going any further it is first necessary to create a new telegram bot by following the instruction in this page. The returned token must be put in TELEGRAM_TOKEN (AGENT Section) in config.ini.
> python ad-caspar.py
PHIDIAS Release 1.3.4.alpha (deepcopy-->clone,micropython,py3)
Autonomous and Robotic Systems Laboratory
Department of Mathematics and Informatics
University of Catania, Italy (santoro@dmi.unict.it)
eShell: main >
eShell: main > go()
eShell: main > AD-Caspar started! Bot is running...
After the agent is started, the Belief KB can be inspected with the following command:
eShell: main > kb
WAIT(1000)
eShell: main >
The value inside the belief WAIT represents the maximum duration of each session in seconds. It can be changed by modifying the value of the variable WAIT_TIME (AGENT Section) in config.ini. The two layers of the Clauses KB (respectively High KB and Low KB) can be inspected with the following commands:
eShell: main > hkb()
0 clauses in High Knowledge Base
eShell: main > lkb()
0 clauses in Low Knowledge Base
eShell: main >
both High KB e Low KB can be emptied with the following commands:
eShell: main > chkb()
High Clauses kb initialized.
0 clauses deleted.
eShell: main > clkb()
Low Clauses kb initialized.
0 clauses deleted.
eShell: main >
to start a session you have to go to the telegram bot window and type the word "hello". Assertions must end with "." and questions must end with "?". Otherwise the utterances will be processed as direct commands or routines (check out the page of CASPAR for details).
After such interaction with the telegram bot, the two layers of the Clauses KB will be as it follows:
eShell: main > hkb()
eShell: main > In_IN(Become_VBD(Barack_NNP_Obama_NNP(x1), Of_IN(President_NN(x2), United_NNP_States_NNP(x3))), N2009_CD(x4))
1 clauses in High Knowledge Base
eShell: main > lkb()
In_IN(Become_VBD(Barack_NNP_Obama_NNP(x1), Of_IN(President_NN(x2), United_NNP_States_NNP(x3))), N2009_CD(x4))
['In_IN', 'Become_VBD', 'Barack_NNP_Obama_NNP', 'Of_IN', 'President_NN', 'United_NNP_States_NNP', 'N2009_CD']
Barack Obama became the president of United States in 2009.
1 clauses in Low Knowledge Base
This prototype gives the change to feed automatically the Clauses KB from file text, set with the parameter FILE_KB_NAME (AGENT section), by the means of the command feed() given in the phidias prompt. Three examples knowledge base of increasing size are available for testing purposes: west25.txt, west104.txt, west303.txt.
A detailed overview of how the wh-questions are treated is provided here. In the following picture are shown two different kind of query with wh-questions:
This prototype give back as result a substitutions containing the literal as logical representation of the snipplet-result of the query. After a bot reboot, as we can see in the following picture, the result will be slightly different because the High Clauses KB will be empty and must be populated getting clauses from the Low Clauses KB, taking in account of a confidence level about the presence of the lemmatized labels in the clauses. Such a confidence level, depending of the domain can be changed by modifying the value of MIN_CONFIDENCE (LKB Section) in config.ini. The first query will get a result form the Low KB (From LKB: True), while the second one from the High KB (From HKB: True); thats because the content of the High KB is preserved during the session, otherwise it can be emptied after a query by changing the value of EMPTY_HKB_AFTER_REASONING (LKB Section) in config.ini.
By changing the values of SHOW_REL (QA Section) in config.ini, it can be possible to show the clauses involved in the abduction pre-inference, together with their confidences.
In the bot closed world assumption, the agent can give back only answers related to its onw knowledge, otherwise it will return False. Optionally, with the value of SHOW_REL set to true, the closest results can be shown together with their confidence level:
In order to test the Nested Reasoning inherited from CASPAR by using the Telegram bot, you must be sure some parameters in config.ini are as it follows:
Section [NL_TO_FOL]:
- ASSIGN_RULES_ADMITTED = true
Section [REASONING]
- NESTED_REASONING = true
Section [GEN]
- GEN_PREP = true
- GEN_ADJ = true
- GEN_ADV = true
After a failed attempt using the High KB (From HKB: False), a successful reasoning is achieved (From LKB: True) getting query-relevant clauses from the Low KB with a MIN_CONFIDENCE (Section [LKB] of config.ini) greater than 0.6.