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!

PCFG and Prolog

Status
Not open for further replies.

JonMacCall

Programmer
Joined
Oct 25, 2012
Messages
1
Location
CA
Hello guys,

I have a problem and I need your help. I'm a super beginner in Prolog, so all my efforts in the last few days didn't give me any result!
I have a parser (Probabilistic Context-Free Grammar) and 10 sentences. When I compile the parser, and parse each of these sentences, it gives me 2 or 3 parse trees with their probabilities. my problem is that for some of the sentences, the parse tree with highest probability is not what I expect (I have the desired parse trees and I can compare them with my result).

I want to improve the grammar (without changing the probabilities) to get correct results for all sentences. I know what the problem is. It's the relation of propositional phrases and the verb. I think I have to add some constraints to my code (i.e. when the verb is 'put' the propositional phrase should be in same level with verb and noun phrase [emphasize verb phrase], and when the verb is 'take' propositional phrase should emphasize the noun phrase). But I don't know how to do it!

Any help would be greatly appreciated.

Thanks,

Jonathan
 
I take a look at your code.
I think that you can use dynamic facts to know what kind of verb is used.
Your code of pcfg2.pl could be
Code:
:- dynamic emphasis/1.

s(P0, s(V, NP)) --> 
	v(P1, V), 
	np(P2, NP), 
	{emphasis(Emph),
	 % use of Emph
	 %  P0 is ....
	 % instead of 
	 P0 is P1*P2*0.35
	}.
s(P0, s(V, NP, PP)) --> 
	v(P1, V), 
	np(P2, NP), 
	pp(P3, PP), 
	{emphasis(Emph),
	 % use of Emph (put or take)
	 %  P0 is ....
	 % instead of 
	 P0 is P1*P2*P3*0.65}.

np(P0, np(D, N)) --> det(P1, D), n(P2, N), {P0 is P1*P2*0.36}.
np(P0, np(D, A, N)) --> det(P1, D), a(P2, A), n(P3, N), {P0 is P1*P2*P3*0.46}.
np(P0, np(D, N, PP)) --> det(P1, D), n(P2, N), pp(P3, PP), {P0 is P1*P2*P3*0.13}.
np(P0, np(D, A, N, PP)) --> det(P1, D), a(P2, A), n(P3, N), pp(P4, PP), {P0 is P1*P2*P3*P4*0.05}.

pp(P0, pp(P, NP)) --> p(P1, P), np(P2, NP), {P0 is P1*P2*1.0}.

v(0.65, v(put)) --> {assert(emphasis(put)}, [put].
v(0.35, v(take)) --> {assert(emphasis(take)}, [take].
......
You must read manual for assert/retract to understand the way to use dynamic facts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top