Java Code Examples for org.semanticweb.owlapi.model.PrefixManager#setDefaultPrefix()
The following examples show how to use
org.semanticweb.owlapi.model.PrefixManager#setDefaultPrefix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner with respect to ontology changes * */ @Test public void testNoChanges() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainX = dataFactory.getOWLClass(":X", pm); OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { // statistics about the root ontology assertEquals(root.getAxiomCount(), 3); // all three ontologies should be in the closure assertEquals(root.getImportsClosure().size(), 3); // all axioms from three ontologies should be in the closure assertEquals(getAxioms(root).size(), 6); // reasoner queries -- all subclasses are there assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( mainY)); assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( extA)); assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity( extB)); assertTrue(reasoner.getSuperClasses(extA, true) .containsEntity(extB)); assertTrue(reasoner.getSuperClasses(extB, true) .containsEntity(extC)); } finally { reasoner.dispose(); } }
Example 2
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner with respect to ontology changes * * removing an axiom ":X is-a :Y" */ @Test public void testRemovingXY() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainX = dataFactory.getOWLClass(":X", pm); OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { // ************************************ // ** removing an axiom ":X is-a :Y" // ************************************ OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(mainX, mainY); man.removeAxiom(root, axiom); reasoner.flush(); // the root ontology contains one fewer axioms assertEquals(root.getAxiomCount(), 2); // the number of ontologies in the import closure does not change assertEquals(root.getImportsClosure().size(), 3); // the total number of axioms reduces assertEquals(getAxioms(root).size(), 5); // reasoner queries -- first subsumption is gone assertFalse(reasoner.getSuperClasses(mainX, true).containsEntity( mainY)); assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( extA)); assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity( extB)); assertTrue(reasoner.getSuperClasses(extA, true) .containsEntity(extB)); assertTrue(reasoner.getSuperClasses(extB, true) .containsEntity(extC)); } finally { reasoner.dispose(); } }
Example 3
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner with respect to ontology changes * <p> * trying to remove "A:A is-a B:B" * <p> * Because the removed axiom belongs to the imported ontology and * not main ontology, the remove does not make any effect. So, we * should end up with the ontology we have started with. * <p> * This test is ignored, because as of OWL API 4.1.3 the removal * of the axiom is broadcasted even though the axiom is not removed. */ @Test public void testRemovingAB() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainX = dataFactory.getOWLClass(":X", pm); OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { // ************************************ // ** trying to remove "A:A is-a B:B" // ************************************ OWLSubClassOfAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB); man.removeAxiom(root, axiom); reasoner.flush(); // Because the removed axiom belongs to the imported ontology and // not main ontology, the remove does not make any effect. So, we // should end up with the ontology we have started with assertEquals(root.getAxiomCount(), 3); // all three ontologies should be in the closure assertEquals(root.getImportsClosure().size(), 3); // all axioms from three ontologies should be in the closure assertEquals(getAxioms(root).size(), 6); // reasoner queries -- all subsumptions are there assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( mainY)); assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( extA)); assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity( extB)); assertTrue(reasoner.getSuperClasses(extA, true) .containsEntity(extB)); assertTrue(reasoner.getSuperClasses(extB, true) .containsEntity(extC)); } finally { reasoner.dispose(); } }
Example 4
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner with respect to ontology changes * <p> * removing the import declaration for </impA> */ @Test public void testRemovingImpA() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainX = dataFactory.getOWLClass(":X", pm); OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { // ************************************ // ** removing the import declaration for </impA> // ************************************ OWLImportsDeclaration importA = new OWLImportsDeclarationImpl( IRI.create("http://www.example.com#impA")); OWLOntologyChange change = new RemoveImport(root, importA); man.applyChange(change); reasoner.flush(); // Now the root ontology should not import anything assertEquals(root.getAxiomCount(), 3); assertEquals(root.getImportsClosure().size(), 1); assertEquals(getAxioms(root).size(), 3); // reasoner queries -- only subsumptions of the root ontology are // there assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( mainY)); assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( extA)); assertTrue(reasoner.getSuperClasses(mainY, true).containsEntity( extB)); assertFalse(reasoner.getSuperClasses(extA, true).containsEntity( extB)); assertFalse(reasoner.getSuperClasses(extB, true).containsEntity( extC)); } finally { reasoner.dispose(); } }
Example 5
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner with respect to ontology changes * <p> * removing the import declaration for </impA>, * adding the import declaration for </impB> and removing * ":Y is-a B:B" */ @Test public void testRemovingImpAAddingImpBRemovingYB() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainX = dataFactory.getOWLClass(":X", pm); OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { // ************************************ // ** adding the import declaration for </impB> and removing // ":Y is-a B:B" // ************************************ OWLImportsDeclaration importA = new OWLImportsDeclarationImpl( IRI.create("http://www.example.com#impA")); OWLOntologyChange change = new RemoveImport(root, importA); man.applyChange(change); OWLImportsDeclaration importB = new OWLImportsDeclarationImpl( IRI.create("http://www.example.com#impB")); change = new AddImport(root, importB); man.applyChange(change); OWLSubClassOfAxiom axiom = dataFactory.getOWLSubClassOfAxiom(mainY, extB); man.removeAxiom(root, axiom); reasoner.flush(); // Now ontology should import only ontology </impB> assertEquals(root.getAxiomCount(), 2); assertEquals(root.getImportsClosure().size(), 2); assertEquals(getAxioms(root).size(), 4); // reasoner queries -- only subsumptions of the root // ontology </impB> and there assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( mainY)); assertTrue(reasoner.getSuperClasses(mainX, true).containsEntity( extA)); assertFalse(reasoner.getSuperClasses(mainY, true).containsEntity( extB)); assertFalse(reasoner.getSuperClasses(extA, true).containsEntity( extB)); assertTrue(reasoner.getSuperClasses(extB, true) .containsEntity(extC)); } finally { reasoner.dispose(); } }
Example 6
Source File: ElkReasonerTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
/** * Testing correctness of the reasoner when changes are made to other, imported or not, ontologies * */ @Test public void testChangesToOtherOntologies() throws Exception { OWLOntologyManager man = TestOWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = man.getOWLDataFactory(); // set up resolution of prefixes PrefixManager pm = new DefaultPrefixManager(); pm.setDefaultPrefix("http://www.example.com/main#"); pm.setPrefix("A:", "http://www.example.com/A#"); pm.setPrefix("B:", "http://www.example.com/B#"); // define query classes OWLClass mainY = dataFactory.getOWLClass(":Y", pm); OWLClass extA = dataFactory.getOWLClass("A:A", pm); OWLClass extB = dataFactory.getOWLClass("B:B", pm); OWLClass extC = dataFactory.getOWLClass("B:C", pm); // loading the root ontology OWLOntology root = loadOntology(man, "root.owl"); // the imported ontologies must be loaded OWLOntology ontoA = man.getOntology(IRI.create("http://www.example.com/A")); OWLOntology ontoB = man.getOntology(IRI.create("http://www.example.com/B")); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(root); try { assertTrue(reasoner.getSuperClasses(extA, false).containsEntity( extC)); assertTrue(reasoner.getSuperClasses(mainY, false).containsEntity( extC)); // ************************************ // ** removing an axiom "A:A is-a B:B" from impA // ************************************ OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB); man.removeAxiom(ontoA, axiom); reasoner.flush(); assertFalse(reasoner.getSuperClasses(extA, false).containsEntity( extC)); // put it back man.addAxiom(ontoA, axiom); reasoner.flush(); assertTrue(reasoner.getSuperClasses(extA, false).containsEntity( extC)); // ************************************ // ** removing an axiom "B:B is-a B:C" from impB // ************************************ axiom = dataFactory.getOWLSubClassOfAxiom(extB, extC); man.removeAxiom(ontoB, axiom); reasoner.flush(); assertFalse(reasoner.getSuperClasses(mainY, false).containsEntity( extC)); } finally { reasoner.dispose(); } }