Commit 0c150892 authored by Hans-Ulrich Krieger (HUK)'s avatar Hans-Ulrich Krieger (HUK)
Browse files

new TupleStore, RuleStore and ForwardChainer files (subjectPosition,...

new TupleStore, RuleStore and ForwardChainer files (subjectPosition, predicatePosition, objectPosition instance fields; new constructors) & extended polarity+transaction time axiomatic tuples and entailment rule files
parent ac9f2d02
......@@ -293,6 +293,40 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* more options that will also affect namespace, tuple store, and rule store
* @throws IOException
* @throws WrongFormatException
* @throws FileNotFoundException
*/
public ForwardChainer(int noOfCores,
boolean verbose,
boolean rdfCheck,
boolean eqReduction,
int minNoOfArgs,
int maxNoOfArgs,
int subjectPosition,
int predicatePosition,
int objectPosition,
int noOfAtoms,
int noOfTuples,
String tupleFile,
String ruleFile,
String namespaceFile)
throws FileNotFoundException, WrongFormatException, IOException {
this(noOfCores, verbose);
this.noOfAtoms = noOfAtoms;
this.noOfTuples = noOfTuples;
Namespace namespace = new Namespace(namespaceFile, verbose);
this.tupleStore = new TupleStore(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs,
subjectPosition, predicatePosition, objectPosition,
this.noOfAtoms, this.noOfTuples, namespace, tupleFile);
this.ruleStore = new RuleStore(verbose, rdfCheck, minNoOfArgs, maxNoOfArgs,
this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* slightly less options as before, but namespace, tuple store, and rule store have already
* been created
......
......@@ -1391,7 +1391,7 @@ public final class RuleStore {
// check whether ituple is part of antecedent or consequent section
if (parseLhs) {
// generate a test and add it to list of tests
generateTest(tuple, ituple[TupleStore.PREDICATE_POSITION], tests, rule.name);
generateTest(tuple, ituple[this.tupleStore.predicatePosition], tests, rule.name);
if (this.verbose)
System.out.println(" " + rule.name + ": equivalence reduction enforces new LHS test");
}
......@@ -1399,12 +1399,12 @@ public final class RuleStore {
// generate a binder var and an action;
// then add triple (?var eqrel ?var) to the consequent of the rule
String varname = generateNewVariableName();
generateAction(varname, tuple, ituple[TupleStore.PREDICATE_POSITION], actions, rule.name);
generateAction(varname, tuple, ituple[this.tupleStore.predicatePosition], actions, rule.name);
if (this.verbose)
System.out.println(" " + rule.name + ": equivalence reduction enforces new RHS action");
final ArrayList<String> eqTriple = new ArrayList<String>();
eqTriple.add(varname);
eqTriple.add(this.tupleStore.idToObject.get(ituple[TupleStore.PREDICATE_POSITION]));
eqTriple.add(this.tupleStore.idToObject.get(ituple[this.tupleStore.predicatePosition]));
eqTriple.add(varname);
tlist.add(makeTuple(eqTriple));
}
......@@ -1473,9 +1473,9 @@ public final class RuleStore {
}
// make subject and object of original tuple arguments of the test;
// equivalence relation patterns are _always_ triples
sb.append(tuple.get(TupleStore.SUBJECT_POSITION));
sb.append(tuple.get(this.tupleStore.subjectPosition));
sb.append(" ");
sb.append(tuple.get(TupleStore.OBJECT_POSITION));
sb.append(tuple.get(this.tupleStore.objectPosition));
tests.add(sb.toString());
}
......@@ -1498,9 +1498,9 @@ public final class RuleStore {
System.exit(1);
break;
}
sb.append(tuple.get(TupleStore.SUBJECT_POSITION));
sb.append(tuple.get(this.tupleStore.subjectPosition));
sb.append(" ");
sb.append(tuple.get(TupleStore.OBJECT_POSITION));
sb.append(tuple.get(this.tupleStore.objectPosition));
actions.add(sb.toString());
}
......
......@@ -116,11 +116,12 @@ public final class TupleStore {
* in case we would move the predicate to the front, predicatePosition must be
* set to 0, subject to 1, and object to 2, even if we would allow for tuples
* of length > 3 (interpret this as "the object, given as a Cartesian product,
* starts at position 2)
* starts at position 2);
* other settings would include polarity information, transaction and valid time
*/
public static final int SUBJECT_POSITION = 0;
public static final int PREDICATE_POSITION = 1;
public static final int OBJECT_POSITION = 2;
public int subjectPosition = 0;
public int predicatePosition = 1;
public int objectPosition = 2;
/**
* this setting is used for input encoding in TupleStore
......@@ -275,13 +276,16 @@ public final class TupleStore {
/**
* init form that "outsources" initialization code that needs to be duplicated by the
* binary (that is used be several other constructors) and 8-ary constructor
* binary (that is used be several other constructors) and 10-ary constructor
*/
private void init(boolean verbose,
boolean rdfCheck,
boolean eqReduction,
int minNoOfArgs,
int maxNoOfArgs,
int subjectPosition,
int predicatePosition,
int objectPosition,
int noOfAtoms,
int noOfTuples) {
this.verbose = verbose;
......@@ -289,6 +293,9 @@ public final class TupleStore {
this.equivalenceClassReduction = eqReduction;
this.minNoOfArgs = minNoOfArgs;
this.maxNoOfArgs = maxNoOfArgs;
this.subjectPosition = subjectPosition;
this.predicatePosition = predicatePosition;
this.objectPosition = objectPosition;
this.objectToId = new HashMap<String, Integer>(noOfAtoms);
this.idToObject = new ArrayList<String>(noOfAtoms);
this.idToJavaObject = new ArrayList<AnyType>(noOfAtoms);
......@@ -376,7 +383,9 @@ public final class TupleStore {
*/
public TupleStore(int noOfAtoms, int noOfTuples) {
init(this.verbose, this.rdfCheck, this.equivalenceClassReduction,
this.minNoOfArgs, this.maxNoOfArgs, noOfAtoms, noOfTuples);
this.minNoOfArgs, this.maxNoOfArgs,
this.subjectPosition, this.predicatePosition, this.objectPosition,
noOfAtoms, noOfTuples);
this.namespace = new Namespace();
}
......@@ -414,7 +423,28 @@ public final class TupleStore {
int noOfAtoms, int noOfTuples,
Namespace namespace, String tupleFile)
throws FileNotFoundException, IOException, WrongFormatException {
init(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs, noOfAtoms, noOfTuples);
init(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs,
this.subjectPosition, this.predicatePosition, this.objectPosition,
noOfAtoms, noOfTuples);
this.namespace = namespace;
readTuples(tupleFile);
}
/**
* more options to fully parameterize the tuple store
* @throws IOException
* @throws FileNotFoundException
* @throws WrongFormatException
*/
public TupleStore(boolean verbose, boolean rdfCheck, boolean eqReduction,
int minNoOfArgs, int maxNoOfArgs,
int subjectPosition, int predicatePosition, int objectPosition,
int noOfAtoms, int noOfTuples,
Namespace namespace, String tupleFile)
throws FileNotFoundException, IOException, WrongFormatException {
init(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs,
subjectPosition, predicatePosition, objectPosition,
noOfAtoms, noOfTuples);
this.namespace = namespace;
readTuples(tupleFile);
}
......@@ -519,7 +549,7 @@ public final class TupleStore {
*/
protected boolean isEquivalenceRelation(int[] tuple) {
// perhaps use an int set plus an element test here if more relations are involved
final int pred = tuple[TupleStore.PREDICATE_POSITION];
final int pred = tuple[this.predicatePosition];
return ((pred == Namespace.OWL_SAMEAS_ID) ||
(pred == Namespace.OWL_EQUIVALENTCLASS_ID) ||
(pred == Namespace.OWL_EQUIVALENTPROPERTY_ID));
......@@ -556,17 +586,17 @@ public final class TupleStore {
// if (isEquivalenceRelation(tuple))
// toBeRemoved.add(tuple);
// OR better: use the index (less triples to iterate over)
toBeRemoved.addAll(getTuples(TupleStore.PREDICATE_POSITION, Namespace.OWL_SAMEAS_ID));
toBeRemoved.addAll(getTuples(TupleStore.PREDICATE_POSITION, Namespace.OWL_EQUIVALENTCLASS_ID));
toBeRemoved.addAll(getTuples(TupleStore.PREDICATE_POSITION, Namespace.OWL_EQUIVALENTPROPERTY_ID));
toBeRemoved.addAll(getTuples(this.predicatePosition, Namespace.OWL_SAMEAS_ID));
toBeRemoved.addAll(getTuples(this.predicatePosition, Namespace.OWL_EQUIVALENTCLASS_ID));
toBeRemoved.addAll(getTuples(this.predicatePosition, Namespace.OWL_EQUIVALENTPROPERTY_ID));
// remove ER tuples from store (set & index) and update uriToProxy and proxyToUris,
// but also record the equivalence relation in which subject and object are related to
for (int[] tuple : toBeRemoved) {
removeTuple(tuple);
addEquivalentElements(tuple[TupleStore.SUBJECT_POSITION], tuple[TupleStore.OBJECT_POSITION]);
addEquivalentElements(tuple[this.subjectPosition], tuple[this.objectPosition]);
// do we need both entries here since subject position is used as THE proxy
this.uriToEquivalenceRelation.put(tuple[TupleStore.SUBJECT_POSITION], tuple[TupleStore.PREDICATE_POSITION]);
this.uriToEquivalenceRelation.put(tuple[TupleStore.OBJECT_POSITION], tuple[TupleStore.PREDICATE_POSITION]);
this.uriToEquivalenceRelation.put(tuple[this.subjectPosition], tuple[this.predicatePosition]);
this.uriToEquivalenceRelation.put(tuple[this.objectPosition], tuple[this.predicatePosition]);
}
// iterate over remaining tuples and replace uris by their proxies, if necessary;
// do NOT modify tuples in set & index, but instead delete old and add new cleaned-up tuples;
......
......@@ -82,7 +82,7 @@
<xsd:double> <rdf:type> <rdfs:Datatype> .
<xsd:duration> <rdf:type> <rdfs:Datatype> .
<xsd:float> <rdf:type> <rdfs:Datatype> .
<xsd:gDayr> <rdf:type> <rdfs:Datatype> .
<xsd:gDay> <rdf:type> <rdfs:Datatype> .
<xsd:gMonth> <rdf:type> <rdfs:Datatype> .
<xsd:gMonthDay> <rdf:type> <rdfs:Datatype> .
<xsd:gYear> <rdf:type> <rdfs:Datatype> .
......
......@@ -28,15 +28,14 @@
# <owl:equivalentProperty> <rdf:type> <rdf:Property> .
# <owl:sameAs> <rdf:type> <rdf:Property> .
#
# NOTE: this is the polarity and transaction time extension of file
# NOTE: this is the _polarity_ and _transaction time_ extension of file
# default.eqred.nt
# in that we prefix triples from this file by polarity
# <logic:true>
# and add suffix
# "0"^^<xsd:long>
# as the universally-holding transaction time 0 (from the very beginning)
# as the universally-holding transaction time 0 ("from the very beginning")
#
# !!!!!!!!!!!!!!!!!!!!!!!!!! VERSION NOT FINISHED YET !!!!!!!!!!!!!!!!!!!!!!!!!!
#
# @author Hans-Ulrich Krieger
# @version Wed Mar 16 09:47:37 CET 2016
......@@ -82,7 +81,7 @@
<logic:true> <owl:Thing> <owl:disjointWith> <owl:Nothing> "0"^^<xsd:long> .
# (some of the) standard XSD datatypes
# note: HFC has further custom XSD datatype of its own
# note: HFC has further _custom_ XSD datatype of its own
<logic:true> <xsd:anySimpleType> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:anyURI> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:boolean> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
......@@ -91,7 +90,7 @@
<logic:true> <xsd:double> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:duration> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:float> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:gDayr> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:gDay> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:gMonth> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:gMonthDay> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
<logic:true> <xsd:gYear> <rdf:type> <rdfs:Datatype> "0"^^<xsd:long> .
......
......@@ -17,37 +17,43 @@
# NOTE: this rule file should only be used if equivalence class reduction in HFC
# is _switched on_
#
# NOTE: this is the _polarity_ and _transaction time_ extension of file
# default.eqred.rdl
# in that we prefix clause triples with a polarity value and add transaction
# time as a suffix, always resulting in quintuples
#
# NOTE: for convenience, information from the TBox & RBox are also represented as
# quintuples, given triple
# subject predicate object
# as follows:
# logic:true subject predicate object "0"^^<xsd:long>
# read as "an always true statement from the begin of time";
# make sure that you load the corresponding axiomatic quintuple file
# default.polarity.transtime.long.quintuple.eqred.nt
#
# NOTE: we assume that the polarity value is the first element of the quintuple
# (position 0), thus the following constants need to be set to the right
# value, viz.
# TupleStore.SUBJECT_POSITION = 1
# TupleStore.PREDICATE_POSITION = 2
# TupleStore.OBJECT_POSITION = 3
# value in class TupleStore (e.g., via a constructor), viz.
# subjectPosition = 1
# predicatePosition = 2
# objectPosition = 3
#
# NOTE: the following rules do _not_ have a non-temporal counterpart
# + $owl_FunctPropDatatype
# + $inval_FunctProp
# + $log_incons
# +
# +
# NOTE: the following general rules do _not_ have a non-temporal counterpart
# + $owl_functional_datatype_property
# + $invalidate_functional_property
# + $logical_inconsistency
# + $disjoint_with_type_type
# + $same_as_different_from
#
#
# @author Hans-Ulrich Krieger
# @version Thu Mar 17 17:44:51 CET 2016
# @author Hans-Ulrich Krieger
# @version Mon Apr 4 13:26:07 CEST 2016
#
# NOTE: $rdf1_rdfs4a_4b (= rdf1 & rdfs4a & rdfs4b) modified;
# not interested that ?s, ?p, and ?o are all of rdf:type rdfs:Resource;
# only add that ?p is of rdf:type rdf:Property;
# not interested that ?s, ?p, and ?o are all of type rdfs:Resource;
# only add that ?p is of type rdf:Property;
# this rule even applies to TBox/RBox information
$rdf1_rdfs4a_4b
?_pol ?_s ?p ?_o ?_time
......@@ -70,7 +76,7 @@ $rdfs2
# added second clause -- do not want to time-tag XSD type values
# comments from $rdfs2+time also aplly here
# comments from $rdfs2+time also apply here
$rdfs3
?pol ?_s ?p ?o ?time
<logic:true> ?p <rdf:type> <owl:ObjectProperty> "0"^^<xsd:long>
......@@ -109,9 +115,8 @@ $rdfs7
?p != ?q
# replaced rdfs:Class by owl:Class;
# or we add a further axiom that owl:Class is a subclass of rdfs:Class as it is
# enforced for OWL Lite and OWL DL
# replaced rdfs:Class by owl:Class (or we add a further axiom that owl:Class is a
# subclass of rdfs:Class);
# NOTE: this rule only implements rdfs10 (not that ?c is a subclass of rdfs:Resource)
$rdfs8_10
<logic:true> ?c <rdf:type> <owl:Class> "0"^^<xsd:long>
......@@ -144,29 +149,29 @@ $rdfs11
?d != ?e
# NOTE: $rdfs12 omitted -- deals with rdfs:member
# NOTE: $rdfs12 omitted -- deals with rdfs:member;
# will not fire for our OWL ontologies
# NOTE: $rdfs13 omitted -- deals with rdfs:Literal
# NOTE: $rdfs13 omitted -- deals with rdfs:Literal;
# will not fire for our OWL ontologies
# time and polarity is taken over from the antecedent
$owl_invOf
$owl_inverse_of
?pol ?s ?p ?o ?time
<logic:true> ?p <owl:inverseOf> ?q "0"^^<xsd:long>
->
?pol ?o ?q ?s ?time
$owl_invOfBySymProp
$owl_symmetric_property_to_inverse_of
<logic:true> ?p <rdf:type> <owl:SymmetricProperty> "0"^^<xsd:long>
->
<logic:true> ?p <owl:inverseOf> ?p "0"^^<xsd:long>
$owl_SymPropByInverse
$owl_inverse_of_to_symmetric_property
<logic:true> ?p <owl:inverseOf> ?p "0"^^<xsd:long>
->
<logic:true> ?p <rdf:type> <owl:SymmetricProperty> "0"^^<xsd:long>
......@@ -175,7 +180,7 @@ $owl_SymPropByInverse
# original rule name is: rdfp3;
# rule was _not_ part of the OWLIM definition; why?
# time and polarity is taken over from the antecedent
$owl_SymmetricProperty
$owl_symmetric_property
<logic:true> ?p <rdf:type> <owl:SymmetricProperty> "0"^^<xsd:long>
?pol ?s ?p ?o ?time
->
......@@ -185,11 +190,11 @@ $owl_SymmetricProperty
# this rule is totally different from the version implemented for valid time;
# the test
# ValidInBetween subj pred obj time1 time2
# returns FunctionalOperator.TRUE iff there is _no_ quintuple
# returns FunctionalOperator.TRUE (= true) iff there is _no_ quintuple
# <logic:false> subj pred obj time
# such that min(time1, time2) <= time <= max(time1, time2);
# FunctionalOperator.FALSE, otherwise
$owl_TransProp
# return FunctionalOperator.FALSE, otherwise
$owl_transitive_property
<logic:true> ?p <rdf:type> <owl:TransitiveProperty> "0"^^<xsd:long>
<logic:true> ?x ?p ?y ?time1
<logic:true> ?y ?p ?z ?time2
......@@ -206,7 +211,7 @@ ValidInBetween ?y ?p ?z ?time1 ?time2
# from a single observation, we derive the identity of ?y and ?z from
# the very beginning (time = 0 in the consequent)
$owl_FunctPropObject
$owl_functional_object_property
<logic:true> ?p <rdf:type> <owl:FunctionalProperty> "0"^^<xsd:long>
<logic:true> ?p <rdf:type> <owl:ObjectProperty> "0"^^<xsd:long>
<logic:true> ?x ?p ?y ?time1
......@@ -220,11 +225,11 @@ ValidInBetween ?x ?p ?y ?time1 ?time2
ValidInBetween ?x ?p ?z ?time1 ?time2
# there is _no_ non-temporal version of this rule in the original rule
# set; note that this rule is a kind of _integrity_ constraint, deriving
# that seriously-wrong things had happened, viz., logical inconsistency;
# see description of test ValidInBetween above
$owl_FunctPropDatatype
# there is _no_ non-temporal version of this rule in the original rule set;
# note that this rule is a kind of _integrity_ constraint, deriving that
# seriously wrong things had happened, viz., logical inconsistency (see the
# description of test ValidInBetween above)
$owl_functional_datatype_property
<logic:true> ?p <rdf:type> <owl:FunctionalProperty> "0"^^<xsd:long>
<logic:true> ?p <rdf:type> <owl:DatatypeProperty> "0"^^<xsd:long>
<logic:true> ?x ?p ?y ?time1
......@@ -240,33 +245,55 @@ ValidInBetween ?x ?p ?z ?time1 ?time2
# there is _no_ non-temporal version of this rule in the original rule;
# if a functional property p in p(x,y)@t1 is "overwritten" by p(x,z)@t2
# (t1 < t2), we can invalidate p(x,y)@t2
# in fact, this is not a rule at all as $inval_FunctProp would badly
# interact with $owlFunctPropObject and $owlFunctPropDatatype above;
# the reason for this is that we cannot distinguish between tuples that
# are "added" (further information) and those which "overwrite" information
$inval_FunctProp
#<logic:true> ?p <rdf:type> <owl:FunctionalProperty> "0"^^<xsd:long>
#<logic:true> ?x ?p ?y ?time1
#<logic:true> ?x ?p ?z ?time2
#->
#<logic:false> ?x ?p ?y ?time2
#@test
#?y != ?z
#LLess ?time1 ?time2
#ValidInBetween ?x ?p ?y ?time1 ?time2
# if a functional property p for p(x,y)@t1 is "overwritten" by p(x,z)@t2
# (t1 < t2), we can invalidate p(x,y)@t2 by marking it as _false_
$invalidate_functional_property
<logic:true> ?p <rdf:type> <owl:FunctionalProperty> "0"^^<xsd:long>
<logic:true> ?x ?p ?y ?time1
<logic:true> ?x ?p ?z ?time2
->
<logic:false> ?x ?p ?y ?time2
@test
?y != ?z
LLess ?time1 ?time2
ValidInBetween ?x ?p ?y ?time1 ?time2
# there is _no_ non-temporal version of this rule in the original rule;
#
$log_incons
# there is _no_ non-temporal version of this rule in the original rule set
$logical_inconsistency
<logic:true> ?x ?p ?y ?time
<logic:false> ?x ?p ?y ?time
->
<logic:error> ?x ?p ?y ?time
# polarity/transaction time extension of an integrity constraint for OWL
$disjoint_with_type_type
<logic:true> ?s <owl:disjointWith> ?t "0"^^<xsd:long>
<logic:true> ?i <rdf:type> ?s ?time1
<logic:true> ?i <rdf:type> ?t ?time2
->
<logic:error> ?i <rdf:type> ?s ?time
<logic:error> ?i <rdf:type> ?t ?time
@test
ValidInBetween ?i <rdf:type> ?s ?time1 ?time2
ValidInBetween ?i <rdf:type> ?t ?time1 ?time2
@action
?time = LMax2 ?time1 ?time2
# polarity/transaction time extension of an integrity constraint for OWL;
# commonsense assumption: individuals do not fall apart (sameAs), nor do they
# become the same, after being different (differentFrom) -> transaction time = 0
$same_as_different_from
<logic:true> ?s <owl:sameAs> ?o "0"^^<xsd:long>
<logic:true> ?s <owl:differentFrom> ?o "0"^^<xsd:long>
->
<logic:error> ?s <owl:sameAs> ?o "0"^^<xsd:long>
<logic:error> ?s <owl:differentFrom> ?o "0"^^<xsd:long>
# holds for both datatype and object properties;
# rule was originally called rdfp2
$owl_InvFunctProp
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment