Some doubts about how work this DCG grammar for subset of natural language in Prolog -


i studying dcg grammar natural language processing using prolog , have doubts if have understand correctly or if missing something.

this dcg grammar:

sentence2(vp) --> noun_phrase2(actor),               verb_phrase2(actor, vp).  /* noun phrase proper name of person (that unified in name variable) */ noun_phrase2(name) --> propername(name).  /* verb_phrase can intransitive verb */ verb_phrase2(actor, vp) --> intrans_verb(actor, vp).  /* verb_phrase can transitive verb followed object complement verb_phrase2(somebody, vp) --> trans_verb(somebody, something, vp),                                noun_phrase2(something).  /* meaning of proper name john john    meaning of proper name mary mary */ propername(john) --> [john]. propername(mary) --> [mary].  intrans_verb(actor, paints(actor)) --> [paints].  trans_verb(somebody, something, likes(somebody, something)) --> [likes]. 

so grammar can accept phrase like: [john, paints] have meaning: paints(john)

i see if idea how reach meaning correct.

so think happen when execute following query:

?- sentence2(meaning, [john, paints], []). meaning = paints(john)  

[john paints] final sentence have evaluate , if belong language or not.

a sentence have formed in following way:

sentence2(vp) --> noun_phrase2(actor),                   verb_phrase2(actor, vp). 

(by noun phrase followed verb phrase.

a noun phrase composed in way:

noun_phrase2(name) --> propername(name). 

so noun phrase proper name

the meaning of proper name simple because line:

propername(john) --> [john]. 

i john proper name , adding parameter dcg grammar specify meaning. so: the semantic meaning of proper name john john

so, meaning of noun phrase same meaning of proper name (because variables name unify)

so in previous case meaning ot noun_phrase2 predicate john , first evalutation step of original sentence end.

now have evaluate second part verbal phrase predicate: verb_phrase2(actor, vp)

a verbal phrase be, in case, intransitive verb:

verb_phrase2(actor, vp) --> intrans_verb(actor, vp). 

an intransitive verb definied in way:

intrans_verb(actor, paints(actor)) --> [paints]. 

so word paints intransitive verb , it's meaning paints(actor) actor variable dependnds context (in case actor rappresent who action, paints)

so, backtrack verb_phrase2(actor, vp) verify verb_phrase2(actor, vp)

now actor still remain not yet unified variable , meaning vp = paints(actor)

so, verified paints intransitive verb , meaning paints(actor)

so execute backtrack original sentence2(vp) predicate have verified noun_phrase2(actor) predicate , in actor = john

so have situation:

sentence2(vp) --> noun_phrase2(john),                   verb_phrase2(john, paints(john)). 

so final vp unified paints(john)

is reasoning correct or missing something? way reasoning in prolog way?

please ask specific, short question. include relevant code without excessive comments.

here's how.


given dcg rules

sentence2(vp) --> noun_phrase2(actor),verb_phrase2(actor, vp). noun_phrase2(name) --> propername(name). verb_phrase2(actor, vp) --> intrans_verb(actor, vp). verb_phrase2(somebody, vp) --> trans_verb(somebody, something, vp),                                  noun_phrase2(something). propername(john) --> [john]. propername(mary) --> [mary]. intrans_verb(actor, paints(actor)) --> [paints]. trans_verb(somebody, something, likes(somebody, something)) --> [likes]. 

how following achieve result?

?- sentence2(meaning, [john, paints], []). meaning = paints(john)  

answer:

the above rules equivalent

sentence2(vp, l, z):- noun_phrase2(actor, l, l2),                        verb_phrase2(actor, vp, l2, z). noun_phrase2(name, l, z):- propername(name, l, z).     verb_phrase2(actor, vp, l, z):- intrans_verb(actor, vp, l, z).  verb_phrase2(somebody, vp, l, z):- trans_verb(somebody, something, vp, l, l2),                                    noun_phrase2(something, l2, z).     propername(john, l, z):-      l = [john | z].         %// 'john' present in input stream propername(mary, l, z):-      l = [mary | z].         %// 'mary' present in input stream /* alternative definition  propername(x) --> [x], { member(x, [john, mary]) }.    %% translated propername(x, l, z):- l = [x | z], member(x, [john, mary]).  */     intrans_verb(actor, paints(actor), l, z):-      l = [paints | z].       %// 'paints' present in input stream     trans_verb(somebody, something, likes(somebody, something), l, z):-     l = [likes | z].        %// 'likes' present in input stream 

in particular,

?- sentence2(meaning, [john, paints], []).      ?- noun_phrase2(actor, [john, paints], l2),                        verb_phrase2(actor, meaning, l2, []).    ?- noun_phrase2(actor, [john, paints], l2).   ?- propername(actor, [john, paints], l2).      ?- propername(john, [john, paints], l2).            { actor=john }   !- [john, paints] = [john | [paints]]               { l2=[paints] }    ?- verb_phrase2(john, meaning, [paints], []).   ?- intrans_verb(john, meaning, [paints], []).   ?- intrans_verb(john, paints(john), [paints], []).  { meaning=paints(john) }   !- [paints] = [paints | []]  !-  

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -