Docsity

Adding Phrase Structure and Meaning to DCG in Prolog, Slides of Formal Semantics

Toggle sidebar
bg1
Adding Phrase Structure
• Modify basic DCG into one that includes phrase structure
•Basic DCG:
sentence --> np, vp.
vp --> v, np.
v --> [likes].
np --> [john].
np --> [mary].
•Query: (we supply two arguments:
sentence as a list and an empty list)
?- sentence([john,likes,mary],[]).
Yes (Answer) •Phrase Structure DCG:
sentence(sentence(NP,VP)) --> np(NP), vp(VP).
vp(vp(V,NP)) --> v(V), np(NP).
v(v(likes)) --> [likes].
np(np(john)) --> [john].
np(np(mary)) --> [mary].
•Modified Query: (supply one more argument)
•?-sentence(PS,[john,likes,mary],[]).
PS = sentence(np(john),vp(v(likes),np(mary)))
sentence
np
John np
vp
v
Mary
likes
sentence(np(john),vp(v(likes),np(mary)))
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Adding Phrase Structure and Meaning to DCG in Prolog and more Slides Formal Semantics in PDF only on Docsity!

Adding Phrase Structure

-^ Modify basic DCG into one that includes phrase structure• Basic DCG:^ sentence

-->^ np,^

vp. vp^ -->^ v,

np.

v^ -->^ [likes].np^ -->^ [john].np^ -->^ [mary]. • Query :^ (we supply two arguments:sentence as a list and an empty list) ?-^ sentence([john,likes,mary],[]).Yes^ (Answer)

-^ Phrase Structure DCG:^ sentence(sentence(NP,VP))

-->^ np(NP),

vp(VP).

vp(vp(V,NP))

-->^ v(V),

np(NP). v(v(likes))

-->^ [likes]. np(np(john))

-->^ [john]. np(np(mary))

-->^ [mary].

-^ Modified Query

:^ (supply one more argument)

-^ ?-^ sentence(

PS ,[john,likes,mary],[]). PS^ =^ sentence(np(john),vp(v(likes),np(mary)))

sentencenp John^

vp npv Mary

likes

sentence(np(john),vp(v(likes),np(mary)))

Adding Meaning

-^ modify basic DCG into one that includes meaning• Basic DCG:^ sentence

-->^ np,^

vp. vp^ -->^ v,

np.

v^ -->^ [likes].np^ -->^ [john].np^ -->^ [mary]. • Query :^ (we supply two arguments:sentence as a list and an empty list) ?-^ sentence([john,likes,mary],[]).Yes^ (Answer)

-^ Meaning DCG:^ –^ sentence(P)

-->^ np(NP1),

vp(P), {saturate1(P,NP1)}.– vp(P)^ -->

v(P),^ np(NP2),

{saturate2(P,NP2)}.

-^ v(likes(X,Y))

-->^ [likes].

-^ np(john)

-->^ [john].

-^ np(mary)

-->^ [mary].

-^ saturate1(P,A)

:-^ arg(1,P,A).

-^ saturate2(P,A)

:-^ arg(2,P,A).

-^ Query

:^ (supply one more argument)

-^ ?-^ sentence(M,[john,likes,mary],[]).^ M^ =^

likes(john,mary)

argument saturation arg(Nth,Predicate,Argument) means make

Nth^ argument of Predicate

equal to^ Argument {^ ^

}^ means call Prolog

{arg(2,VBm,NPm)}

means call^ arg(2,VBm,NPm)

sentencenp

vp npv

John

mary Marylikes

likes(john,mary)likes(X,mary)john likes(X,Y)

Sample Grammar

%^ Exercises

1 through

3

sbar^ -->

np,^ s. sbar^ -->

s. s^ -->^

vp. s^ -->^

np,^ vp. np^ -->

[john]. np^ -->

[pete]. np^ -->

[mary]. np^ -->

det,^

n. np^ -->

[who].

-^ np^

-->^ neg,

np.

-^ np^

-->^ np,

conj,

np.

-^ n^ -->

[student].

-^ n^ -->

[baseball,fan].

-^ neg

-->^ [not].

-^ conj

-->^ [and].

-^ vp^

-->^ v,

np.

-^ v^ -->

[is].

-^ det

-->^ [a].

Exercise 4

-^ Step 1: Get some phrase structure output first•^ Step 2: Note:–^ rule ordering is important here...–^ how to ensure the right rule gets applied for sentences vs. questions?^ –^ sbar --> s.–^ sbar --> np, s.^ | ?- sbar(PS,[who,is,not,a,baseball,fan],[]).PS = sbar(np(who),s(vp(v(is),np(neg(not),np(det(a),n(baseball_fan)))))) ?| ?- sbar(PS,[john,is,a,baseball,fan],[]).PS = sbar(s(np(john),vp(v(is),np(det(a),n(baseball_fan))))) ?| ?- sbar(PS,[who,is,a,student,and,a,baseball,fan],[]).PS = sbar(np(who),s(vp(v(is),np(np(det(a),n(student)),conj(and),np(det(a),n(baseball_fan)))))) ?| ?- sbar(PS,[who,is,a,student,and,not,a,baseball,fan],[]).PS = sbar(np(who),s(vp(v(is),np(np(det(a),n(student)),conj(and),np(neg(not),np(det(a),n(baseball_fan)))))))?

Exercise 5

-^ Step 1: Generate some meaning output.•^ Step 2: Notice, for example, that for the conjunction cases youneed the same variable for both predicate nominals–^ i.e.

saturate1/

must be modified to deal with logical connectives like

,

(conjunction) and

+^ (negation) | ?- sbar(M,[who,is,not,a,baseball,fan],[]).M = +baseball_fan(_A) ?| ?- sbar(M,[john,is,a,baseball,fan],[]).M = baseball_fan(john) ?| ?- sbar(M,[who,is,a,student,and,a,baseball,fan],[]).M = student(_A),baseball_fan(_A) ?| ?- sbar(M,[who,is,a,student,and,not,a,baseball,fan],[]).M = student(_A),+baseball_fan(_A)?