API for datalog - clojure-contrib v1.3 (in development)

by Jeffrey Straszheim

Full namespace name: clojure.contrib.datalog

Overview

A Clojure implementation of Datalog

Related documentation:
An Overview of Datalog

Public Variables and Functions



build-work-plan

function
Usage: (build-work-plan rules query)
Given a list of rules and a query, build a work plan that can be
used to execute the query.
Source


run-work-plan

function
Usage: (run-work-plan work-plan database query-bindings)
Given a work plan, a database, and some query bindings, run the
work plan and return the results.
Source

datalog.database






add-index

function
Usage: (add-index db name key)
Adds an index to an empty relation named name
Source

add-relation

function
Usage: (add-relation db name keys)
Adds a relation to the database
Source

add-tuple

function
Usage: (add-tuple db rel-name tuple)
       (add-tuple rel tuple)
Two forms:

[db relation-name tuple] adds tuple to the named relation.  Returns
the new database.

[rel tuple] adds to the relation object.  Returns the new relation.
Source

add-tuples

function
Usage: (add-tuples db & tupls)
Adds a collection of tuples to the db, as
(add-tuples db
   [:rel-name :key-1 1 :key-2 2]
   [:rel-name :key-1 2 :key-2 3])
Source

any-match?

function
Usage: (any-match? db rn pt)
Finds if there are any matching records for the partial tuple
Source

database-counts

function
Usage: (database-counts db)
Returns a map with the count of elements in each relation.
Source

database-merge

function
Usage: (database-merge dbs)
Merges databases together
Source

database-merge-parallel

function
Usage: (database-merge-parallel dbs)
Merges databases together in parallel
Source

datalog-relation

function
Usage: (datalog-relation schema data indexes)
Creates a relation
Source

ensure-relation

function
Usage: (ensure-relation db name keys indexes)
If the database lacks the named relation, add it
Source

get-relation

function
Usage: (get-relation db rel-name)
Get a relation object by name
Source

make-database

macro
Usage: (make-database & commands)
Makes a database, like this
(make-database
  (relation :fred [:mary :sue])
  (index :fred :mary)
  (relation :sally [:jen :becky])
  (index :sally :jen)
  (index :sally :becky))
Source

merge-relations

function
Usage: (merge-relations r1 r2)
Merges two relations
Source

remove-tuple

function
Usage: (remove-tuple db rel-name tuple)
       (remove-tuple rel tuple)
Two forms:

[db relation-name tuple] removes the tuple from the named relation,
returns a new database.

[rel tuple] removes the tuple from the relation.  Returns the new
relation.
Source

replace-relation

function
Usage: (replace-relation db rel-name rel)
Add or replace a fully constructed relation object to the database.
Source

select

function
Usage: (select db rn pt)
finds all matching tuples to the partial tuple (pt) in the relation named (rn)
Source

datalog.literals






build-atom

function
Usage: (build-atom f type)
Returns an unevaluated expression (to be used in a macro) of an
atom.
Source

build-seed-bindings

function
Usage: (build-seed-bindings s)
Given a seed literal, already adorned and in magic form, convert
its bound constants to new variables.
Source

delta-literal

function
Usage: (delta-literal l)
Given a literal l, return a delta version
Source

get-adorned-bindings

function
Usage: (get-adorned-bindings pred)
Get the bindings from this adorned literal.
Source

get-base-predicate

function
Usage: (get-base-predicate pred)
Get the base predicate from this predicate.
Source

literal-magic?

function
Usage: (literal-magic? lit)
Is this literal magic?
Source

magic-literal

function
Usage: (magic-literal l)
Create a magic version of this adorned predicate.
Source

negated-literal

function
Usage: (negated-literal l)
Given a literal l, return a negated version
Source

negated?

function
Usage: (negated? l)
Is this literal a negated literal?
Source

positive?

function
Usage: (positive? l)
Is this a positive literal?
Source

project-literal

function
Usage: (project-literal db lit bs)
       (project-literal db lit bs var?)
