A minimal implementation of Datalog.
A minimal implementation of Datalog.
(q query kb)
(q query kb rules)
Queries a knowledge base or a set of relations given a vector form of a query and an optional set of rules.
A query takes the form:
[:find find-spec :where clauses]
A find-spec can be any number of lvars like:
[:find ?e ?v :where ...]
or a tuple containing a mix of lvars and grounds which is used to build output tuples from the query results:
[:find [?e :an/attribute ?v] :where ...]
The :where clauses are any number of tuples containing a mix of lvars and grounds:
[:find ... :where [?e :an/attribute ?v] [?e :another/attr 42]]
:where clauses may also contain filters defined as calls to predicates used to constrain the values that may bind to lvars:
[:find ... :where [?e :an/attribute ?v] (= ?v 42)]
The possible filter predicates are: =, not=, <, >, <=, >=
rules are a vector of lists where each list defines a rule with a single head tuple followed by any number of rule clauses:
([?p :relationship/parent ?c] [?p :relationship/father ?c])
The rule above defines a syntheic relation called
:relationship/parent
defined in terms of another relation
relationship/father
. Rules describe synthetic relations derived
from real relations in the data or other synthetic relations
derived from previous rule applications.
Queries a knowledge base or a set of relations given a vector form of a query and an optional set of rules. A query takes the form: [:find find-spec :where clauses] A find-spec can be any number of lvars like: [:find ?e ?v :where ...] or a tuple containing a mix of lvars and grounds which is used to build output tuples from the query results: [:find [?e :an/attribute ?v] :where ...] The :where clauses are any number of tuples containing a mix of lvars and grounds: [:find ... :where [?e :an/attribute ?v] [?e :another/attr 42]] :where clauses may also contain filters defined as calls to predicates used to constrain the values that may bind to lvars: [:find ... :where [?e :an/attribute ?v] (= ?v 42)] The possible filter predicates are: =, not=, <, >, <=, >= rules are a vector of lists where each list defines a rule with a single head tuple followed by any number of rule clauses: ([?p :relationship/parent ?c] [?p :relationship/father ?c]) The rule above defines a syntheic relation called `:relationship/parent` defined in terms of another relation `relationship/father`. Rules describe synthetic relations derived from real relations in the data or other synthetic relations derived from previous rule applications.
(query->map query)
Accepts the vector form of a Datalog query and outputs a map of the component sections as keyword->seq mappings.
Accepts the vector form of a Datalog query and outputs a map of the component sections as keyword->seq mappings.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close