CSC 8520-001: Definite Clause Grammars in Prolog
Wednesdays from 6:15pm to 8:45pm in Mendel G29
Dr. David Matuszek, Mendel 162C, (610) 519-5654
Villanova University, Spring 2000

grammar.pl
sentence --> noun_phrase, verb_phrase.
noun_phrase --> article, unqualified_noun_phrase.
unqualified_noun_phrase --> noun.
unqualified_noun_phrase --> noun, prepositional_phrase.
unqualified_noun_phrase --> adjective, unqualified_noun_phrase.
prepositional_phrase --> preposition, noun_phrase.
verb_phrase --> transitive_verb_phrase ; intransitive_verb_phrase.
transitive_verb_phrase --> transitive_verb, noun_phrase.
transitive_verb_phrase --> transitive_verb, noun_phrase, adverb.
intransitive_verb_phrase --> intransitive_verb.
intransitive_verb_phrase --> intransitive_verb, prepositional_phrase.

noun --> [hobbit] ; [troll] ; [gnome].
article --> [a] ; [the] ; [this] ; [every].
transitive_verb --> [fought] ; [saw] ; [threw].
intransitive_verb --> [sat] ; [slept] ; [flew].
adjective --> [green] ; [ugly] ; [friendly] ; [huge] ; [beautiful].
preposition --> [over] ; [under] ; [around] ; [through].
adverb --> [quickly] ; [fiercely] ; [hopelessly] ; [well].

 

Welcome to SWI-Prolog (Version 3.3.0)
Copyright (c) 1993-1999 University of Amsterdam. All rights reserved.

For help, use ?- help(Topic). or ?- apropos(Word).

% c:/_Prolog/grammar.pl compiled 0.00 sec, 5,160 bytes

?- listing(sentence).

sentence(A, B) :-
        noun_phrase(A, C),
        verb_phrase(C, B).

Yes
?- sentence([a, hobbit, slept], []).

Yes
?- sentence([a, hobbit, slept]).
ERROR: Undefined procedure: sentence/1
ERROR:     However, there are definitions for:
ERROR:         sentence/2

No
?- phrase(sentence, [a, hobbit, slept]).

Yes
?- phrase(prepositional_phrase, [around, the, troll]).

Yes
?- phrase(sentence, S).

S = [a, hobbit, fought, a, hobbit] ;

S = [a, hobbit, fought, a, troll] ;

S = [a, hobbit, fought, a, gnome] ;

S = [a, hobbit, fought, a, hobbit, over, a, hobbit] 

Yes
?- phrase(prepositional_phrase, PP).

PP = [over, a, hobbit] ;

PP = [over, a, troll] ;

PP = [over, a, gnome] ;

PP = [over, a, hobbit, over, a, hobbit] 

Yes
?-