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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing

Status
Not open for further replies.

Yupar

Programmer
Mar 11, 2004
4
AU
Hi,

I am learning grammar and parsing. Here I can parse a very simple sentence
"John eats the cat". BUT HOW CAN I EXTEND IT TO PARSE A MORE COMPLICATED SENTENCE LIKE " The wombat on Jane give him". The parts of speech to be covered are: art noun prep pro proper v
("pro" signifies pronoun, "proper" signifies proper noun, "prep" signifies preposition).
The grammar rules to be covered are:

s -> np vp
vp -> v np
np -> proper
np -> art cnp2
cnp2 -> cnp
cnp -> noun
(s=sentence,np=noun phrase,vp=verb phrase,proper=proper noun,art=article,cnp=common noun phrase,v=verb)

Current simple parsing in prolog
% grammar rules: (the first four only yet)

s(P1,P3,s(NP,VP)) :- np(P1,P2,NP), vp(P2,P3,VP).
vp(P1,P3,vp(v(Verb),NP)) :- v(P1,P2,Verb), np(P2,P3,NP).
np(P1,P2,np(name(Name))) :- proper(P1,P2,Name).
np(P1,P3,np(art(Art),noun(Noun))) :- art(P1,P2,Art), noun(P2,P3,Noun).

% lexicon entries:

isname(john).
isverb(ate).
isart(the).
isnoun(cat).

% rules to do lexical analysis - that is to classify words according
% to their part of speech:

art(From, To, Word) :- word(Word, From, To), isart(Word).
noun(From, To, Word) :- word(Word, From, To), isnoun(Word).
v(From, To, Word) :- word(Word, From, To), isverb(Word).
proper(From, To, Word) :- word(Word, From, To), isname(Word).

% An example sentence to parse:

word(john, 1, 2).
word(ate, 2, 3).
word(the, 3, 4).
word(cat, 4, 5).

____________
Lexical entries for a more complicated sentence
isart(the, the1).
isname(jane, "Jane").
isnoun(wombat, wombat1).
isprep(on, on_loc1).
ispro(him, he1).
isverb(give, give1).

Regards,
Y
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top