Re: JESS: query distinct values of a slot

2007-08-06 Thread Joaquín Cañadas
Thank you for your answer, however, your solution is useful for sorting only the values of one slot. My problem is printing all the facts (with all the slot values) sorted by means of the values of one (or two) slots. For example, these facts: (deffacts data (person (firstName Fred)

Re: JESS: query distinct values of a slot

2007-08-06 Thread Ernest Friedman-Hill
On Aug 6, 2007, at 8:09 AM, Joaquín Cañadas wrote: Thank you for your answer, however, your solution is useful for sorting only the values of one slot. Collections.sort() can sort data however you'd like -- you just have to write a Comparator. - I can not access to the facts returned by

Re: JESS: query distinct values of a slot

2007-08-06 Thread Joaquín Cañadas
Ok ! I have done it. Thank you for your help. Joaquín Ernest Friedman-Hill escribió: On Aug 6, 2007, at 8:09 AM, Joaquín Cañadas wrote: Thank you for your answer, however, your solution is useful for sorting only the values of one slot. Collections.sort() can sort data however you'd

Re: JESS: query distinct values of a slot

2007-08-03 Thread Joaquín Cañadas
Thank you Bob for your quick and useful answer! It was simpler than I was trying (without success). I have another related question, I hope not to abuse ;). How can we modify the print function for printing names sorted alphabetically? In the Jess in Action book an example rule called

Re: JESS: query distinct values of a slot

2007-08-03 Thread Robert Kirby
As a Jess 7.0p1 query: (defquery unique-first-name A query for unique first names among person facts ?person - (person (firstName ?firstName)) (not (and ?earlier-person - (person (firstName ?firstName)) (test ( ?earlier-person ?person) (deffunction

Re: JESS: query distinct values of a slot

2007-08-03 Thread Wolfgang Laun
Two solutions. (A) You define a query: (defquery personQuery (person (firstName ?fn)(lastName ?ln)(age ?age))) The Jess function values-of runs the query and processes the result, collecting the values of the result component with the name given as the function argument name into the list

Re: JESS: query distinct values of a slot

2007-08-03 Thread Ernest Friedman-Hill
Instead of imnmediately printing the results below, add them to a java.util.List, and sort the list; then you can print them in order. So, for example (import java.util.*) (deffunction print-unique-first-names () print unique first names from person facts (bind ?results (run-query*

JESS: query distinct values of a slot

2007-08-02 Thread Joaquín Cañadas
Hello, I need some help with queries. How can I query the distinct values of a slot? The manual explains how to select facts with a concrete value in an slot. But my problem is different, for example, with these facts: *Jess *(deffacts data (person (firstName Fred) (lastName Smith)(age