@Test public void testMinusInf() throws Exception { String input = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)\n" + "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)\n" + "Prefix(:=<http://test.org/test#>)\n" + "Ontology(\nDeclaration(NamedIndividual(:a))\n" + "Declaration(DataProperty(:dp))\n" + "Declaration(Class(:A))\n" + "SubClassOf(:A DataAllValuesFrom(:dp owl:real))" + "\nSubClassOf(:A \n" + "DataSomeValuesFrom(:dp DataOneOf(\"-INF\"^^xsd:float \"-0\"^^xsd:integer))" + "\n)" + "\n" + "ClassAssertion(:A :a)" + "\n)"; StringDocumentSource in = new StringDocumentSource(input); OWLOntologyManager m = Factory.getManager(); OWLOntology o = m.loadOntologyFromOntologyDocument(in); StringDocumentTarget t = new StringDocumentTarget(); m.saveOntology(o, t); assertTrue(t.toString() + " should contain -INF", t.toString().contains("-INF")); OWLOntology o1 = m.loadOntologyFromOntologyDocument(new StringDocumentSource(t.toString())); assertEquals( "Obtologies were supposed to be the same", o.getLogicalAxioms(), o1.getLogicalAxioms()); }
@Override public void prepare() throws TaskException { // load positive and negative deltas via the OWL API try { OWLOntology additions = loadFromDisk(ADDITION_SUFFIX); OWLOntology deletions = loadFromDisk(DELETION_SUFFIX); applyToReasoner(additions.getLogicalAxioms(), true); applyToReasoner(deletions.getLogicalAxioms(), false); measureTime = additions.getLogicalAxiomCount() > 0 && deletions.getLogicalAxiomCount() > 0; } catch (OWLOntologyCreationException e) { throw new TaskException(e); } }
private void getPelletIncrementalClassifierRunTime(String baseOnt, String ontDir) throws Exception { System.out.println("Using Pellet Incremental Classifier..."); GregorianCalendar start = new GregorianCalendar(); File ontFile = new File(baseOnt); IRI documentIRI = IRI.create(ontFile); OWLOntology baseOntology = OWL.manager.loadOntology(documentIRI); IncrementalClassifier classifier = new IncrementalClassifier(baseOntology); classifier.classify(); System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount()); System.out.println("Time taken for base ontology (millis): " + Util.getElapsedTime(start)); File ontDirPath = new File(ontDir); File[] allFiles = ontDirPath.listFiles(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); addTripsBaseOntologies(manager); int count = 1; for (File owlFile : allFiles) { IRI owlDocumentIRI = IRI.create(owlFile); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(owlDocumentIRI); Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms(); for (OWLLogicalAxiom axiom : axioms) OWL.manager.applyChange(new AddAxiom(baseOntology, axiom)); System.out.println("\nLogical axioms: " + baseOntology.getLogicalAxiomCount()); System.out.println(count + " file: " + owlFile.getName()); // System.out.println("" + count + " file: " + owlFile.getName()); // GregorianCalendar start2 = new GregorianCalendar(); classifier.classify(); // System.out.println("Time taken (millis): " + // Util.getElapsedTime(start2)); manager.removeOntology(ontology); count++; } System.out.println("\nTotal time taken (millis): " + Util.getElapsedTime(start)); }
public Integer visit(OWLOntology ontology) { int max = _0; for (OWLAxiom axiom : ontology.getLogicalAxioms()) { int depth = axiom.accept(this); if (depth > max) { max = depth; } } return max; }
private OWLTheory loadTheory(OWLOntology ontology, String ontologyDir, String o1, String o2) { OWLTheory theory = getExtendTheory(ontology, false); LinkedHashSet<OWLLogicalAxiom> bx = new LinkedHashSet<OWLLogicalAxiom>(); OWLOntology ontology1 = getOntologySimple(ontologyDir, o1 + ".owl"); OWLOntology ontology2 = getOntologySimple(ontologyDir, o2 + ".owl"); Set<OWLLogicalAxiom> onto1Axioms = createIntersection(ontology.getLogicalAxioms(), ontology1.getLogicalAxioms()); Set<OWLLogicalAxiom> onto2Axioms = createIntersection(ontology.getLogicalAxioms(), ontology2.getLogicalAxioms()); int modOnto1Size = onto1Axioms.size(); int modOnto2Size = onto2Axioms.size(); int modMappingSize = ontology.getLogicalAxioms().size() - modOnto1Size - modOnto2Size; bx.addAll(onto1Axioms); bx.addAll(onto2Axioms); theory.getKnowledgeBase().addBackgroundFormulas(bx); logger.info( "ontology axiom sizes: " + modOnto1Size + "," + modOnto2Size + "," + modMappingSize); return theory; }
private List<Construct> getOrderedConstructs() { constructs.clear(); constructs.add(AL); for (OWLOntology ont : ontologies) { for (OWLAxiom ax : ont.getLogicalAxioms()) { ax.accept(this); } } pruneConstructs(); List<Construct> cons = new ArrayList<Construct>(constructs); Collections.sort(cons, new ConstructComparator()); return cons; }
public void getELKIncrementalRuntime(String baseOnt, String ontDir) throws Exception { GregorianCalendar start = new GregorianCalendar(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); IRI documentIRI = IRI.create(new File(baseOnt)); OWLOntology baseOntology = manager.loadOntology(documentIRI); System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount()); // findDataHasValueAxiom(baseOntology.getAxioms(AxiomType.SUBCLASS_OF)); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(baseOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); File[] files = new File(ontDir).listFiles(); int count = 0; OWLOntologyManager manager2 = OWLManager.createOWLOntologyManager(); addTripsBaseOntologies(manager2); for (File file : files) { System.out.println("File name: " + file.getName()); documentIRI = IRI.create(file); OWLOntology ontology = manager2.loadOntology(documentIRI); Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms(); // findDataHasValueAxiom(ontology.getAxioms(AxiomType.SUBCLASS_OF)); manager.addAxioms(baseOntology, axioms); reasoner.flush(); System.out.println("Logical axioms: " + baseOntology.getLogicalAxiomCount()); // From the ELK wiki, it seems ABox reasoning will trigger TBox reasoning reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); manager2.removeOntology(ontology); count++; System.out.println("Done with " + count); // if(count == 5) // break; } reasoner.dispose(); System.out.println("Time taken (millis): " + Util.getElapsedTime(start)); }
public Set<OWLClass> getRootUnsatisfiableClasses() { // StructureBasedRootClassFinder srd = new StructureBasedRootClassFinder(this.baseReasoner); StructuralRootDerivedReasoner srd = new StructuralRootDerivedReasoner(this.manager, this.baseReasoner, this.reasonerFactory); Set<OWLClass> estimatedRoots = srd.getRootUnsatisfiableClasses(); this.cls2JustificationMap = new HashMap<OWLClass, Set<Explanation>>(); Set<OWLAxiom> allAxioms = new HashSet<OWLAxiom>(); for (OWLOntology ont : this.baseReasoner.getRootOntology().getImportsClosure()) { allAxioms.addAll(ont.getLogicalAxioms()); } for (OWLClass cls : estimatedRoots) { this.cls2JustificationMap.put(cls, new HashSet<Explanation>()); System.out.println("POTENTIAL ROOT: " + cls); } System.out.println("Finding real roots from " + estimatedRoots.size() + " estimated roots"); int done = 0; this.roots.addAll(estimatedRoots); for (OWLClass estimatedRoot : estimatedRoots) { try { PelletExplanationGenerator gen = new PelletExplanationGenerator(manager.createOntology(allAxioms)); OWLDataFactory df = this.manager.getOWLDataFactory(); Set<Explanation> expls = gen.getExplanations(df.getOWLSubClassOfAxiom(estimatedRoot, df.getOWLNothing())); cls2JustificationMap.get(estimatedRoot).addAll(expls); ++done; System.out.println("Done " + done); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } } for (OWLClass clsA : estimatedRoots) { for (OWLClass clsB : estimatedRoots) if (!clsA.equals(clsB)) { Set<Explanation> clsAExpls = cls2JustificationMap.get(clsA); Set<Explanation> clsBExpls = cls2JustificationMap.get(clsB); boolean clsARootForClsB = false; boolean clsBRootForClsA = false; for (Explanation clsAExpl : clsAExpls) { for (Explanation clsBExpl : clsBExpls) if (isRootFor(clsAExpl, clsBExpl)) { clsARootForClsB = true; } else if (isRootFor(clsBExpl, clsAExpl)) { clsBRootForClsA = true; } } Explanation clsAExpl; if ((!clsARootForClsB) || (!clsBRootForClsA)) if (clsARootForClsB) { this.roots.remove(clsB); } else if (clsBRootForClsA) this.roots.remove(clsA); } } OWLClass clsA; return this.roots; }