Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Prolog rules and query

16 views
Skip to first unread message

cdio...@gmail.com

unread,
Jun 15, 2015, 5:16:18 AM6/15/15
to
I need some help to find the rules and/or query for knowledgebase in Prolog with information about Costumers in a supermarket.

For example I have:

Customer(Name,Age,Sex,Wage).

customer(John,30,M,2000).
customer(Mary,35,F,2500).
customer(Mark,40,M,2500).

invoice(Number, CostumerName, Product, Price).

invoice(001, John, Potatoes, 20).
invoice(002, John, Tomatoes, 10).
invoice(003, Mary, Soap, 50).
invoice(004, Mark, Potatoes, 20).
invoice(005, Mary, Detergent, 15).

Food(Potatoes).
Food(Tomatoes).
CleanProd(Soap).
CleanProd(Detergent).


If I want to find a trend for example, to understand that Female bought more clean products than Male...which kind or what rule and query should I use ?

Jan Burse

unread,
Jun 15, 2015, 11:18:58 AM6/15/15
to
Hi,

cdio...@gmail.com schrieb:
> invoice(001, John, Potatoes, 20).
> invoice(002, John, Tomatoes, 10).
> invoice(003, Mary, Soap, 50).
> invoice(004, Mark, Potatoes, 20).
> invoice(005, Mary, Detergent, 15).

Please use:

invoice(001, 'John', 'Potatoes', 20).
invoice(002, 'John', 'Tomatoes', 10).
invoice(003, 'Mary', 'Soap', 50).
invoice(004, 'Mark', 'Potatoes', 20).
invoice(005, 'Mary', 'Detergent', 15).

If you use uppercase and no quotes, the Prolog system
thinks you are using a variable. You will get singleton
errors without correcting it.

> Food(Potatoes).
> Food(Tomatoes).
> CleanProd(Soap).
> CleanProd(Detergent).

Please use:

food('Potatoes').
food('Tomatoes').
clean_prod('Soap').
clean_prod('Detergent').

Same problem as above, you will get superflous token
errors without correcting it. Additionaly underscores are
recommended instead of camel case for predicate names,
but this is only a style issue.

See also:

Coding Guidelines for Prolog
Michael A. Covington et al.
http://arxiv.org/abs/0911.2899

Bye


0 new messages