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:
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).
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 ?
Best How To :
You can use
findall followed by
sort to collect unique results of a query (you don't want duplicate invoices in your list), and
length to check the length of the collected results.
findall(X, (invoice(X, C, P, _), customer(C, _, f, _), cleanProd(P)), Xs),
Also, please note that variable start with uppercase, and atoms start with lower case (also applies for predicate names).
If you really want an atom starting with a upper case, you have to surround with single quotes.
For example, you could rewrite your KB in this way:
% this is not needed, however is useful as
% a documentation of what your predicate means:
% 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).