Created
August 30, 2013 06:27
-
-
Save jackrusher/6386833 to your computer and use it in GitHub Desktop.
Transitive properties in a toy triple store using Clojure's core.logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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