Phobophiliac
Technical User
I have been coding a prolog parser and have come stuck it brings up my front screen then just says 'no' and stops all my rules are right and I cant find anything wrong can anyone help
thanx
Craig Dunn
heres the code
/*MAIN PROGRAM*/
:-ensure_loaded('drawtree.pl').
parse:-
write('Welcome to Craigs Parser'),nl,nl,
write('Please enter a sentence: '),nl,nl,
getsent(s),
test(s).
test(s)
hrase(s(Tree),s),write('The sentence is grammatically correct'),nl,nl,
write(s(Tree)),nl,nl,
print_tree(s(Tree)).
test(_):-write('Sentence is incorrect.'),nl.
/*READ IN A SENTENCE*/
getsent([W|Ws]):-get0(C),readword(C,W,C1),
restsent(W,C1,Ws).
restsent(W,_,[]):-lastword(W),!.
restsent(W,C,[W1|Ws]):-readword(C,W1,C1),
restsent(W1,C1,Ws).
readword(C,W,C1):-single_character(C),
!,name(W,[C]),get0(C1).
readword(C,W,C2):-in_word(C,NewC),!,get0(C1),
restword(C1,Cs,C2),name(W,[NewC|Cs]).
readword(C,W,C2):-get0(C1),readword(C1,W,C2).
restword(C,[NewC|Cs],C2):-in_word(C,NewC),!,
get0(C1),restword(C1,Cs,C2).
restword(C,[],C).
single_character(44). single_character(59).
single_character(58). single_character(63).
single_character(33). single_character(46).
in_word(C,C):-C>96,C<123. in_word(C,C):-C>47,C<58.
in_word(39,39). in_word(45,45).
in_word(C,L):-C>64,C<91,L is C+32.
lastword('.'). lastword('!'). lastword('?').
/*Sentence Structures*/
s(s(NP,VP))-->np(NP),vp(VP).
np(np(D,N))-->det(D),n(N). /*first sentence on the left*/
vp(vp(VP,NP))-->vp(VP),np(NP).
np(np(D,NP))-->det(D),np(NP).
np(np(A,NP))-->adj(A),np(NP).
np(np(A,N))-->adj(A),n(N).
/*LEXICON*/
det(det(the))-->[the].
det(det(a))-->[a].
n(n(hole))-->[hole].
v(v(was))-->[was].
adj(adj(dry))-->[dry].
adj(adj(bare))-->[bare].
adj(adj(sandy))-->[sandy].
heres the parse tree
---------------------------
Penn TreeBank Tree Diagrams
---------------------------
---------------S----------------
/ NP-SBJ -----------VP------------
/ \ / DET NP VP -------NP-PRD--------
t h w / DET -----NP-----
a / ADJP --NP---
d / ADJP NP
b / ADJP NP
s h
thanx
Craig Dunn
heres the code
/*MAIN PROGRAM*/
:-ensure_loaded('drawtree.pl').
parse:-
write('Welcome to Craigs Parser'),nl,nl,
write('Please enter a sentence: '),nl,nl,
getsent(s),
test(s).
test(s)
write(s(Tree)),nl,nl,
print_tree(s(Tree)).
test(_):-write('Sentence is incorrect.'),nl.
/*READ IN A SENTENCE*/
getsent([W|Ws]):-get0(C),readword(C,W,C1),
restsent(W,C1,Ws).
restsent(W,_,[]):-lastword(W),!.
restsent(W,C,[W1|Ws]):-readword(C,W1,C1),
restsent(W1,C1,Ws).
readword(C,W,C1):-single_character(C),
!,name(W,[C]),get0(C1).
readword(C,W,C2):-in_word(C,NewC),!,get0(C1),
restword(C1,Cs,C2),name(W,[NewC|Cs]).
readword(C,W,C2):-get0(C1),readword(C1,W,C2).
restword(C,[NewC|Cs],C2):-in_word(C,NewC),!,
get0(C1),restword(C1,Cs,C2).
restword(C,[],C).
single_character(44). single_character(59).
single_character(58). single_character(63).
single_character(33). single_character(46).
in_word(C,C):-C>96,C<123. in_word(C,C):-C>47,C<58.
in_word(39,39). in_word(45,45).
in_word(C,L):-C>64,C<91,L is C+32.
lastword('.'). lastword('!'). lastword('?').
/*Sentence Structures*/
s(s(NP,VP))-->np(NP),vp(VP).
np(np(D,N))-->det(D),n(N). /*first sentence on the left*/
vp(vp(VP,NP))-->vp(VP),np(NP).
np(np(D,NP))-->det(D),np(NP).
np(np(A,NP))-->adj(A),np(NP).
np(np(A,N))-->adj(A),n(N).
/*LEXICON*/
det(det(the))-->[the].
det(det(a))-->[a].
n(n(hole))-->[hole].
v(v(was))-->[was].
adj(adj(dry))-->[dry].
adj(adj(bare))-->[bare].
adj(adj(sandy))-->[sandy].
heres the parse tree
---------------------------
Penn TreeBank Tree Diagrams
---------------------------
---------------S----------------
/ NP-SBJ -----------VP------------
/ \ / DET NP VP -------NP-PRD--------
t h w / DET -----NP-----
a / ADJP --NP---
d / ADJP NP
b / ADJP NP
s h