本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntologyManager.removeAxiom方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntologyManager.removeAxiom方法的具體用法?Java OWLOntologyManager.removeAxiom怎麽用?Java OWLOntologyManager.removeAxiom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntologyManager
的用法示例。
在下文中一共展示了OWLOntologyManager.removeAxiom方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyChanges
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
@Override
public void applyChanges(final Iterable<OWLAxiom> changes,
final IncrementalChangeType type) {
// the changes are applied indirectly by modifying the ontology
final OWLOntologyManager manager = testOntology_
.getOWLOntologyManager();
for (OWLAxiom axiom : changes) {
switch (type) {
case ADD:
manager.addAxiom(testOntology_, axiom);
break;
case DELETE:
manager.removeAxiom(testOntology_, axiom);
break;
}
}
standardReasoner_.flush();
incrementalReasoner_.flush();
}
示例2: main
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public static void main(String[] args) throws OWLOntologyStorageException,
OWLOntologyCreationException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load your ontology
OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Classify the ontology.
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState"));
OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState")));
OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure")));
// Remove an existing axiom, add a new axiom
manager.addAxiom(ont, added);
manager.removeAxiom(ont, removed);
// This is a buffering reasoner, so you need to flush the changes
reasoner.flush();
// Re-classify the ontology, the changes should be accommodated
// incrementally (i.e. without re-inferring all subclass relationships)
// You should be able to see it from the log output
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例3: ignoreChangesInNonImportedOntologies
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Testing correctness of the reasoner with respect to ontology changes
*/
@Test
public void ignoreChangesInNonImportedOntologies() throws Exception {
OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// set up resolution of prefixes
DefaultPrefixManager 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#");
OWLClass extA = dataFactory.getOWLClass("A:A", pm);
OWLClass extB = dataFactory.getOWLClass("B:B", pm);
// loading the root ontology
OWLOntology root = loadOntology(man, "root.owl");
// Create an ELK reasoner.
ElkReasoner reasoner = (ElkReasoner) new ElkReasonerFactory()
.createReasoner(root);
// make sure the reasoner loads the ontology
reasoner.flush();
reasoner.isConsistent();
try {
OWLOntology nonImported = loadOntology(man, "nonImported.owl");
OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB);
man.removeAxiom(nonImported, axiom);
reasoner.flush();
AbstractReasonerState state = reasoner.getInternalReasoner();
assertTrue(state.stageManager.inputLoadingStage.isCompleted());
} finally {
reasoner.dispose();
}
}
示例4: modifyInferredAxiom
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
private static OWLAxiom modifyInferredAxiom(OWLAxiom axiom, OWLOntology ontology, boolean add) {
final OWLOntologyManager manager = ontology.getOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
final OWLAxiom newAxiom = updateInferredAxiom(axiom, factory, add);
// update ontology
manager.removeAxiom(ontology, axiom);
manager.addAxiom(ontology, newAxiom);
return newAxiom;
}
示例5: main
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = man.getOWLDataFactory();
// Load your ontology.
OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
"c:/ontologies/ontology.owl"));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Create your desired query class expression. In this example we
// will query ObjectIntersectionOf(A ObjectSomeValuesFrom(R B)).
PrefixManager pm = new DefaultPrefixManager("http://example.org/");
OWLClass A = dataFactory.getOWLClass(":A", pm);
OWLObjectProperty R = dataFactory.getOWLObjectProperty(":R", pm);
OWLClass B = dataFactory.getOWLClass(":B", pm);
OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
dataFactory.getOWLObjectSomeValuesFrom(R, B));
// Create a fresh name for the query.
OWLClass newName = dataFactory.getOWLClass(IRI.create("temp001"));
// Make the query equivalent to the fresh class
OWLAxiom definition = dataFactory.getOWLEquivalentClassesAxiom(newName,
query);
man.addAxiom(ont, definition);
// Remember to either flush the reasoner after the ontology change
// or create the reasoner in non-buffering mode. Note that querying
// a reasoner after an ontology change triggers re-classification of
// the whole ontology which might be costly. Therefore, if you plan
// to query for multiple complex class expressions, it will be more
// efficient to add the corresponding definitions to the ontology at
// once before asking any queries to the reasoner.
reasoner.flush();
// You can now retrieve subclasses, superclasses, and instances of
// the query class by using its new name instead.
reasoner.getSubClasses(newName, true);
reasoner.getSuperClasses(newName, true);
reasoner.getInstances(newName, false);
// After you are done with the query, you should remove the definition
man.removeAxiom(ont, definition);
// You can now add new definitions for new queries in the same way
// After you are done with all queries, do not forget to free the
// resources occupied by the reasoner
reasoner.dispose();
}
示例6: testRemovingXY
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* 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();
}
}
示例7: testRemovingAB
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* 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();
}
}
示例8: testChangesToOtherOntologies
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* 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();
}
}
示例9: changeAxiomAnnotations
import org.semanticweb.owlapi.model.OWLOntologyManager; //導入方法依賴的package包/類
/**
* Update the given axiom to a new set of axiom annotation.<br>
* <b>Side effect</b>: This removes the old axiom and adds the new axiom to
* the given ontology. The method also returns the new axiom to enable
* chaining.
*
* @param axiom
* @param annotations
* @param ontology
* @return newAxiom
*/
public static OWLAxiom changeAxiomAnnotations(OWLAxiom axiom, Set<OWLAnnotation> annotations, OWLOntology ontology) {
final OWLOntologyManager manager = ontology.getOWLOntologyManager();
final OWLDataFactory factory = manager.getOWLDataFactory();
final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, annotations, factory);
manager.removeAxiom(ontology, axiom);
manager.addAxiom(ontology, newAxiom);
return newAxiom;
}