%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% %% Probabilistic Syntactic structure-building DCG in DCG notation %% %% Mark Steedman, November 2002, rev. November 2003, Nov. 05 %% %% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Stuff to overcome Sictus' abbreviation of list terms portray(Term) :- is_list(Term), write(Term). is_list([]). is_list([_|_]). %%%% End of stuff s( P0, [s,[NP, VP]]) --> %Rule r1 np(P1, NP), vp(P2, VP), {p(r1, P), P0 is P*P1*P2}. p(r1, 1.0). np(P0, [np,[PN]]) --> %Rule r2 pn(P1, PN), {p(r2,P), P0 is P*P1}. p(r2, 0.3). np(P0, [np,[Det, N, Rel]]) --> %Rule r3 det(P1, Det), n(P2, N), optrel(P3, Rel), {p(r3,P), P0 is P*P1*P2*P3}. p(r3, 0.7). ppwith(P0, [ppwith,[PREP, NP]]) --> %Rule r41 pwith(P1, PREP), np(P2, NP), {p(r41,P), P0 is P*P1*P2}. p(r41, 1.0). ppon(P0, [ppon,[PREP, NP]]) --> %Rule r42 pon(P1, PREP), np(P2, NP), {p(r42,P), P0 is P*P1*P2}. p(r42, 1.0). vp(P0, [vp,[TV, NP]]) --> %Rule r5 tv(P1, TV), np(P2, NP), {p(r5,P), P0 is P*P1*P2}. p(r5, 0.4). vp(P0, [vp,[DTV, NP, PP]]) --> %Rule r61 dtv(P1, DTV), np(P2, NP), ppwith(P3, PP), {p(r61,P), P0 is P*P1*P2*P3}. p(r61, 0.4). vp(P0, [vp,[DTV, NP, PP]]) --> %Rule r62 dtv(P1, DTV), np(P2, NP), ppon(P3, PP), {p(r62,P), P0 is P*P1*P2*P3}. p(r62, 0.05). vp(P0, [vp,[IV]]) --> %Rule r7 iv(P1, IV), {p(r7,P), P0 is P*P1}. p(r7, 0.15). optrel(P0, [rel,[0]]) --> [], {p(r8,P), P0 is P}. %Rule r8 p(r8, 0.8). optrel(P0, [rel,[PP]]) --> ppwith(P1, PP), {p(r91, P), P0 is P*P1}. %Rule r91 p(r91, 0.1). optrel(P0, [rel,[PP]]) --> ppon(P1, PP), {p(r92, P), P0 is P*P1}. %Rule r92 p(r92, 0.099). optrel(P0, [rel,[WH, VP]]) --> %Rule r10 relpro(P1, WH), vp(P2, VP), {p(r10, P), P0 is P*P1*P2}. p(r10, 0.001). %pn(P0, pn[harry]) --> [harry], {p(harry, pn, P1), P0 is P1. %% etc. -- very tedious, therefore .... pn(P0, [pn,[Word]]) --> [Word], {pn(Word), p(Word, pn, P1), P0 is P1}. pn(gilbert). pn(george). p(gilbert, pn, 0.5). p(george, pn, 0.5). iv(P0, [iv,[Word]]) --> [Word], {iv(Word), p(Word,iv,P1), P0 is P1}. iv(walks). iv(talks). p(walks, iv, 0.7). p(talks, iv, 0.3). tv(P0, [tv,[Word]]) --> [Word], {tv(Word), p(Word,tv,P1), P0 is P1}. tv(sees). tv(shoots). p(sees, tv, 0.7). p(shoots, tv, 0.3). dtv(P0, [dtv,[Word]]) --> [Word], {dtv(Word), p(Word,dtv,P1), P0 is P1}. dtv(sees). dtv(shoots). p(sees, dtv, 0.6). p(shoots, dtv, 0.4). det(P0, [det,[Word]]) --> [Word], {det(Word), p(Word,det,P1), P0 is P1}. det(a). det(the). p(a, det, 0.5). p(the, det, 0.5). n(P0, [n,[Word]]) --> [Word], {n(Word), p(Word, n, P1), P0 is P1}. n(frog). n(man). n(telescope). n(revolver). p(frog, n, 0.3). p(man, n, 0.3). p(telescope, n, 0.2). p(revolver, n, 0.1). pwith(P0, [pwith,[Word]]) --> [Word], {pwith(Word), p(Word, pwith, P1), P0 is P1}. pwith(with). p(with, pwith, 1.0). pon(P0, [pon,[Word]]) --> [Word], {pon(Word), p(Word, pon, P1), P0 is P1}. pon(on). p(on, pon, 1.0). relpro(P0, [relpro,[Word]]) --> [Word], {relpro(Word), p(Word, relpro, P1), P0 is P1}. relpro(that). p(that, relpro, 1.0). %| ?- s(P, T, [gilbert, sees, a, frog, with, a, telescope],[]). %P = 2.4695999999999995E-05, %T = [s,[[np,[[pn,[gilbert]]]], % [vp,[[tv,[sees]], % [np,[[det,[a]],[n,[frog]], % [rel,[[ppwith,[[pwith,[with]], % [np,[[det,[a]],[n,[telescope]],[rel,[0]]]]]]]]]]]]]] ? ; %P = 0.000169344, %T = [s,[[np,[[pn,[gilbert]]]], % [vp,[[dtv,[sees]], % [np,[[det,[a]],[n,[frog]],[rel,[0]]]], % [ppwith,[[pwith,[with]],[np,[[det,[a]],[n,[telescope]],[rel,[0]]]]]]]]]] ? ; %no %| ?- s(P, T, [gilbert, sees, a, man, with, a, telescope],[]). %P = 2.4695999999999995E-05, %T = [s,[[np,[[pn,[gilbert]]]], % [vp,[[tv,[sees]], % [np,[[det,[a]],[n,[man]], % [rel,[[ppwith,[[pwith,[with]], % [np,[[det,[a]],[n,[telescope]],[rel,[0]]]]]]]]]]]]]] ? ; %P = 0.000169344, %T = [s,[[np,[[pn,[gilbert]]]], % [vp,[[dtv,[sees]], % [np,[[det,[a]],[n,[man]],[rel,[0]]]], % [ppwith,[[pwith,[with]],[np,[[det,[a]],[n,[telescope]],[rel,[0]]]]]]]]]] ? ; %no %| ?-