threatgrid / asami

A graph store for Clojure and ClojureScript
Eclipse Public License 1.0
637 stars 29 forks source link

Update planner to push transitive attributes back #77

Open quoll opened 4 years ago

quoll commented 4 years ago

Using the #70 data, the transitive attribute gets pushed forward in the following query:

=> (d/q '[:find ?a ?name :where [?e :name "Falls Church"][?e2 :name ?name][?e ?a* ?e2]] (d/db conn))
([nil "Falls Church"]
 [:neighbor "Arlington"]
 [:neighbor "Solar System"]
 [:neighbor "Washington, DC"]
 [:neighbor "USA"]
 [:neighbor "Orion-Cygnus Arm"]
 [:neighbor "Earth"]
 [:neighbor "Milky Way Galaxy"])

This can (and probably should) be modified to return more than the first step in ?a, but it is also better to push this to the back of the query, where both ends of the constraint get bound:

=> (d/q '[:find ?a ?name :where [?e :name "Falls Church"][?e2 :name ?name][?e ?a* ?e2]] (d/db conn) :planner :user)
([[:neighbor :neighbor :is-in :is-in :is-in :is-in] "Orion-Cygnus Arm"]
 [[:neighbor :neighbor :is-in :is-in :is-in] "Solar System"]
 [[:neighbor :neighbor :is-in :is-in] "Earth"]
 [[:neighbor :neighbor] "Washington, DC"]
 [[:neighbor :neighbor :is-in] "USA"]
 [[:neighbor :neighbor :is-in :is-in :is-in :is-in :is-in] "Milky Way Galaxy"]
 [[:neighbor] "Arlington"])