sentence(Price) --> noun_phrase(Num), verb_phrase(Num,Price).
noun_phrase(sg) --> proper_noun.
noun_phrase(Num) --> pronoun(Num).
noun_phrase(Num) --> article(Num), noun(Num).
verb_phrase(Num,Price) --> trans_verb(Num), objective_noun_phrase(Price).
article(sg) --> [a].
article(_) --> [the].
trans_verb(pl) --> [buy].
trans_verb(sg) --> [buys].
% We will limit ourselves to using these names
proper_noun --> [peter].
proper_noun --> [sarah].
noun(sg) --> [buyer].
noun(pl) --> [buyers].
objective_noun_phrase(Price, Text, Rest):-
nums(Num, Number, Text, Text2),
object(Num,PiecePrice, Text2, Rest),
Price is Number * PiecePrice.
object(sg,1) --> [apple].
object(pl,1) --> [apples].
object(sg,3) --> [peach].
object(pl,3) --> [peaches].
nums(Num, Number) --> num(Num,Number).
num(sg,1) --> [one].
num(pl,2) --> [two].
num(pl,3) --> [three].
num(pl,4) --> [four].
num(pl,5) --> [five].
num(pl,6) --> [six].
num(pl,7) --> [seven].
num(pl,8) --> [eight].
num(pl,9) --> [nine].
num(pl,10) --> [ten].
pronoun(sg) --> [he].
pronoun(pl) --> [they].
Here is the output it would generate for the four queries above.
?- sentence(Price0,[john,buy,three,peaches], []). false
?- sentence(Price1,[he,buys,one,apples], X). false
?- sentence(Price2,[he,buys,five,apples], []). Price2 = 5
?- sentence(Price3,[he,buys,nine,peaches], X). Price2 = 5 Price3 = 27 X = []
Resource created 5 years ago, last modified 5 years ago.