- Harry Potter (imaginary worlds)
- Ostriches and wounded birds don't fly (Birds Rulebase)
- Birds typically don't fly, but ostriches can (Birds Rulebase)
- Electricity Rulebase 1
Ask prolexa to "load example xyz" and the memory will be wiped and the facts and rules as given by the example are loaded.
prolexa> "load example harry_potter".
prolexa> "load example bird_1".
prolexa> "load example bird_2".
prolexa> "load example electricity".
The riddle's "Is it true?" questions can be tested by either asking a direct question:
prolexa> "Is the bell is ringing".
or by asking prolexa to explain:
prolexa> "Explain why Bill cannot fly".
In some of our cases, negation works as failure.
prolexa> "Muggles cannot do magic".
prolexa> "If someone can do magic then they can vanish".
prolexa> "Mr Dursley is a Muggle".
prolexa> "Can Mr Dursley vanish".
Other times we had to implement a rule to check if the information had been explicitly declared or inferred. For example in this case, it needs to be implied that when something has not been declared as abnormal, that it is then normal. This example needs to handle both negations and conjunctions.
prolexa> "If someone is an ostrich then they are abnormal".
prolexa> "If someone is a bird and not abnormal then they can fly".
prolexa> "Explain why Arthur can fly".
Sentences and properties can be conjoined using “and” meaning that an utterance may include more than one fact and the head or body of a rule may have multiple parts.
The following will determine that Colin is wounded and a bird from a single utterance
prolexa> "Colin is a bird and wounded".
prolexa> "Is Colin wounded".
prolexa> "Is Colin a bird".
The following shows an example of a conditional sentence making a rule with a conjunctive body:
prolexa> "If the circuit has the switch and the switch is on then the circuit is complete".
prolexa> "The circuit has the switch".
prolexa> "The switch is on".
prolexa> "Explain why the circuit is complete".
Transitive verbs require a subject and an object so need binary rather than unary predicates. For example:
prolexa> "The circuit has a switch".
adds the rule has(circuit, switch):-true
to the rulebase
Common nouns can be handled in two ways. The circuit example required nouns to be regarded as constants in some cases as opposed to properties of proper nouns such as in the bird example.
prolexa> "bill is an ostrich".
prolexa> "the bell is ringing".
prolexa> "if someone is an ostrich then they are abnormal".
adds the rules (ostrich(bill):-true),(ringing(bell):-true),(abnormal(X):-ostrich(X))
to the rulebase
This repository contains Prolog code for a simple question-answering assistant. The top-level module is prolexa.pl
, which can either be run in the command line or with speech input and output through the
alexa developer console.
The heavy lifting is done in
prolexa_grammar.pl
, which defines DCG rules for
sentences (that are added to the knowledge base if they don't already follow),
questions (that are answered if possible), and
commands (e.g., explain why something follows); and
prolexa_engine.pl
, which implements reasoning by means of meta-interpreters.
Also included are nl_shell.pl
, which is taken verbatim from Chapter 7 of Simply Logical,
and an extended version nl_shell2.pl
, which formed the basis for the prolexa
code.
The code has been tested with SWI Prolog versions 7.6.0 and 8.0.3.
% swipl prolexa.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- prolexa_cli.
prolexa> "Tell me everything you know".
*** utterance(Tell me everything you know)
*** goal(all_rules(_7210))
*** answer(every human is mortal. peter is human)
every human is mortal. peter is human
prolexa> "Peter is mortal".
*** utterance(Peter is mortal)
*** rule([(mortal(peter):-true)])
*** answer(I already knew that Peter is mortal)
I already knew that Peter is mortal
prolexa> "Explain why Peter is mortal".
*** utterance(Explain why Peter is mortal)
*** goal(explain_question(mortal(peter),_8846,_8834))
*** answer(peter is human; every human is mortal; therefore peter is mortal)
peter is human; every human is mortal; therefore peter is mortal
Follow the steps below if you want to use the Amazon Alexa speech to text and text to speech facilities. This requires an HTTP interface that is exposed to the web, for which we use Heroku.
swipl -g "mk_prolexa_intents, halt." prolexa.pl
The intents are found in prolexa_intents.json
. You can copy and paste the contents of this file while building your skill on the
alexa developer console.
To build:
docker build . -t prolexa
To run:
docker run -it -p 4000:4000 prolexa
To test the server:
curl -v POST http://localhost:4000/prolexa -d @testjson --header "Content-Type: application/json"
Prerequisites:
- Docker app running in the background
- Installed Heroku CLI (
brew install heroku/brew/heroku
)
To see the status of your Heroku webapp use
heroku logs
in the prolexa directory.
-
Clone this repository
git clone git@github.com:So-Cool/prolexa.git cd prolexa
-
Login to Heroku
heroku login
-
Add Heroku remote
heroku git:remote -a prolexa
-
Before you start open your local copy of Prolexa and login to Heroku
cd prolexa heroku container:login
-
Change local files to your liking
-
Once you're done push them to Heroku
heroku container:push web heroku container:release web
-
Test your skill and repeat steps 2. and 3. if necessary
-
Once you're done commit all the changes and push them to GitHub
git commit -am "My commit message" git push origin master