Pure is a query rewriter: given a set of rules R and a conjunctive query q, it rewrites q using the rules in R such that, for any data set D, the answers to q over the knowledge base (R,D) can be computed by evaluating the rewritten query directly over D.
Pure comes in two versions.
- The basic version (Pure) rewrites q into a union of conjunctive queries (UCQ) of minimal cardinality (number of conjunctive queries in the UCQ).
- The compilation-based version (PureC) exploits compilable rules to produce a so-called pivotal UCQ, which is much smaller than the classical UCQ rewriting. Compilable rules are of the form
atom2 :- atom1
where no constant occurs and atom2 does not contain any existential variable. Such rules are at the core of any ontology. A special kind of compilable rules are hierarchical rules in which atom1 and atom2 have exactly the same list of variables and all variables are distinct.
A pivotal UCQ computed by Pure
C can be evaluated in different ways.
- It can be directly evaluated over in-memory data using a special homomorphism (that embbeds the result of the rule compilation) or over a database semi-saturated by the compilable rules.
- Together with compilable rules, it forms a Datalog query that can be evaluated over data by a Datalog engine.
- It can be unfolded into a classical UCQ rewriting.
Even when a classical UCQ is wanted, using first PureC then unfolding the obtained pivotal UCQ is faster than using the basic version of Pure.
Associated publications
See SWJ 2015 for Pure (basic query rewriting), IJCAI 2015 and RuleML 2015 for PureC (compilation-based query rewriting).
Getting started
The following program (Pure-rewriter) includes both the basic and the compilation-based versions of Pure.
There are three options for compilation:
- NONE: no compilation
- H: compilation of hierarchical rules (specific compilable rules)
- ID: compilation of all compilable rules
Rewrite with compilation
Rewriting a query is decomposed into two steps.
- Compiled rules are transformed into a set of compiled rules (file.idc). This step needs to be performed only once independently from any query.
- Rewriting a query embbeds file.idc to compute a pivotal UCQ.
- Finally, the pivotal UCQ can be unfolded into a classical UCQ rewriting if needed.
-
Compile the ontology into ./example.idc:
java -jar pure-rewriter-*.jar compile ./example.dlp -f ./example.idc
-
Rewrite the query using the compiled ontology file:
java -jar pure-rewriter-*.jar rewrite ./example.dlp -q "?(X):- criticalManager(X),woman(X)." -c ./example.idc > ./pivotal.dlp
- Unfold the pivotal query:
java -jar pure-rewriter-*.jar unfold -c ./example.idc -q ./pivotal.dlp
Without compilation
-
java -jar pure-rewriter-*.jar rewrite ./example.dlp -q "?(X):- criticalManager(X),woman(X)." -c NONE
Other useful options
-
Verbose mode: print informations like runtime, number of rewritings, etc.
java -jar pure-rewriter-*.jar -v compile ./example.dlp -f ./example.idc
-
Rewrite+compile+unfold in a single line:
java -jar pure-rewriter-*.jar rewrite ./example.dlp -q "?(X):- criticalManager(X),woman(X)." -u
-
Rewrite multiple queries from a file
java -jar pure-rewriter-*.jar rewrite ./example.dlp -q ./queries.dlp
-
More options:
java -jar pure-rewriter-*.jar --help