本文整理匯總了Java中org.semanticweb.owlapi.model.OWLDataFactory.getOWLSubClassOfAxiom方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLDataFactory.getOWLSubClassOfAxiom方法的具體用法?Java OWLDataFactory.getOWLSubClassOfAxiom怎麽用?Java OWLDataFactory.getOWLSubClassOfAxiom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLDataFactory
的用法示例。
在下文中一共展示了OWLDataFactory.getOWLSubClassOfAxiom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepare
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
@Override
void prepare() {
final OWLDataFactory factory = new OWLDataFactoryImpl();
A = factory.getOWLClass(IRI.create("A"));
B = factory.getOWLClass(IRI.create("B"));
OWLObjectProperty R = factory.getOWLObjectProperty(IRI.create("R"));
OWLObjectProperty S = factory.getOWLObjectProperty(IRI.create("S"));
OWLAxiom axExSsomeAsubB = factory.getOWLSubClassOfAxiom(
factory.getOWLObjectSomeValuesFrom(S, A), B);
OWLAxiom axReflR = factory.getOWLReflexiveObjectPropertyAxiom(R);
axRsubS = factory.getOWLSubObjectPropertyOfAxiom(R, S);
// from these three axioms it should follow A subclass B
ontologyManager = TestOWLManager.createOWLOntologyManager();
try {
ont = ontologyManager.createOntology(new HashSet<OWLAxiom>(Arrays
.asList(axExSsomeAsubB, axReflR, axRsubS)));
} catch (OWLOntologyCreationException e) {
fail(e.toString());
}
}
開發者ID:liveontologies,項目名稱:elk-reasoner,代碼行數:21,代碼來源:RoleAxiomOWLAPILowLevelIncrementalClassTest.java
示例2: visit
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
@Override
public OWLAxiom visit(GCI1Axiom axiom) {
Objects.requireNonNull(axiom);
OWLClass owlLeftSubClass = translator.getTranslationRepository().getOWLClass(axiom.getLeftSubClass());
OWLClass owlRightSubClass = translator.getTranslationRepository().getOWLClass(axiom.getRightSubClass());
OWLClass owlSuperClass = translator.getTranslationRepository().getOWLClass(axiom.getSuperClass());
Set<OWLAnnotation> owlAnnotations = translateAnnotations(axiom.getAnnotations());
OWLDataFactory dataFactory = ontology.getOWLOntologyManager().getOWLDataFactory();
Set<OWLClass> set = new HashSet<>();
set.add(owlLeftSubClass);
set.add(owlRightSubClass);
OWLClassExpression owlObjectIntersectionOf = dataFactory.getOWLObjectIntersectionOf(set);
return dataFactory.getOWLSubClassOfAxiom(owlObjectIntersectionOf, owlSuperClass, owlAnnotations);
}
示例3: getAxiomsForReadingOffCompexProperties
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
public OWLAxiom[] getAxiomsForReadingOffCompexProperties(OWLDataFactory factory, ReasonerProgressMonitor monitor, int completedSteps, int steps) {
if (m_complexRoles.size()>0) {
int noAdditionalAxioms=0;
List<OWLAxiom> additionalAxioms=new ArrayList<OWLAxiom>();
m_interruptFlag.startTask();
try {
for (;m_currentIndividualIndex<m_individuals.length && noAdditionalAxioms < thresholdForAdditionalAxioms;m_currentIndividualIndex++) {
Individual ind=m_individuals[m_currentIndividualIndex];
for (AtomicRole objectRole : m_complexRoles) {
completedSteps++;
if (monitor!=null)
monitor.reasonerTaskProgressChanged(completedSteps,steps);
OWLObjectProperty objectProperty=factory.getOWLObjectProperty(IRI.create(objectRole.getIRI()));
String indIRI=ind.getIRI();
OWLClass classForIndividual=factory.getOWLClass(IRI.create("internal:individual-concept#"+indIRI));
OWLAxiom axiom=factory.getOWLClassAssertionAxiom(classForIndividual,factory.getOWLNamedIndividual(IRI.create(indIRI)));
additionalAxioms.add(axiom); // A_a(a)
AtomicConcept conceptForRole=AtomicConcept.create("internal:individual-concept#"+objectRole.getIRI()+"#"+indIRI);
OWLClass classForRoleAndIndividual=factory.getOWLClass(IRI.create(conceptForRole.getIRI()));
axiom=factory.getOWLSubClassOfAxiom(classForIndividual,factory.getOWLObjectAllValuesFrom(objectProperty,classForRoleAndIndividual));
additionalAxioms.add(axiom); // A_a implies forall r.A_a^r
noAdditionalAxioms+=2;
m_interruptFlag.checkInterrupt();
}
}
} finally {
m_interruptFlag.endTask();
}
OWLAxiom[] additionalAxiomsArray=new OWLAxiom[additionalAxioms.size()];
return additionalAxioms.toArray(additionalAxiomsArray);
}
else {
m_currentIndividualIndex=m_individuals.length-1;
return new OWLAxiom[0];
}
}
示例4: getEntailment
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
private static OWLAxiom getEntailment() {
// Let's pick some class subsumption we want to explain
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLClass subsumee = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#LiquidFood"));
OWLClass subsumer = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#Food"));
return factory.getOWLSubClassOfAxiom(subsumee, subsumer);
}
示例5: main
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的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();
}
示例6: prepare
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
@Override
void prepare() {
final OWLDataFactory factory = new OWLDataFactoryImpl();
A = factory.getOWLClass(IRI.create("A"));
B = factory.getOWLClass(IRI.create("B"));
axAsubB = factory.getOWLSubClassOfAxiom(A, B);
axBsubA = factory.getOWLSubClassOfAxiom(B, A);
ontologyManager = TestOWLManager.createOWLOntologyManager();
try {
ont = ontologyManager.createOntology(new HashSet<OWLAxiom>(Arrays
.asList(axAsubB, axBsubA)));
} catch (OWLOntologyCreationException e) {
fail(e.toString());
}
}
開發者ID:liveontologies,項目名稱:elk-reasoner,代碼行數:16,代碼來源:ConceptAxiomOWLAPILowLevelIncrementalClassTest.java
示例7: testEdgeCache
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
@Test
public void testEdgeCache() throws Exception {
OWLGraphWrapper g = getGraph("graph/cache-test.obo");
OWLOntology o = g.getSourceOntology();
OWLOntologyManager m = o.getOWLOntologyManager();
OWLDataFactory f = m.getOWLDataFactory();
OWLClass orphan = g.getOWLClassByIdentifier("FOO:0004");
OWLClass root = g.getOWLClassByIdentifier("FOO:0001");
g.getEdgesBetween(orphan, root); //just to trigger the cache
OWLSubClassOfAxiom ax = f.getOWLSubClassOfAxiom(orphan, root);
AddAxiom addAx = new AddAxiom(o, ax);
m.applyChange(addAx);
Set<OWLGraphEdge> edges = g.getEdgesBetween(orphan, root);
assertNotNull(edges);
assertEquals(0, edges.size());
g.clearCachedEdges(); // test clear cache method
edges = g.getEdgesBetween(orphan, root);
assertNotNull(edges);
assertEquals(1, edges.size());
}
示例8: assertSubClass
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
* Convenience method for asserting a subClass relation between
* a parent and child class in an ontology.
*
* @param ontology the current ontology
* @param child the child class
* @param parent the parent class
* @return the axiom
*/
protected static OWLSubClassOfAxiom assertSubClass(
OWLOntology ontology, OWLClass child, OWLClass parent) {
OWLOntologyManager manager = ontology.getOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
OWLSubClassOfAxiom axiom =
dataFactory.getOWLSubClassOfAxiom(child, parent);
ontology.getOWLOntologyManager().addAxiom(ontology, axiom);
return axiom;
}
示例9: testUnsatisfiabilityDuetoSimpleSubsumptionViolation
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
public void testUnsatisfiabilityDuetoSimpleSubsumptionViolation() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B")));
OWLClassExpression complClassB = factory.getOWLObjectComplementOf(classB);
OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indiv);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(complClassB, indiv);
OWLSubClassOfAxiom subClOf = factory.getOWLSubClassOfAxiom(classA, classB);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
manager.addAxiom(ontology, subClOf);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例10: testUnsatisfiabilityDoToFixedDomain1
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
* Smth like
* A subClassOf r min 5 B
* But we have only a domain with 4 elements ...
*/
public void testUnsatisfiabilityDoToFixedDomain1() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B")));
OWLObjectPropertyExpression roleR = factory.getOWLObjectProperty(IRI.create(String.format("%s#%s", PREFIX, "r")));
OWLNamedIndividual indA = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLNamedIndividual indB = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "b")));
OWLNamedIndividual indC = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "c")));
OWLNamedIndividual indD = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "d")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indA);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(classA, indB);
OWLIndividualAxiom fact3 = factory.getOWLClassAssertionAxiom(classA, indC);
OWLIndividualAxiom fact4 = factory.getOWLClassAssertionAxiom(classA, indD);
OWLObjectMinCardinality exprRmin5B = factory.getOWLObjectMinCardinality(5, roleR, classB);
OWLSubClassOfAxiom axmAsubRsomeB = factory.getOWLSubClassOfAxiom(classA, exprRmin5B);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
manager.addAxiom(ontology, fact3);
manager.addAxiom(ontology, fact4);
manager.addAxiom(ontology, axmAsubRsomeB);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例11: testRemovingXY
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的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();
}
}
示例12: testChangesToOtherOntologies
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的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();
}
}
示例13: retainAxiomsInPropertySubset
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
* given an ontology *ont* and a set of object properties *filterProps*, remove all axioms from ontology that
* have an object property P in their signature where P is not in *filterProps*
*
* @param ont
* @param filterProps
* @param reasoner
*/
public static void retainAxiomsInPropertySubset(OWLOntology ont, Set<OWLObjectProperty> filterProps, OWLReasoner reasoner) {
LOG.info("Removing axioms that use properties not in set: "+filterProps);
Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
OWLDataFactory df = ont.getOWLOntologyManager().getOWLDataFactory();
for (OWLAxiom ax : ont.getAxioms()) {
Set<OWLObjectProperty> ps = ax.getObjectPropertiesInSignature();
ps.removeAll(filterProps);
if (ps.size() > 0) {
rmAxioms.add(ax);
// if p not-in SubSet, and
// A = X SubClassOf p Some Y,
// then rewrite as
// A = X SubClassOf p' some Y, where p' SubPropertyOf p
// rewrite as weaker axioms.
// TOOD - Elk does not support superobjectprops - do in wrapper for now?
if (ax instanceof OWLSubClassOfAxiom) {
OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom)ax;
if (!sca.getSubClass().isAnonymous()) {
if (sca.getSuperClass() instanceof OWLObjectSomeValuesFrom) {
OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) sca.getSuperClass();
OWLObjectPropertyExpression p = svf.getProperty();
Set<OWLObjectPropertyExpression> sps =
getSuperObjectProperties(p, reasoner, ont);
sps.retainAll(filterProps);
for (OWLObjectPropertyExpression sp : sps) {
OWLObjectSomeValuesFrom newSvf = df.getOWLObjectSomeValuesFrom(sp, svf.getFiller());
OWLSubClassOfAxiom newSca = df.getOWLSubClassOfAxiom(sca.getSubClass(), newSvf);
LOG.info("REWRITE: "+sca+" --> "+newSca);
newAxioms.add(newSca);
}
}
}
}
//else if (ax instanceof OWLEquivalentClassesAxiom) {
// ((OWLEquivalentClassesAxiom)ax).getClassExpressions();
//}
}
}
LOG.info("Removing "+rmAxioms.size()+" axioms");
ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms);
LOG.info("Adding "+newAxioms.size()+" axioms");
ont.getOWLOntologyManager().addAxioms(ont, newAxioms);
}
示例14: splitSubClassAxioms
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
* Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax
* {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf},
* into multiple {@code OWLSubClassOfAxiom}s, using a <a
* href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'>
* SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose
* superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an
* {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with
* an {@code OWLObjectSomeValuesFrom} as superclass, with the same
* {@code OWLPropertyExpression}, and individual operands as filler.
* <p>
* Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in
* {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s.
* But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed
* them into {@code OWLSubClassOfAxiom}s. It must be called before this method.
*
* @see #performDefaultModifications()
* @see #convertEquivalentClassesToSuperClasses()
*/
private void splitSubClassAxioms() {
log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf");
//first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf
SplitSubClassAxioms split = new SplitSubClassAxioms(
this.getOwlGraphWrapper().getAllOntologies(),
this.getOwlGraphWrapper().getDataFactory());
this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges());
this.triggerWrapperUpdate();
//some ontologies use an OWLObjectIntersectionOf as the filler of
//an OWLObjectSomeValuesFrom class expression. We go only one level down
//(i.e., we would not translate another OWLObjectSomeValuesFrom part of the
//OWLObjectIntersectionOf)
OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory();
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
OWLClassExpression superClsExpr = ax.getSuperClass();
if (superClsExpr instanceof OWLObjectSomeValuesFrom) {
OWLObjectSomeValuesFrom someValuesFrom =
(OWLObjectSomeValuesFrom) superClsExpr;
if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) {
//remove original axiom
changes.add(new RemoveAxiom(ont, ax));
OWLObjectIntersectionOf filler =
(OWLObjectIntersectionOf) someValuesFrom.getFiller();
for (OWLClassExpression op : filler.getOperands()) {
//we accept only OWLClasses, otherwise we would need to compose
//OWLObjectPropertyExpressions
if (op instanceof OWLClass) {
OWLAxiom replAx = dataFactory.
getOWLSubClassOfAxiom(ax.getSubClass(),
dataFactory.getOWLObjectSomeValuesFrom(
someValuesFrom.getProperty(), op));
changes.add(new AddAxiom(ont, replAx));
}
}
}
}
}
}
this.getOwlGraphWrapper().getManager().applyChanges(changes);
this.triggerWrapperUpdate();
log.info("OWLObjectIntersectionOf relaxation done.");
}
示例15: testOWLOntologyChangeHashCode
import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
* Test that two {@code OWLClass}es that are equal have a same hashcode,
* because the OWLGraphEdge bug get me paranoid.
*/
@Test
public void testOWLOntologyChangeHashCode()
{
OWLOntology ont = this.graphManipulator.getOwlGraphWrapper().getSourceOntology();
OWLDataFactory factory = this.graphManipulator.getOwlGraphWrapper().
getManager().getOWLDataFactory();
OWLClass source =
this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0005");
OWLClass target =
this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001");
OWLGraphEdge checkEdge = new OWLGraphEdge(source, target, ont);
OWLAxiom axiom = factory.getOWLSubClassOfAxiom(source,
(OWLClassExpression) this.graphManipulator.getOwlGraphWrapper().
edgeToTargetExpression(checkEdge));
OWLAxiomChange rm1 = new RemoveAxiom(ont, axiom);
OWLGraphEdge checkEdge2 = new OWLGraphEdge(source, target, ont);
OWLAxiom axiom2 = factory.getOWLSubClassOfAxiom(source,
(OWLClassExpression) this.graphManipulator.getOwlGraphWrapper().
edgeToTargetExpression(checkEdge2));
OWLAxiomChange rm2 = new RemoveAxiom(ont, axiom2);
assertTrue("The two OWLAxiomChange objects are equal",
rm1.equals(rm2));
//then of course the hashcodes will be the same...
assertTrue("Two OWLAxiomChange are equal but have different hashcode",
rm1.equals(rm2) && rm1.hashCode() == rm2.hashCode());
source =
this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0014");
target =
this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001");
checkEdge = new OWLGraphEdge(source, target, ont);
axiom = factory.getOWLSubClassOfAxiom(source,
(OWLClassExpression) this.graphManipulator.getOwlGraphWrapper().
edgeToTargetExpression(checkEdge));
OWLAxiomChange rm3 = new RemoveAxiom(ont, axiom);
assertFalse("Different OWLAxiomChange objects are equal",
rm1.equals(rm3));
//then of course the hashcodes will be the same...
assertFalse("Different OWLAxiomChanges have same hashcode",
rm1.hashCode() == rm3.hashCode());
}