diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 16:31:48 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 16:31:48 +0100 |
| commit | 4298cdef8e551325cd16b4e24ae6699c44b60751 (patch) | |
| tree | f939308424c6baf49eaafd7cb868f616604b2d4b /src | |
| parent | 2e069a4966e6305194c4168d6fc5c406123d7f64 (diff) | |
| download | ACQuA-4298cdef8e551325cd16b4e24ae6699c44b60751.tar.gz ACQuA-4298cdef8e551325cd16b4e24ae6699c44b60751.zip | |
Rewritten ontology loading of class RLPlusOntology. Now query-dependent skolemisation works.
Diffstat (limited to 'src')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index 767d379..d961223 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.approx; | 1 | package uk.ac.ox.cs.pagoda.approx; |
| 2 | 2 | ||
| 3 | import org.apache.commons.io.FilenameUtils; | ||
| 3 | import org.semanticweb.HermiT.Configuration; | 4 | import org.semanticweb.HermiT.Configuration; |
| 4 | import org.semanticweb.HermiT.model.DLClause; | 5 | import org.semanticweb.HermiT.model.DLClause; |
| 5 | import org.semanticweb.HermiT.model.DLOntology; | 6 | import org.semanticweb.HermiT.model.DLOntology; |
| @@ -19,25 +20,22 @@ import java.nio.file.Paths; | |||
| 19 | import java.util.*; | 20 | import java.util.*; |
| 20 | 21 | ||
| 21 | public class RLPlusOntology implements KnowledgeBase { | 22 | public class RLPlusOntology implements KnowledgeBase { |
| 22 | 23 | ||
| 24 | private static final String DEFAULT_ONTOLOGY_FILE_EXTENSION = "owl"; | ||
| 23 | OWLOntologyManager manager; | 25 | OWLOntologyManager manager; |
| 24 | OWLDataFactory factory; | 26 | OWLDataFactory factory; |
| 25 | String ontologyIRI; | 27 | String ontologyIRI; |
| 26 | String corrFileName = null; | 28 | String corrFileName = null; |
| 27 | String outputPath, aBoxPath; | 29 | String outputPath, aBoxPath; |
| 28 | |||
| 29 | OWLOntology inputOntology = null; | 30 | OWLOntology inputOntology = null; |
| 30 | OWLOntology tBox = null; | 31 | OWLOntology tBox = null; |
| 31 | OWLOntology aBox = null; | 32 | OWLOntology aBox = null; |
| 32 | OWLOntology restOntology = null; | 33 | OWLOntology restOntology = null; |
| 33 | OWLOntology outputOntology = null; //RL ontology | 34 | OWLOntology outputOntology = null; //RL ontology |
| 34 | |||
| 35 | DLOntology dlOntology = null; | 35 | DLOntology dlOntology = null; |
| 36 | int rlCounter = 0; | 36 | int rlCounter = 0; |
| 37 | 37 | LinkedList<Clause> clauses; | |
| 38 | LinkedList<Clause> clauses; | ||
| 39 | Map<OWLAxiom, OWLAxiom> correspondence; | 38 | Map<OWLAxiom, OWLAxiom> correspondence; |
| 40 | |||
| 41 | BottomStrategy botStrategy; | 39 | BottomStrategy botStrategy; |
| 42 | Random random = new Random(19900114); | 40 | Random random = new Random(19900114); |
| 43 | private Map<OWLClassExpression, Integer> subCounter = null; | 41 | private Map<OWLClassExpression, Integer> subCounter = null; |
| @@ -45,7 +43,7 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 45 | 43 | ||
| 46 | // FIXME multiple anonymous ontologies | 44 | // FIXME multiple anonymous ontologies |
| 47 | @Override | 45 | @Override |
| 48 | public void load(OWLOntology o, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { | 46 | public void load(OWLOntology ontology, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { |
| 49 | if (bottomStrategy instanceof UnaryBottom) | 47 | if (bottomStrategy instanceof UnaryBottom) |
| 50 | botStrategy = BottomStrategy.UNARY; | 48 | botStrategy = BottomStrategy.UNARY; |
| 51 | else if (bottomStrategy instanceof NullaryBottom) | 49 | else if (bottomStrategy instanceof NullaryBottom) |
| @@ -55,55 +53,60 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 55 | 53 | ||
| 56 | if(corrFileName == null) | 54 | if(corrFileName == null) |
| 57 | corrFileName = "rlplus.crr"; | 55 | corrFileName = "rlplus.crr"; |
| 58 | manager = o.getOWLOntologyManager(); | 56 | manager = ontology.getOWLOntologyManager(); |
| 59 | // manager = OWLManager.createOWLOntologyManager(); | 57 | // manager = OWLManager.createOWLOntologyManager(); |
| 60 | factory = manager.getOWLDataFactory(); | 58 | factory = manager.getOWLDataFactory(); |
| 61 | inputOntology = o; | 59 | inputOntology = ontology; |
| 62 | 60 | ||
| 63 | try { | 61 | try { |
| 64 | String path = OWLHelper.getOntologyPath(inputOntology); | 62 | IRI ontologyIri; |
| 65 | String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); | 63 | if(ontology.isAnonymous()) { |
| 66 | String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; | 64 | String anonymousOntologySuffix = Long.toString(System.currentTimeMillis()); |
| 67 | 65 | ontologyIri = IRI.create("http://www.example.org/", "anonymous-ontology-" | |
| 68 | if (inputOntology.getOntologyID().getOntologyIRI() == null) | 66 | + anonymousOntologySuffix + "." + DEFAULT_ONTOLOGY_FILE_EXTENSION); |
| 69 | ontologyIRI = "http://www.example.org/anonymous-ontology" + originalExtension; | 67 | } |
| 70 | else | 68 | else |
| 71 | ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString(); | 69 | ontologyIri = inputOntology.getOntologyID().getOntologyIRI(); |
| 72 | 70 | ||
| 73 | String tOntoIRI = ontologyIRI; | 71 | String ontologyIriPrefix = ontologyIri.getNamespace(); |
| 74 | if (!tOntoIRI.endsWith(originalExtension)) tOntoIRI += originalExtension; | 72 | ontologyIRI = ontologyIri.toString(); |
| 75 | 73 | String ontologyIriFragment = ontologyIri.getFragment(); | |
| 76 | String rlOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-RL.owl" : tOntoIRI.replaceFirst(originalExtension, "-RL.owl"); | 74 | String originalFileName = FilenameUtils.removeExtension(ontologyIriFragment); |
| 77 | String rlDocumentIRI = (outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "RL.owl").toString()); | 75 | String originalExtension = FilenameUtils.getExtension(ontologyIriFragment); |
| 78 | outputOntology = manager.createOntology(IRI.create(rlOntologyIRI)); | 76 | if(originalExtension.isEmpty()) originalExtension = DEFAULT_ONTOLOGY_FILE_EXTENSION; |
| 79 | manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(rlDocumentIRI))); | 77 | |
| 80 | 78 | ||
| 81 | String tBoxOntologyIRI, aBoxOntologyIRI; | 79 | IRI rlOntologyIRI = IRI.create(ontologyIriPrefix, originalFileName + "-RL." + originalExtension); |
| 82 | tBoxOntologyIRI = | 80 | outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), |
| 83 | originalExtension.isEmpty() ? tOntoIRI + "-TBox.owl" : tOntoIRI.replaceFirst(originalExtension, "-TBox.owl"); | 81 | originalFileName + "-RL." + originalExtension).toString(); |
| 84 | aBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-ABox.owl" : tOntoIRI.replaceFirst(originalExtension, "-ABox.owl"); | 82 | IRI rlDocumentIRI = IRI.create(outputPath); |
| 85 | 83 | outputOntology = manager.createOntology(rlOntologyIRI); | |
| 86 | String tBoxDocumentIRI = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "TBox.owl").toString(); | 84 | manager.setOntologyDocumentIRI(outputOntology, rlDocumentIRI); |
| 87 | String aBoxDocumentIRI = (aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "ABox.owl").toString()); | 85 | |
| 88 | tBox = manager.createOntology(IRI.create(tBoxOntologyIRI)); | 86 | String tBoxOntologyFragment = originalFileName + "-TBox." + originalExtension; |
| 89 | aBox = manager.createOntology(IRI.create(aBoxOntologyIRI)); | 87 | IRI tBoxOntologyIRI = IRI.create(ontologyIriPrefix, tBoxOntologyFragment); |
| 90 | manager.setOntologyDocumentIRI(tBox, IRI.create(Utility.toFileIRI(tBoxDocumentIRI))); | 88 | IRI tBoxDocumentIRI = |
| 91 | manager.setOntologyDocumentIRI(aBox, IRI.create(Utility.toFileIRI(aBoxDocumentIRI))); | 89 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), tBoxOntologyFragment)); |
| 90 | |||
| 91 | String aBoxOntologyFragment = originalFileName + "-ABox." + originalExtension; | ||
| 92 | IRI aBoxOntologyIRI = IRI.create(ontologyIriPrefix, aBoxOntologyFragment); | ||
| 93 | aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath()) + aBoxOntologyFragment; | ||
| 94 | IRI aBoxDocumentIRI = | ||
| 95 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), aBoxOntologyFragment)); | ||
| 96 | |||
| 97 | tBox = manager.createOntology(tBoxOntologyIRI); | ||
| 98 | aBox = manager.createOntology(aBoxOntologyIRI); | ||
| 99 | manager.setOntologyDocumentIRI(tBox, tBoxDocumentIRI); | ||
| 100 | manager.setOntologyDocumentIRI(aBox, aBoxDocumentIRI); | ||
| 92 | 101 | ||
| 93 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); | 102 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); |
| 94 | manager.saveOntology(aBox, aBoxOut); | 103 | manager.saveOntology(aBox, aBoxOut); |
| 95 | aBoxOut.close(); | 104 | aBoxOut.close(); |
| 96 | 105 | ||
| 97 | restOntology = manager.createOntology(); | 106 | restOntology = manager.createOntology(); |
| 98 | } | 107 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { |
| 99 | catch (OWLOntologyCreationException e) { | ||
| 100 | e.printStackTrace(); | ||
| 101 | } catch (OWLOntologyStorageException e) { | ||
| 102 | // TODO Auto-generated catch block | ||
| 103 | e.printStackTrace(); | ||
| 104 | } catch (IOException e) { | ||
| 105 | // TODO Auto-generated catch block | ||
| 106 | e.printStackTrace(); | 108 | e.printStackTrace(); |
| 109 | System.exit(1); | ||
| 107 | } | 110 | } |
| 108 | } | 111 | } |
| 109 | 112 | ||
