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/rules | |
| parent | 0c39145b3b76b3db73db0a38d5324caa7ff3c434 (diff) | |
| download | ACQuA-c3480bb733b8bca976718a3dc2f09a21cb4b1b45.tar.gz ACQuA-c3480bb733b8bca976718a3dc2f09a21cb4b1b45.zip | |
Rules parsing.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/rules')
7 files changed, 64 insertions, 47 deletions
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 | } | ||
