Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog Parser

Status
Not open for further replies.

Phobophiliac

Technical User
May 13, 2003
1
GB
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):phrase(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

 
what was the bit of the code that gave the purple face in that lot? Hint: untick the 'Process TGML' checkbox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top