diff options
author | Jeffrey Straszheim <straszheimjeffrey@gmail.com> | 2009-03-05 23:45:03 +0000 |
---|---|---|
committer | Jeffrey Straszheim <straszheimjeffrey@gmail.com> | 2009-03-05 23:45:03 +0000 |
commit | d6b2018ea742f89cd55f2b6ff30f5e6b839a3e74 (patch) | |
tree | 2dfefb845db20f459f6d05d30b4def2f742adcf3 /src/clojure/contrib | |
parent | f087e3a7f8b2f2ca48c07db2a47724ce7b98dce7 (diff) |
Progress on semi-naive
Diffstat (limited to 'src/clojure/contrib')
-rw-r--r-- | src/clojure/contrib/datalog/seminaive.clj | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/clojure/contrib/datalog/seminaive.clj b/src/clojure/contrib/datalog/seminaive.clj new file mode 100644 index 00000000..9c8d69e8 --- /dev/null +++ b/src/clojure/contrib/datalog/seminaive.clj @@ -0,0 +1,72 @@ +;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and +;; distribution terms for this software are covered by the Eclipse Public +;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can +;; be found in the file epl-v10.html at the root of this distribution. By +;; using this software in any fashion, you are agreeing to be bound by the +;; terms of this license. You must not remove this notice, or any other, +;; from this software. +;; +;; seminaive.clj +;; +;; A Clojure implementation of Datalog -- Semi Naive Evaluation +;; +;; straszheimjeffrey (gmail) +;; Created 5 March 2009 + + +(ns clojure.contrib.datalog.seminaive + (:use clojure.contrib.datalog.util + clojure.contrib.datalog.database + clojure.contrib.datalog.literals + clojure.contrib.datalog.rules + clojure.contrib.datalog.magic) + (:use [clojure.set :only (union intersection difference)]) + (:use [clojure.contrib.seq-utils :only (indexed)]) + (:require [clojure.contrib.graph :as graph])) + + +;;;; WORK IN PROGRESS !!! + + +;;; Delta Rules + +(defn- compute-delta-rules* + "Perform the delta computation of a rule, where i-rules is the set + of intensional predicates." + [r i-preds] + (let [head (:head r) + head-negated (negated-literal head) + delta-head (delta-literal head) + body (:body r) + new-rules (loop [lit (first body) + left [] + right (next body) + results []] + (if (nil? lit) + results + (let [new-results (if (i-preds lit) + (conj results + (assoc r :head delta-head + :body (concat left + [(delta-literal lit)] + right + [head-negated]))) + results)] + (recur (first right) + (conj left lit) + (next right) + new-results))))] + (if (empty? new-rules) + [(assoc r :head delta-head :body (conj (vec body) head-negated))] + new-rules))) + + +(defn- compute-delta-rules + "Compute the delta rules of a rules set, where i-rules is the set of + intensional predicates." + [rs i-preds] + (mapcat #(compute-delta-rules* % i-preds) rs)) + + + +;; End of file |