Mercurial > lasercutter
view src/clojure/contrib/datalog.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 ;; Copyright (c) Jeffrey Straszheim. All rights reserved. The use and2 ;; distribution terms for this software are covered by the Eclipse Public3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can4 ;; be found in the file epl-v10.html at the root of this distribution. By5 ;; using this software in any fashion, you are agreeing to be bound by the6 ;; terms of this license. You must not remove this notice, or any other,7 ;; from this software.8 ;;9 ;; datalog.clj10 ;;11 ;; A Clojure implementation of Datalog12 ;;13 ;; straszheimjeffrey (gmail)14 ;; Created 2 March 200917 ;;; Please see the example.clj file in the datalog folder20 (ns21 ^{:author "Jeffrey Straszheim",22 :doc "A Clojure implementation of Datalog"}23 clojure.contrib.datalog24 (:use clojure.contrib.datalog.rules25 clojure.contrib.datalog.softstrat26 clojure.contrib.datalog.database)27 (:use [clojure.set :only (intersection)]28 [clojure.contrib.except :only (throwf)]))30 (defstruct work-plan31 :work-plan ; The underlying structure32 :rules ; The original rules33 :query ; The original query34 :work-plan-type) ; The type of plan36 (defn- validate-work-plan37 "Ensure any top level semantics are not violated"38 [work-plan database]39 (let [common-relations (-> work-plan :rules (intersection (-> database keys set)))]40 (when (-> common-relations41 empty?42 not)43 (throwf "The rules and database define the same relation(s): %s" common-relations))))44 ; More will follow46 (defn build-work-plan47 "Given a list of rules and a query, build a work plan that can be48 used to execute the query."49 [rules query]50 (struct-map work-plan51 :work-plan (build-soft-strat-work-plan rules query)52 :rules rules53 :query query54 :work-plan-type ::soft-stratified))56 (defn run-work-plan57 "Given a work plan, a database, and some query bindings, run the58 work plan and return the results."59 [work-plan database query-bindings]60 (validate-work-plan work-plan database)61 (evaluate-soft-work-set (:work-plan work-plan) database query-bindings))64 ;; End of file