Extend the following grammar to handle simple semantics, i.e. to determine the price of a purchase:
sentence --> noun_phrase, verb_phrase.
noun_phrase --> proper_noun.
noun_phrase --> pronoun.
noun_phrase --> article, noun.
verb_phrase --> trans_verb, objective_noun_phrase.
article --> [a].
article --> [the].
trans_verb --> [buy].
trans_verb --> [buys].
% will limit ourselves to using these names
proper_noun --> [peter].
proper_noun --> [sarah].
proper_noun --> [john].
proper_noun --> [alice].
proper_noun --> [jenny].
proper_noun --> [james].
noun --> [buyer].
noun --> [buyers].
noun --> [customer].
noun --> [customers].
objective_noun_phrase --> nums, [of], object.
objective_noun_phrase --> nums, object.
object --> [apple].
object --> [apples].
object --> [peach].
object --> [peaches].
object --> [strawberry].
object --> [strawberries].
nums --> num.
nums --> num,doz.
nums --> [a],doz.
num --> [one].
num --> [two].
num --> [three].
num --> [four].
num --> [five].
num --> [six].
num --> [seven]
num --> [eight].
num --> [nine].
num --> [ten].
doz --> [halfdozen].
doz --> [dozen].
doz --> [halfdozens].
doz --> [dozens].
pronoun --> [he].
pronoun --> [we].
pronoun --> [you].
pronoun --> [they].
Make the following modifications:
?- sentence(TotalPrice, [john,buys,three,dozen,peaches], []). TotalPrice = 108?- sentence(TotalPrice, [john,buy,three,dozens,of,peaches], []). false?- sentence(TotalPrice, [we,buy,one,dozens,of,strawberry], []). false?- sentence(TotalPrice, [he,buys,one,dozen,strawberries], []). TotalPrice = 12?- sentence(TotalPrice, [a,customers,buy,one,dozen,of,strawberries], []). false
Resource created Saturday 06 February 2021, 09:11:00 PM.