Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created August 30, 2013 06:27
Show Gist options
  • Save jackrusher/6386833 to your computer and use it in GitHub Desktop.
Save jackrusher/6386833 to your computer and use it in GitHub Desktop.
Transitive properties in a toy triple store using Clojure's core.logic.
(defrel triple ^{:index true} s ^{:index true} p ^{:index true} o)
(facts triple [[:Berlin :is-a :city]
[:city :is-a :permanent-settlement]
[:Berlin :part-of :Germany]
[:Germany :part-of :EU]
[:EU :part-of :Eurasia]
[:Eurasia :part-of :Earth]])
(run* [q] (triple q :is-a :city))
;; => (:Berlin)
(defne transitivo [x p y]
([x p y] (triple y p x))
([x p y] (fresh [z]
(triple z p x)
(transitivo z p y))))
(run* [q] (transitivo q :is-a :Berlin))
;; => (:city :permanent-settlement)
(run* [q] (transitivo q :part-of :Berlin))
;; => (:Germany :Eurasia :EU :Earth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment