<< Prev | - Up - | Next >> |
Driver Predicate and Code Summary for this Chapter.
We've already seen a first run of our semantically annotated DCG, and we've implemented a module for -conversion. Now we shall put them together in a predicate
firstLambda/0
to get our first real semantic construction system. Here's the code of firstLambda/0
:
firstLambda :-
readLine(Sentence),
s(Formula,Sentence,[]),
resetVars,vars2atoms(Formula),
betaConvert(Formula,Converted),
printRepresentations([Converted]).
This predicate first converts the keyboard input into a list of Prolog atoms (using readLine/0
form comsemLib.pl
). Then it uses the semantically annotated DCG from firstLambda.pl
and tries to parse a sentence.
So far, so good. But what are the two calls resetVars,vars2atoms(Formula)
for? The reason why we have to include them is that we've broken our representational convention for variables (we've explained why in Section 3.5.7). Hence the Formula
coming from the call s(Formula,Sentence,[])
may still contain Prolog variables. For instance when we construct the semantics for the sentence ``John walks'', we will get something like lambda(_G365,_G365@john)@lambda(_G371,walk(_G371))
.
Undo Variable Cheat
So we undo our little cheat before going on. Calling resetVars,vars2atoms(Formula)
(see Section ``vars2atoms/1'') instantiates the Prolog variables in Formula
with new (and consistently distinct) variables-as-atoms, according to our convention. Finally, the resulting -expression is
-converted by our predicate
betaConvert/2
. In the last step, the resulting formula is printed out (the predicate printRepresentations/1
used for this purpose is documented here).
Before we turn to the exercises for this chapter, we give a listing of the files that contain the code discussed in this chapter. You run our -based semantic construction program by:
Consulting the file runningFirstLambda.pl
, which contains the driver predicate we've just seen:
?- [runningFirstLambda].
Calling the driver predicate:
?- firstLambda.
Entering a sentence of your choice at the prompt.
Code For This Chapter
Our very first experimantal DCG. | |
The code for our first attempt at semantic construction, using the | |
DCG for semantic construction using | |
| |
Driver predicate for our first lambda approach. | |
Generating new variables | |
Auxiliaries. | |
Operator definitions. |
<< Prev | - Up - | Next >> |