Invoke the author tool by:
./create
Create a new problem to be saved into file fruit.pl
scala: val p = new Problem("fruit.pl")
p: wp.Problem = Problem with 0 statements
We could use the Statement
class to add new statements to the problem with the +=
operator.
However, it is more convenient to define a statement factory for entering them in natural language (denoted by its 3-letter ISO code):
scala: val en = new StatementFactory("Eng")
We can now use a predictive parser to enter a new sentence into the problem:
scala: p += en.read
Eng: John has seven fruit .
Notice the final period. We can keep track of how many statements our problem has by:
scala: p
res1: wp.Problem = Problem with 1 statements
Let us add some more facts:
scala: p += en.read
Eng: John has two apples , some oranges and three bananas .
scala: p += en.read
Eng: how many oranges does John have ?
To take a look to the internal representation of the problem, use print
:
scala: p.print
We can check if the problem is consistent (it does not contain contradictory statements) or complete (it has a single solution) by using the methods consistent
and complete
:
scala: p.complete
res3: Boolean = true
Remember to save the problem:
scala: p.save()
Saved to 'fruit.pl'
and now we can exit:
:q
We can now try to solve our problem, by calling model
with the file containing the problem:
./model fruit.pl
It shows us the statement of the problem:
John has seven fruit .
John has two apples , some oranges and three bananas .
how many oranges does John have ?
and displays the prompt:
?
We can always press return at the prompt (or type help
) for the system to suggest the proper action:
you must assign a variable to the oranges that John has .
But we do not know how to assign variables. Let us ask for an example:
? give me an example
let $x$ denote the animals that Mary has
Using this template we can now compose a definition for the variable x:
? let x denote the oranges that Mary has
you must assign a variable to the oranges that John has .
I forgot that we were dealing with John's fruit, not Mary's:
? let x denote the oranges that John has
it is right .
Press again return for the next suggestion:
you must split the fruit that John has .
This means that we have to specify how John's fruit are split in different classes:
? the fruit that John has are the apples that John has and the bananas that John has
you must consider oranges .
Yes, there are oranges too. Let us correct it:
? the fruit that John has are the apples that John has , the bananas that John has and the oranges that John has
it is right .
Good. Next suggestion:
you must write an equation which says that the fruit that John has are the bananas that John has ,
the oranges that John has and the apples that John has .
What about this?
? y plus 2 plus 3 is equal to 7
it doesn't follow .
This means that the proposed equation can not be deduced from the statement of the problem. Let us see what is wrong with the variable y:
? tell me about y
nothing is known about it .
Perhaps we used a different variable to denote the amount of oranges:
? tell me about the oranges that John has
the oranges that John has are $x$ oranges .
So we used x for it. Just to confirm it:
? tell me about x
$x$ denotes the oranges that John has .
We rewrite the equation using x:
? x plus 2 plus 3 is equal to 7
it is right .
Now the problem is correctly modeled. The next action will give us the solution:
the oranges that John has are two oranges .
To run the same problem but in Spanish, add the 3-letter-ISO code of the language as second argument:
./model examples/fruit.pl spa
...
Juan tiene siete frutas .
Juan tiene dos manzanas , algunas naranjas y tres plátanos .
¿ cuantas naranjas tiene Juan ?
Asking for help:
?
debes asignar una variable a las naranjas que Juan tiene .
Asking for an example:
? dame un ejemplo
denota las cartas que María tiene por $z$
The system will start/stop the GF-java service for you, but if you run into trouble you can check the state of the service by:
bin/wpserver status
and stop it by: bin/wpserver stop
. ↩