diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-08-04 18:30:46 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-08-04 18:30:46 +0100 |
| commit | c3480bb733b8bca976718a3dc2f09a21cb4b1b45 (patch) | |
| tree | 648b2dacb4b162205d26856c4be4bb7389f99141 /src/uk/ac/ox/cs/pagoda | |
| parent | 0c39145b3b76b3db73db0a38d5324caa7ff3c434 (diff) | |
| download | ACQuA-c3480bb733b8bca976718a3dc2f09a21cb4b1b45.tar.gz ACQuA-c3480bb733b8bca976718a3dc2f09a21cb4b1b45.zip | |
Rules parsing.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda')
13 files changed, 151 insertions, 57 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/hermit/RuleHelper.java b/src/uk/ac/ox/cs/pagoda/hermit/RuleHelper.java index 81c99a4..43c5849 100644 --- a/src/uk/ac/ox/cs/pagoda/hermit/RuleHelper.java +++ b/src/uk/ac/ox/cs/pagoda/hermit/RuleHelper.java | |||
| @@ -2,9 +2,16 @@ package uk.ac.ox.cs.pagoda.hermit; | |||
| 2 | 2 | ||
| 3 | import org.semanticweb.HermiT.model.*; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 4 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 5 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.Namespace; | 6 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 6 | 7 | ||
| 8 | import java.security.InvalidParameterException; | ||
| 9 | import java.util.ArrayList; | ||
| 10 | |||
| 7 | public class RuleHelper { | 11 | public class RuleHelper { |
| 12 | private static final String OR = "|"; | ||
| 13 | private static final String IF = ":-"; | ||
| 14 | private static final String AND = ","; | ||
| 8 | 15 | ||
| 9 | // public static String abbreviateIRI(String text) { | 16 | // public static String abbreviateIRI(String text) { |
| 10 | // String prefixName, prefixIRI; | 17 | // String prefixName, prefixIRI; |
| @@ -37,16 +44,16 @@ public class RuleHelper { | |||
| 37 | boolean lastSpace = true; | 44 | boolean lastSpace = true; |
| 38 | for (Atom headAtom: clause.getHeadAtoms()) { | 45 | for (Atom headAtom: clause.getHeadAtoms()) { |
| 39 | if ((atomText = getText(headAtom)) == null) continue; | 46 | if ((atomText = getText(headAtom)) == null) continue; |
| 40 | if (!lastSpace) buf.append(" v "); | 47 | if (!lastSpace) buf.append(" ").append(OR).append(" "); |
| 41 | buf.append(atomText); | 48 | buf.append(atomText); |
| 42 | lastSpace = false; | 49 | lastSpace = false; |
| 43 | } | 50 | } |
| 44 | buf.append(" :- "); | 51 | buf.append(" ").append(IF).append(" "); |
| 45 | lastSpace = true; | 52 | lastSpace = true; |
| 46 | for (Atom bodyAtom: clause.getBodyAtoms()) { | 53 | for (Atom bodyAtom: clause.getBodyAtoms()) { |
| 47 | // for (String str: strs[1].split(", ")) { | 54 | // for (String str: strs[1].split(", ")) { |
| 48 | if ((atomText = getText(bodyAtom)) == null) continue; | 55 | if ((atomText = getText(bodyAtom)) == null) continue; |
| 49 | if (!lastSpace) buf.append(", "); | 56 | if (!lastSpace) buf.append(AND).append(" "); |
| 50 | buf.append(atomText); | 57 | buf.append(atomText); |
| 51 | lastSpace = false; | 58 | lastSpace = false; |
| 52 | } | 59 | } |
| @@ -74,7 +81,7 @@ public class RuleHelper { | |||
| 74 | else builder.append(getText(p)); | 81 | else builder.append(getText(p)); |
| 75 | builder.append("("); | 82 | builder.append("("); |
| 76 | builder.append(getText(atom.getArgument(0))); | 83 | builder.append(getText(atom.getArgument(0))); |
| 77 | builder.append(","); | 84 | builder.append(","); |
| 78 | builder.append(getText(atom.getArgument(1))); | 85 | builder.append(getText(atom.getArgument(1))); |
| 79 | builder.append(")"); | 86 | builder.append(")"); |
| 80 | } | 87 | } |
| @@ -95,4 +102,72 @@ public class RuleHelper { | |||
| 95 | return MyPrefixes.PAGOdAPrefixes.abbreviateIRI(t.toString()); | 102 | return MyPrefixes.PAGOdAPrefixes.abbreviateIRI(t.toString()); |
| 96 | } | 103 | } |
| 97 | 104 | ||
| 105 | public static Term parseTerm(String s) { | ||
| 106 | s = s.trim(); | ||
| 107 | if(s.startsWith("?")) return Variable.create(s.substring(1)); | ||
| 108 | return Individual.create(MyPrefixes.PAGOdAPrefixes.expandIRI(s)); | ||
| 109 | } | ||
| 110 | |||
| 111 | public static Atom parseAtom(String s) { | ||
| 112 | s = s.trim(); | ||
| 113 | |||
| 114 | String[] split = s.split("\\("); | ||
| 115 | String predicateIri = OWLHelper.removeAngles(MyPrefixes.PAGOdAPrefixes.expandText(split[0])); | ||
| 116 | String[] predicateArgs = split[1].substring(0, split[1].length() - 1).split(","); | ||
| 117 | int numOfargs = predicateArgs.length; | ||
| 118 | Term terms[] = new Term[predicateArgs.length]; | ||
| 119 | for (int i = 0; i < terms.length; i++) | ||
| 120 | terms[i] = parseTerm(predicateArgs[i]); | ||
| 121 | if(numOfargs == 1) { | ||
| 122 | AtomicConcept atomicConcept = AtomicConcept.create(predicateIri); | ||
| 123 | return Atom.create(atomicConcept, terms); | ||
| 124 | } | ||
| 125 | else if(numOfargs == 2) { | ||
| 126 | AtomicRole atomicRole = AtomicRole.create(predicateIri); | ||
| 127 | return Atom.create(atomicRole, terms); | ||
| 128 | } | ||
| 129 | else | ||
| 130 | throw new InvalidParameterException(); | ||
| 131 | // TODO? add equality (owl:sameAs)? | ||
| 132 | } | ||
| 133 | |||
| 134 | public static DLClause parseClause(String s) { | ||
| 135 | s = s.trim(); | ||
| 136 | if(s.endsWith(".")) s = s.substring(0, s.length()-1).trim(); | ||
| 137 | |||
| 138 | String[] headAndBody = s.split(IF); | ||
| 139 | String[] headAtomsStr = splitAtoms(headAndBody[0], OR); | ||
| 140 | String[] bodyAtomsStr = splitAtoms(headAndBody[1], AND); | ||
| 141 | |||
| 142 | Atom[] headAtoms = new Atom[headAtomsStr.length]; | ||
| 143 | Atom[] bodyAtoms = new Atom[bodyAtomsStr.length]; | ||
| 144 | for (int i = 0; i < headAtoms.length; i++) | ||
| 145 | headAtoms[i] = parseAtom(headAtomsStr[i]); | ||
| 146 | for (int i = 0; i < bodyAtoms.length; i++) | ||
| 147 | bodyAtoms[i] = parseAtom(bodyAtomsStr[i]); | ||
| 148 | |||
| 149 | return DLClause.create(headAtoms, bodyAtoms); | ||
| 150 | } | ||
| 151 | |||
| 152 | private static String[] splitAtoms(String s, String operator) { | ||
| 153 | char op = operator.charAt(0); | ||
| 154 | ArrayList<String> result = new ArrayList<>(); | ||
| 155 | |||
| 156 | int b = 0; | ||
| 157 | boolean betweenParenthesis = false; | ||
| 158 | for (int i = 0; i < s.length(); i++) { | ||
| 159 | if(s.charAt(i) == '(') | ||
| 160 | betweenParenthesis = true; | ||
| 161 | else if(s.charAt(i) == ')') | ||
| 162 | betweenParenthesis = false; | ||
| 163 | else if(s.charAt(i) == op && !betweenParenthesis) { | ||
| 164 | result.add(s.substring(b, i)); | ||
| 165 | b = i + 1; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | if(b < s.length()) result.add(s.substring(b)); | ||
| 169 | |||
| 170 | return result.toArray(new String[0]); | ||
| 171 | } | ||
| 172 | |||
| 98 | } | 173 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageUpperProgram.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageUpperProgram.java index 1664c99..e64c5e6 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageUpperProgram.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageUpperProgram.java | |||
| @@ -193,6 +193,7 @@ public abstract class MultiStageUpperProgram { | |||
| 193 | 193 | ||
| 194 | public abstract Collection<Violation> isIntegrated(MultiStageQueryEngine engine, boolean incrementally); | 194 | public abstract Collection<Violation> isIntegrated(MultiStageQueryEngine engine, boolean incrementally); |
| 195 | 195 | ||
| 196 | // TODO -RULE- | ||
| 196 | protected Violation violate(MultiStageQueryEngine engine, DLClause clause, boolean incrementally) { | 197 | protected Violation violate(MultiStageQueryEngine engine, DLClause clause, boolean incrementally) { |
| 197 | Utility.logTrace("checking constraint: " + clause); | 198 | Utility.logTrace("checking constraint: " + clause); |
| 198 | 199 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java index 687fa4a..3528788 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java | |||
| @@ -49,6 +49,7 @@ public abstract class Pick4NegativeConcept extends Treatment { | |||
| 49 | tripleManager.addTripleByID(tripleManager.getInstance(gapAtom, assignment)); | 49 | tripleManager.addTripleByID(tripleManager.getInstance(gapAtom, assignment)); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | // TODO -RULE- | ||
| 52 | protected boolean makeSatisfied(Violation violation, Comparator<Atom> comp) { | 53 | protected boolean makeSatisfied(Violation violation, Comparator<Atom> comp) { |
| 53 | LinkedList<AnswerTupleID> tuples = violation.getTuples(); | 54 | LinkedList<AnswerTupleID> tuples = violation.getTuples(); |
| 54 | DLClause constraint = violation.getConstraint(); | 55 | DLClause constraint = violation.getConstraint(); |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java index a56a793..15dfa03 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java | |||
| @@ -117,7 +117,7 @@ class ELHOUQueryReasoner extends QueryReasoner { | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | OWLOntology ontology = o; | 119 | OWLOntology ontology = o; |
| 120 | program = new DatalogProgram(ontology, properties.getToClassify()); | 120 | program = new DatalogProgram(ontology); |
| 121 | 121 | ||
| 122 | importData(program.getAdditionalDataFile()); | 122 | importData(program.getAdditionalDataFile()); |
| 123 | 123 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java index 15eb9e8..ac62488 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java | |||
| @@ -52,7 +52,7 @@ class HermiTReasoner extends QueryReasoner { | |||
| 52 | e.printStackTrace(); | 52 | e.printStackTrace(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | DatalogProgram datalogProgram = new DatalogProgram(tbox, false); | 55 | DatalogProgram datalogProgram = new DatalogProgram(tbox); |
| 56 | importData(datalogProgram.getAdditionalDataFile()); | 56 | importData(datalogProgram.getAdditionalDataFile()); |
| 57 | upperStore = new MultiStageQueryEngine("rl-upper", false); | 57 | upperStore = new MultiStageQueryEngine("rl-upper", false); |
| 58 | upperStore.importRDFData("data", getImportedData()); | 58 | upperStore.importRDFData("data", getImportedData()); |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 8e28142..71d5752 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -68,7 +68,7 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | ontology = o; | 70 | ontology = o; |
| 71 | program = new DatalogProgram(ontology, properties.getToClassify()); | 71 | program = new DatalogProgram(ontology); |
| 72 | // program.getLower().save(); | 72 | // program.getLower().save(); |
| 73 | // program.getUpper().save(); | 73 | // program.getUpper().save(); |
| 74 | // program.getGeneral().save(); | 74 | // program.getGeneral().save(); |
| @@ -154,7 +154,7 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 154 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); | 154 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); |
| 155 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); | 155 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); |
| 156 | 156 | ||
| 157 | // TODO add consistency check by Skolem-upper-bound | 157 | // TODO? add consistency check by Skolem-upper-bound |
| 158 | 158 | ||
| 159 | if(!isConsistent()) | 159 | if(!isConsistent()) |
| 160 | return false; | 160 | return false; |
| @@ -225,7 +225,7 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 225 | @Override | 225 | @Override |
| 226 | public void evaluateUpper(QueryRecord queryRecord) { | 226 | public void evaluateUpper(QueryRecord queryRecord) { |
| 227 | if(isDisposed()) throw new DisposedException(); | 227 | if(isDisposed()) throw new DisposedException(); |
| 228 | // TODO add new upper store | 228 | // TODO? add new upper store |
| 229 | AnswerTuples rlAnswer = null; | 229 | AnswerTuples rlAnswer = null; |
| 230 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; | 230 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; |
| 231 | try { | 231 | try { |
| @@ -388,7 +388,7 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 388 | Utility.logInfo(">> Semi-Skolemisation <<"); | 388 | Utility.logInfo(">> Semi-Skolemisation <<"); |
| 389 | t.reset(); | 389 | t.reset(); |
| 390 | 390 | ||
| 391 | DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false | 391 | DatalogProgram relevantProgram = new DatalogProgram(relevantSubset); |
| 392 | 392 | ||
| 393 | MultiStageQueryEngine relevantStore = | 393 | MultiStageQueryEngine relevantStore = |
| 394 | new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true | 394 | new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java b/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java index 29e74c2..e2a171d 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java +++ b/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java | |||
| @@ -2,11 +2,12 @@ package uk.ac.ox.cs.pagoda.rules; | |||
| 2 | 2 | ||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | 3 | import org.semanticweb.owlapi.model.OWLOntology; |
| 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; |
| 5 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; | ||
| 6 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; | 5 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; |
| 7 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | 6 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; |
| 8 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | 7 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; |
| 9 | 8 | ||
| 9 | import java.io.InputStream; | ||
| 10 | |||
| 10 | public class DatalogProgram extends Disposable { | 11 | public class DatalogProgram extends Disposable { |
| 11 | 12 | ||
| 12 | UpperDatalogProgram upperProgram = new UpperDatalogProgram(); | 13 | UpperDatalogProgram upperProgram = new UpperDatalogProgram(); |
| @@ -15,14 +16,36 @@ public class DatalogProgram extends Disposable { | |||
| 15 | 16 | ||
| 16 | BottomStrategy upperBottom; | 17 | BottomStrategy upperBottom; |
| 17 | 18 | ||
| 18 | public DatalogProgram(OWLOntology o) { | 19 | public DatalogProgram(InputStream inputStream) { |
| 19 | lowerProgram = new LowerDatalogProgram(); | 20 | lowerProgram = new LowerDatalogProgram(); |
| 20 | init(o, false); | 21 | |
| 22 | upperProgram.load(inputStream, upperBottom = new UpperUnaryBottom()); | ||
| 23 | lowerProgram.clone(upperProgram); | ||
| 24 | program.clone(upperProgram); | ||
| 25 | |||
| 26 | upperProgram.transform(); | ||
| 27 | lowerProgram.transform(); | ||
| 28 | program.transform(); | ||
| 29 | |||
| 30 | program.buildDependencyGraph(); | ||
| 31 | lowerProgram.dependencyGraph = upperProgram.buildDependencyGraph(); | ||
| 21 | } | 32 | } |
| 22 | 33 | ||
| 23 | public DatalogProgram(OWLOntology o, boolean toClassify) { | 34 | public DatalogProgram(OWLOntology o) { |
| 24 | lowerProgram = new LowerDatalogProgram(toClassify); | 35 | lowerProgram = new LowerDatalogProgram(); |
| 25 | init(o, toClassify); | 36 | |
| 37 | upperProgram.load(o, upperBottom = new UpperUnaryBottom()); | ||
| 38 | // upperProgram.load(o, upperBottom = new UnaryBottom()); | ||
| 39 | lowerProgram.clone(upperProgram); | ||
| 40 | program.clone(upperProgram); | ||
| 41 | // program.botStrategy = new UnaryBottom(); | ||
| 42 | |||
| 43 | upperProgram.transform(); | ||
| 44 | lowerProgram.transform(); | ||
| 45 | program.transform(); | ||
| 46 | |||
| 47 | program.buildDependencyGraph(); | ||
| 48 | lowerProgram.dependencyGraph = upperProgram.buildDependencyGraph(); | ||
| 26 | } | 49 | } |
| 27 | 50 | ||
| 28 | public LowerDatalogProgram getLower() { | 51 | public LowerDatalogProgram getLower() { |
| @@ -55,20 +78,4 @@ public class DatalogProgram extends Disposable { | |||
| 55 | super.dispose(); | 78 | super.dispose(); |
| 56 | if(upperProgram != null) upperProgram.deleteABoxTurtleFile(); | 79 | if(upperProgram != null) upperProgram.deleteABoxTurtleFile(); |
| 57 | } | 80 | } |
| 58 | |||
| 59 | private void init(OWLOntology o, boolean forSemFacet) { | ||
| 60 | upperProgram.load(o, upperBottom = new UpperUnaryBottom()); | ||
| 61 | // upperProgram.load(o, upperBottom = new UnaryBottom()); | ||
| 62 | lowerProgram.clone(upperProgram); | ||
| 63 | program.clone(upperProgram); | ||
| 64 | // program.botStrategy = new UnaryBottom(); | ||
| 65 | |||
| 66 | upperProgram.transform(); | ||
| 67 | lowerProgram.transform(); | ||
| 68 | program.transform(); | ||
| 69 | |||
| 70 | program.buildDependencyGraph(); | ||
| 71 | PredicateDependency graph = upperProgram.buildDependencyGraph(); | ||
| 72 | lowerProgram.dependencyGraph = graph; | ||
| 73 | } | ||
| 74 | } | 81 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/GeneralProgram.java b/src/uk/ac/ox/cs/pagoda/rules/GeneralProgram.java index 01ab427..e390a29 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/GeneralProgram.java +++ b/src/uk/ac/ox/cs/pagoda/rules/GeneralProgram.java | |||
| @@ -15,7 +15,7 @@ public class GeneralProgram extends Program { | |||
| 15 | ontology = relevantOntology; | 15 | ontology = relevantOntology; |
| 16 | 16 | ||
| 17 | ontologyDirectory = null; | 17 | ontologyDirectory = null; |
| 18 | dlOntology = null; | 18 | // dlOntology = null; |
| 19 | botStrategy = new UnaryBottom(); | 19 | botStrategy = new UnaryBottom(); |
| 20 | 20 | ||
| 21 | clauses = botStrategy.process(relevantClauses); | 21 | clauses = botStrategy.process(relevantClauses); |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/LowerDatalogProgram.java b/src/uk/ac/ox/cs/pagoda/rules/LowerDatalogProgram.java index 9930009..a2676e8 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/LowerDatalogProgram.java +++ b/src/uk/ac/ox/cs/pagoda/rules/LowerDatalogProgram.java | |||
| @@ -39,6 +39,7 @@ public class LowerDatalogProgram extends ApproxProgram implements IncrementalPro | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | // TODO -RULE- filter out unsafe rules | ||
| 42 | @Override | 43 | @Override |
| 43 | public void transform() { | 44 | public void transform() { |
| 44 | if (m_toClassify) { | 45 | if (m_toClassify) { |
| @@ -56,7 +57,7 @@ public class LowerDatalogProgram extends ApproxProgram implements IncrementalPro | |||
| 56 | else | 57 | else |
| 57 | super.transform(); | 58 | super.transform(); |
| 58 | 59 | ||
| 59 | Normalisation norm = new Normalisation(dlOntology.getDLClauses(), ontology, new NullaryBottom()); | 60 | Normalisation norm = new Normalisation(dlClauses, ontology, new NullaryBottom()); |
| 60 | BottomStrategy tBottom = new NullaryBottom(); | 61 | BottomStrategy tBottom = new NullaryBottom(); |
| 61 | norm.process(); | 62 | norm.process(); |
| 62 | for (DLClause nClause: norm.getNormlisedClauses()) { | 63 | for (DLClause nClause: norm.getNormlisedClauses()) { |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/Program.java b/src/uk/ac/ox/cs/pagoda/rules/Program.java index a0edf85..de06f52 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/Program.java +++ b/src/uk/ac/ox/cs/pagoda/rules/Program.java | |||
| @@ -4,6 +4,7 @@ import org.apache.commons.io.FilenameUtils; | |||
| 4 | import org.semanticweb.HermiT.Configuration; | 4 | import org.semanticweb.HermiT.Configuration; |
| 5 | import org.semanticweb.HermiT.model.*; | 5 | import org.semanticweb.HermiT.model.*; |
| 6 | import org.semanticweb.HermiT.structural.OWLClausification; | 6 | import org.semanticweb.HermiT.structural.OWLClausification; |
| 7 | import org.semanticweb.owlapi.apibinding.OWLManager; | ||
| 7 | import org.semanticweb.owlapi.model.*; | 8 | import org.semanticweb.owlapi.model.*; |
| 8 | import org.semanticweb.simpleETL.SimpleETL; | 9 | import org.semanticweb.simpleETL.SimpleETL; |
| 9 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 10 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| @@ -13,6 +14,7 @@ import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | |||
| 13 | import uk.ac.ox.cs.pagoda.constraints.NullaryBottom; | 14 | import uk.ac.ox.cs.pagoda.constraints.NullaryBottom; |
| 14 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; | 15 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; |
| 15 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 16 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 17 | import uk.ac.ox.cs.pagoda.hermit.RuleHelper; | ||
| 16 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 18 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 17 | import uk.ac.ox.cs.pagoda.util.Utility; | 19 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 18 | 20 | ||
| @@ -23,7 +25,9 @@ public abstract class Program implements KnowledgeBase { | |||
| 23 | 25 | ||
| 24 | protected String ontologyDirectory = null; | 26 | protected String ontologyDirectory = null; |
| 25 | protected OWLOntology ontology; | 27 | protected OWLOntology ontology; |
| 26 | protected DLOntology dlOntology; | 28 | // protected DLOntology dlOntology; |
| 29 | protected Set<DLClause> dlClauses = new HashSet<>(); | ||
| 30 | protected Set<Atom> positiveFacts = new HashSet<>(); | ||
| 27 | protected BottomStrategy botStrategy; | 31 | protected BottomStrategy botStrategy; |
| 28 | protected Collection<DLClause> clauses = new HashSet<DLClause>(); | 32 | protected Collection<DLClause> clauses = new HashSet<DLClause>(); |
| 29 | // protected Set<DLClause> used = new HashSet<DLClause>(); | 33 | // protected Set<DLClause> used = new HashSet<DLClause>(); |
| @@ -40,6 +44,24 @@ protected PredicateDependency dependencyGraph; | |||
| 40 | return sb.toString(); | 44 | return sb.toString(); |
| 41 | } | 45 | } |
| 42 | 46 | ||
| 47 | public void load(InputStream rules, BottomStrategy botStrategy) { | ||
| 48 | // this.botStrategy = botStrategy; | ||
| 49 | // // fake instantiation | ||
| 50 | try { | ||
| 51 | load(OWLManager.createOWLOntologyManager().createOntology(), botStrategy); | ||
| 52 | } catch (OWLOntologyCreationException e) { | ||
| 53 | e.printStackTrace(); | ||
| 54 | } | ||
| 55 | |||
| 56 | try(BufferedReader br = new BufferedReader(new InputStreamReader(rules))) { | ||
| 57 | String line; | ||
| 58 | while((line = br.readLine()) != null) | ||
| 59 | dlClauses.add(RuleHelper.parseClause(line)); | ||
| 60 | } catch (IOException e) { | ||
| 61 | e.printStackTrace(); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 43 | public void load(OWLOntology o, BottomStrategy botStrategy) { | 65 | public void load(OWLOntology o, BottomStrategy botStrategy) { |
| 44 | this.botStrategy = botStrategy; | 66 | this.botStrategy = botStrategy; |
| 45 | RLPlusOntology owlOntology = new RLPlusOntology(); | 67 | RLPlusOntology owlOntology = new RLPlusOntology(); |
| @@ -57,7 +79,7 @@ protected PredicateDependency dependencyGraph; | |||
| 57 | OWLOntology abox = OWLHelper.loadOntology(aboxOWLFile); | 79 | OWLOntology abox = OWLHelper.loadOntology(aboxOWLFile); |
| 58 | OWLOntologyManager manager = abox.getOWLOntologyManager(); | 80 | OWLOntologyManager manager = abox.getOWLOntologyManager(); |
| 59 | OWLAxiom axiom; | 81 | OWLAxiom axiom; |
| 60 | for (Atom atom: dlOntology.getPositiveFacts()) { | 82 | for (Atom atom: positiveFacts) { |
| 61 | if ((axiom = OWLHelper.getABoxAssertion(manager.getOWLDataFactory(), atom)) != null) | 83 | if ((axiom = OWLHelper.getABoxAssertion(manager.getOWLDataFactory(), atom)) != null) |
| 62 | manager.addAxiom(abox, axiom); | 84 | manager.addAxiom(abox, axiom); |
| 63 | } | 85 | } |
| @@ -90,7 +112,7 @@ protected PredicateDependency dependencyGraph; | |||
| 90 | 112 | ||
| 91 | @Override | 113 | @Override |
| 92 | public void transform() { | 114 | public void transform() { |
| 93 | for(DLClause dlClause : dlOntology.getDLClauses()) { | 115 | for(DLClause dlClause : dlClauses) { |
| 94 | DLClause simplifiedDLClause = DLClauseHelper.removeNominalConcept(dlClause); | 116 | DLClause simplifiedDLClause = DLClauseHelper.removeNominalConcept(dlClause); |
| 95 | simplifiedDLClause = removeAuxiliaryBodyAtoms(simplifiedDLClause); | 117 | simplifiedDLClause = removeAuxiliaryBodyAtoms(simplifiedDLClause); |
| 96 | simplifiedDLClause = DLClauseHelper.replaceWithDataValue(simplifiedDLClause); | 118 | simplifiedDLClause = DLClauseHelper.replaceWithDataValue(simplifiedDLClause); |
| @@ -190,7 +212,9 @@ protected PredicateDependency dependencyGraph; | |||
| 190 | void clone(Program program) { | 212 | void clone(Program program) { |
| 191 | this.ontologyDirectory = program.ontologyDirectory; | 213 | this.ontologyDirectory = program.ontologyDirectory; |
| 192 | this.ontology = program.ontology; | 214 | this.ontology = program.ontology; |
| 193 | this.dlOntology = program.dlOntology; | 215 | // this.dlOntology = program.dlOntology; |
| 216 | this.dlClauses = program.dlClauses; | ||
| 217 | this.positiveFacts = program.positiveFacts; | ||
| 194 | this.botStrategy = program.botStrategy; | 218 | this.botStrategy = program.botStrategy; |
| 195 | this.additionalDataFile = program.additionalDataFile; | 219 | this.additionalDataFile = program.additionalDataFile; |
| 196 | this.transitiveAxioms = program.transitiveAxioms; | 220 | this.transitiveAxioms = program.transitiveAxioms; |
| @@ -248,8 +272,9 @@ protected PredicateDependency dependencyGraph; | |||
| 248 | } | 272 | } |
| 249 | Utility.logInfo("The number of data property range axioms that are ignored: " + noOfDataPropertyRangeAxioms + "(" + noOfAxioms + ")"); | 273 | Utility.logInfo("The number of data property range axioms that are ignored: " + noOfDataPropertyRangeAxioms + "(" + noOfAxioms + ")"); |
| 250 | 274 | ||
| 251 | dlOntology = (DLOntology) clausifier.preprocessAndClausify(filteredOntology, null)[1]; | 275 | DLOntology dlOntology = (DLOntology) clausifier.preprocessAndClausify(filteredOntology, null)[1]; |
| 252 | clausifier = null; | 276 | dlClauses = dlOntology.getDLClauses(); |
| 277 | positiveFacts = dlOntology.getPositiveFacts(); | ||
| 253 | } | 278 | } |
| 254 | 279 | ||
| 255 | private DLClause removeAuxiliaryBodyAtoms(DLClause dlClause) { | 280 | private DLClause removeAuxiliaryBodyAtoms(DLClause dlClause) { |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java index 7d29c74..a140225 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java | |||
| @@ -9,7 +9,7 @@ import java.util.ArrayList; | |||
| 9 | import java.util.Collection; | 9 | import java.util.Collection; |
| 10 | import java.util.Collections; | 10 | import java.util.Collections; |
| 11 | 11 | ||
| 12 | /** | 12 | /*** |
| 13 | * Approximates existential rules through a limited form of Skolemisation. | 13 | * Approximates existential rules through a limited form of Skolemisation. |
| 14 | * <p> | 14 | * <p> |
| 15 | * Given a rule and a ground substitution, | 15 | * Given a rule and a ground substitution, |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/clauses/Conjunction.java b/src/uk/ac/ox/cs/pagoda/rules/clauses/Conjunction.java deleted file mode 100644 index 91bb3e7..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/clauses/Conjunction.java +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules.clauses; | ||
| 2 | |||
| 3 | public class Conjunction { | ||
| 4 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/rules/clauses/DLClause.java b/src/uk/ac/ox/cs/pagoda/rules/clauses/DLClause.java deleted file mode 100644 index 7394be0..0000000 --- a/src/uk/ac/ox/cs/pagoda/rules/clauses/DLClause.java +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules.clauses; | ||
| 2 | |||
| 3 | public class DLClause extends Clause { | ||
| 4 | |||
| 5 | // private DLClause(Atom[] headAtoms, Atom[] bodyAtoms) { | ||
| 6 | // super(headAtoms, bodyAtoms); | ||
| 7 | // } | ||
| 8 | // | ||
| 9 | // public static DLClause create(Atom[] headAtoms, Atom[] bodyAtoms) { | ||
| 10 | // return s_interningManager.intern(new DLClause(headAtoms, bodyAtoms)); | ||
| 11 | // } | ||
| 12 | } | ||
