Massive rewrite.

* Introduced query class
* Querying now yields bindings instead of dicts
* Rule resolution now localizes Vars, so that the same var can be used
to define a rule as to run a query
I Partial, untested implementation of conditional rules.
All the things