Project a stream of bindings onto a literal/relation. Returns a new
db.
Source

datalog.magic






adorn-query

function
Usage: (adorn-query q)
Adorn a query
Source

adorn-rules-set

function
Usage: (adorn-rules-set rs q)
Adorns the given rules-set for the given query.  (rs) is a
rules-set, (q) is an adorned query.
Source

build-partial-tuple

function
Usage: (build-partial-tuple q bindings)
Given a query and a set of bindings, build a partial tuple needed
to extract the relation from the database.
Source

magic-transform

function
Usage: (magic-transform rs)
       (magic-transform rs i-preds)
Return a magic transformation of an adorned rules-set (rs).  The
(i-preds) are the predicates of the intension database.  These
default to the predicates within the rules-set.
Source

seed-predicate-for-insertion

function
Usage: (seed-predicate-for-insertion q)
Given a query, return the predicate to use for database insertion.
Source

seed-relation

function
Usage: (seed-relation q)
Given a magic form of a query, give back the literal form of its seed
relation
Source

seed-rule

function
Usage: (seed-rule q)
Given an adorned query, give back its seed rule
Source

datalog.rules






<-

macro
Usage: (<- hd & body)
Build a datalog rule.  Like this:

(<- (:head :x ?x :y ?y) (:body-1 :x ?x :y ?y) (:body-2 :z ?z) (not! :body-3 :x ?x) (if > ?y ?z))
Source

?-

macro
Usage: (?- & q)
Define a datalog query
Source

all-predicates

function
Usage: (all-predicates rs)
Given a rules-set, return all defined predicates
Source

apply-rule

function
Usage: (apply-rule db rule)
       (apply-rule db-1 db-2 rule)
Apply the rule against db-1, adding the results to the appropriate
relation in db-2.  The relation will be created if needed.
Source

compute-sip

function
Usage: (compute-sip bindings i-preds rule)
Given a set of bound column names, return an adorned sip for this
rule.  A set of intensional predicates should be provided to
determine what should be adorned.
Source

display-query

function
Usage: (display-query query)
Return a query in a readable format.
Source

display-rule

function
Usage: (display-rule rule)
Return the rule in a readable format.
Source

is-safe?

function
Usage: (is-safe? rule)
Is the rule safe according to the datalog protocol?
Source

make-rules-set

function
Usage: (make-rules-set rs)
Given an existing set of rules, make it a 'rules-set' for
printing.
Source

non-base-rules

function
Usage: (non-base-rules rs)
Return a collection of rules that depend, somehow, on other rules
Source

predicate-map

function
Usage: (predicate-map rs)
Given a rules-set, return a map of rules keyed by their predicates.
Each value will be a set of rules.
Source

return-rule-data

function
Usage: (return-rule-data rule)
Returns an untypted rule that will be fully printed
Source

rules-set

function
Usage: (rules-set & rules)
Given a collection of rules return a rules set
Source

datalog.softstrat






build-soft-strat-work-plan

function
Usage: (build-soft-strat-work-plan rs q)
Return a work plan for the given rules-set and query
Source

get-all-relations

function
Usage: (get-all-relations ws)
Return a set of all relation names defined in this workplan
Source

datalog.util






is-query-var?

function
Usage: (is-query-var? sym)
Is this a query variable: e.g. a symbol prefixed with ??
Source

is-var?

function
Usage: (is-var? sym)
Is this a logic variable: e.g. a symbol prefixed with a ?
Source

keys-to-vals

function
Usage: (keys-to-vals m ks)
Given a map and a collection of keys, return the collection of vals
Source

map-values

function
Usage: (map-values f hash)
Like map, but works over the values of a hash map
Source

preduce

function
Usage: (preduce f data)
Similar to merge-with, but the contents of each key are merged in
parallel using f.

f - a function of 2 arguments.
data - a collection of hashes.
Source

reverse-map

function
Usage: (reverse-map m)
Reverse the keys/values of a map
Source

trace-datalog

macro
Usage: (trace-datalog & body)
If *test-datalog* is set to true, run the enclosed commands
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.