DCG parsing - Natural Language in Prolog
From: Neil (neilyork82_at_yahoo.com)
Date: 05/17/04
- Next message: Tom Schrijvers: "Re: CLP trick: ...Code correction."
- Previous message: Dirk Mittler: "Re: ...Code with same effect."
- Next in thread: Bill Spight: "Re: DCG parsing - Natural Language in Prolog"
- Reply: Bill Spight: "Re: DCG parsing - Natural Language in Prolog"
- Reply: rg: "Re: DCG parsing - Natural Language in Prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 May 2004 16:56:47 +1000
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:
a.. s -> np vp
b.. vp -> v np
c.. np -> proper
d.. np -> art cnp2
e.. cnp2 -> cnp
f.. 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 more complicated sentence
isart(the, the1).
isname(jane, "Jane").
isnoun(wombat, wombat1).
isprep(on, on_loc1).
ispro(him, he1).
isverb(give, give1).
Regards,Neil
- Next message: Tom Schrijvers: "Re: CLP trick: ...Code correction."
- Previous message: Dirk Mittler: "Re: ...Code with same effect."
- Next in thread: Bill Spight: "Re: DCG parsing - Natural Language in Prolog"
- Reply: Bill Spight: "Re: DCG parsing - Natural Language in Prolog"
- Reply: rg: "Re: DCG parsing - Natural Language in Prolog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|