dyna icon indicating copy to clipboard operation
dyna copied to clipboard

better sort order for query results

Open jeisner opened this issue 11 years ago • 5 comments

Right now results are sorted by an item's print name, giving the out-of-order results below. It would be nice to sort instead by a recursive comparison function on terms that understands how to compare numbers (and which compares on functor before arguments even if that functor is written as infix).

> query brown(0,Position)
   "It" =* brown(0,0)
   "was" =* brown(0,1)
   "Barco" =* brown(0,10)
   "!" =* brown(0,11)
   "!" =* brown(0,12)
   "among" =* brown(0,2)
   "these" =* brown(0,3)
   "that" =* brown(0,4)
   "Hinkle" =* brown(0,5)
   "identified" =* brown(0,6)
   "a" =* brown(0,7)
   "photograph" =* brown(0,8)
   "of" =* brown(0,9)

jeisner avatar Jul 02 '13 03:07 jeisner

Also, the results of vquery don't currently seem to be sorted at all. I think they should have the same sort order as query. Ideally trace should also present results in that order.

jeisner avatar Jul 02 '13 03:07 jeisner

That is exactly how solutions are printed -- recursive comparison, numbers, functors, infix, all that. Unfortunately this will require a bit of trickery, much like I did in trace.

Trace shows instantiations of rules which looks slightly different than the ones the user provided -- in particular with side conditions and whitespace. We can't get around this until we overhaul ANF to track more of what the user typed. Even then we'd still be adding parens to show intermediate results (there are of course alternative ways to display intermediate in #1).

Rather than employ the same tricks I used in trace, I figured I'd show the users something which is as similar as possible to their query.

You're right that vquery isn't sorted at all. They are now sorted by (value, bindings)... as quick fix so that tests will be stable.

It would be nice to have an option to sort query results on different keys (sort of like clicking a column in a streadsheet).

timvieira avatar Jul 02 '13 03:07 timvieira

Clicking columns indeed -- looking forward to the GUI version!

jeisner avatar Jul 02 '13 05:07 jeisner

Regarding section 3.9 of Darcey's tutorial, I wrote:

I see you found a convincing example for vquery, thanks. Contrary to what you say, the results of vquery aren't sorted at all -- that is issue #33. It would be nice if Dyna printed them in the same order as query. That would make it easier to understand what was going on in the tutorial, and also easier to switch to query or vquery after investing a minute in puzzling over the output of the other one.

Correction: As Tim says above, they are in fact sorted, but not the way they will eventually be. The above is a reason we'd want vquery and query to match.

jeisner avatar Jul 03 '13 19:07 jeisner

Could vquery list the variables in order of first appearance on the command line? So that vqueries like these would list the variables in the natural order A,B,C,D, which is easier to read. This also makes the output easier to line up with the output of query.

vquery swapadj(A,B), swapadj(B,C) for A != C
vquery swap(A,B), swap(B,C), swap(C,D) for A != C, B != D

jeisner avatar Jul 03 '13 21:07 jeisner