Augmented Grammars and Semantics in Natural Language

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].
    

The Task

Make the following modifications:

  • Add parameters to the grammar rules so that singular and plural in nouns as well as the 's' in verbs is treated properly. Make sure that all sentences that are recognised by your modified grammar are grammatically correct, i.e. that 'buys' instead of 'buy' is only used where appropriate etc. Also make sure that 'of' is only used after 'dozens' or 'halfdozens' - not after numbers of dozens. But note, we will not be testing the grammatically correct "john buys dozens of peaches" because the price is indeterminate.
  • Allow for the calculation of total price of purchases that can be described by grammatical sentences. Assume that one peach costs 3 dollars, one apple 2 dollars and one strawberry 1 dollar.
  • The sentence predicate must be called with three arguments. For example:
  • ?- 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.


Back to top

COMP3411/COMP9814 21T1 (Artificial Intelligence) is powered by WebCMS3
CRICOS Provider No. 00098G