Information Technology Reference
In-Depth Information
This change to John's status happens only within the Prolog session. The file with the
world model remains unchanged. This means that if the programmer exits, restarts
Prolog, and then reloads the file, John's status will again show as single. To keep
John's married status as a permanent part of the world model, the knowledge base of
clauses would have to be saved to a new file, which the program could then run.
8.3.3 Simple declarative sentences
For simplicity,
consider declarative sentences described by the following single
grammar rule:
→
SD
NP copula_verb preposition NP
This is a special case of the sentences described by the
S
category of the grammar in
figure 8.1. An example sentence of this form is the following:
The man with the red hat is in the park with the big tree.
Parsing sentences like these requires a predicate
sd
(
that holds when
z
is a list of
words that forms a simple declarative sentence. In addition, the parser should find
the objects corresponding to the two noun phrases, and update the world model. For
the example sentence shown here, it should assert
in(john,queens_park)
.
To parse and interpret declaratives in this way, prepositions must be used dynam-
ically, not just to locate objects in the world model. The simplest way to do this is to
extend the lexicon to include a predicate
add_for_preposition
that states how new
information for each preposition should be handled:
add_for_preposition(on,X,Y) :- assert(on(X,Y)).
add_for_preposition(in,X,Y) :- assert(in(X,Y)).
add_for_preposition(beside,X,Y) :-
assert(beside(X,Y)), assert(beside(Y,X)).
Note that the assertions for
beside
give both orders of arguments, since that is the
convention in the world model (for example, for Linda and Mary). Note also that
there is no clause for the preposition
with
. This is because of its ambiguity: given the
statement
X
is with
Y
, it is not clear what relation should be updated.
With clauses like these in the lexicon, simple declarative sentences can be handled
using the program in figure 8.15. The
split_words
predicate is used to break a quoted
string into a list of words. The
sd
predicate takes this list of words and uses
append
to break it into a noun phrase, the constant
is
, a single word
Prep
(which must
be a preposition), and a second noun phrase. The predicate
np
is used to find each
referent, and the predicate
add_for_preposition
is used to change the world model.
z
)