use of org.semanticweb.owlapi.model.OWLClassAssertionAxiom in project stanbol by apache.
the class ConversionTester method testEntityOwlToJenaResource.
public void testEntityOwlToJenaResource() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntology ont = null;
StmtIterator resource = null;
try {
ont = mgr.createOntology();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Could not load ontology");
}
OWLDataFactory factory = mgr.getOWLDataFactory();
OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
// Classe
OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
// obj prop
OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
// data prop
OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
// subject
OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
// object
OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
// Istanza
OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
// Istanza
OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
// Obj
OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
// prop
// tra
// individui
OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, sub, // Dataprop all'istanza;
literal1);
// Annotazione
OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
mgr.addAxiom(ont, daxiomcls);
mgr.addAxiom(ont, daxiomop);
mgr.addAxiom(ont, daxiomdp);
mgr.addAxiom(ont, daxiomsub);
mgr.addAxiom(ont, daxiomobj);
mgr.addAxiom(ont, axiomsub);
mgr.addAxiom(ont, axiomobj);
mgr.addAxiom(ont, axiomop);
mgr.addAxiom(ont, axiomvalue);
mgr.addAxiom(ont, axioman);
Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
try {
resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
if (resource == null) {
fail("Some errors accour");
} else {
int cont = 0;
while (resource.hasNext()) {
Statement stm = resource.nextStatement();
IRI subres = IRI.create(stm.getSubject().getURI());
if (("<" + subres + ">").equals(daxiomsub.getEntity().toString()))
cont++;
}
assertEquals(ind.size(), (cont - 1));
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(resource);
}
}
use of org.semanticweb.owlapi.model.OWLClassAssertionAxiom in project stanbol by apache.
the class RegistryUtils method getType.
@Deprecated
public static Type getType(final OWLIndividual ind, Set<OWLOntology> ontologies) {
// 0 is for library, 1 is for ontology (more in the future?)
final int[] pointsFor = new int[] { 0, 0 };
final int[] pointsAgainst = new int[] { 0, 0 };
OWLAxiomVisitor v = new OWLAxiomVisitorAdapter() {
@Override
public void visit(OWLClassAssertionAxiom axiom) {
if (ind.equals(axiom.getIndividual())) {
OWLClassExpression type = axiom.getClassExpression();
if (cRegistryLibrary.equals(type)) {
pointsFor[0]++;
pointsAgainst[1]++;
} else if (cOntology.equals(type)) {
pointsFor[1]++;
pointsAgainst[0]++;
}
}
}
@Override
public void visit(OWLObjectPropertyAssertionAxiom axiom) {
OWLObjectPropertyExpression prop = axiom.getProperty();
if (ind.equals(axiom.getSubject())) {
if (hasOntology.equals(prop)) {
pointsFor[0]++;
pointsAgainst[1]++;
} else if (isOntologyOf.equals(prop)) {
pointsFor[1]++;
pointsAgainst[0]++;
}
} else if (ind.equals(axiom.getObject())) {
if (isOntologyOf.equals(prop)) {
pointsFor[0]++;
pointsAgainst[1]++;
} else if (hasOntology.equals(prop)) {
pointsFor[1]++;
pointsAgainst[0]++;
}
}
}
};
// TODO use this strategy in the single pass algorithm for constructing the model.
for (OWLOntology o : ontologies) for (OWLAxiom ax : o.getAxioms()) ax.accept(v);
if (pointsFor[0] > 0 && pointsAgainst[0] == 0)
return Type.LIBRARY;
if (pointsFor[1] > 0 && pointsAgainst[1] == 0)
return Type.ONTOLOGY;
// Cannot determine registries, since they have no associated individual.
return null;
}
use of org.semanticweb.owlapi.model.OWLClassAssertionAxiom in project stanbol by apache.
the class HermitReasoningServiceTest method testClassifyWithRules.
private void testClassifyWithRules(String testID, String rulesID, String testExpectedID) {
log.info("Testing the task CLASSIFY with rules");
OWLOntologyManager manager = TestData.manager;
// We prepare the input ontology
try {
OWLOntology testOntology = manager.createOntology();
OWLOntologyID testOntologyID = testOntology.getOntologyID();
log.debug("Created test ontology with ID: {}", testOntologyID);
OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
manager.applyChange(new AddImport(testOntology, importTest));
Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
// Maybe we want to see the list of rules
if (log.isDebugEnabled()) {
log.debug("List of {} rules: ", rules.size());
TestUtils.debug(rules, log);
}
log.debug("We add the rules to the ontology");
manager.addAxioms(manager.getOntology(testOntologyID), rules);
// Maybe we want to see what is in before
if (log.isDebugEnabled())
log.debug("Content of the input is:");
TestUtils.debug(manager.getOntology(testOntologyID), log);
// Now we test the method
log.debug("Running HermiT");
Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.CLASSIFY, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
log.debug("{} inferred axioms:", inferred.size());
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
// We consider here only two kind of axioms
if (expected instanceof OWLSubClassOfAxiom || expected instanceof OWLClassAssertionAxiom) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
}
assertTrue(missing.isEmpty());
// We want to remove the ontology from the manager
manager.removeOntology(testOntology);
} catch (OWLOntologyCreationException e) {
log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
assertTrue(false);
} catch (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.OWLClassAssertionAxiom in project stanbol by apache.
the class HermitReasoningServiceTest method testClassify.
/**
* We may want to test this method with more then 1 ontology. This is why the implementation is in
* aprivate method. This method tests if all the logical axioms in testExpectedID ontology are inferences
* of the testID ontology.
*
* @param testID
* // The ID of the ontology to be the input (loaded in the TestData.manager)
* @param testExpectedID
* // The ID of the ontology which contains logical axioms expected in the result
*/
private void testClassify(String testID, String testExpectedID) {
log.info("Testing the CLASSIFY task");
OWLOntologyManager manager = TestData.manager;
// We prepare the input ontology
try {
OWLOntology testOntology = manager.createOntology();
OWLOntologyID testOntologyID = testOntology.getOntologyID();
log.debug("Created test ontology with ID: {}", testOntologyID);
manager.applyChange(new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID))));
// Maybe we want to see what is in before
if (log.isDebugEnabled())
TestUtils.debug(manager.getOntology(testOntologyID), log);
// Now we test the method
log.debug("Running HermiT");
Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.CLASSIFY, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
assertTrue(missing.isEmpty());
// We want only Class related axioms in the result set
for (OWLAxiom a : inferred) {
assertTrue(a instanceof OWLClassAssertionAxiom || a instanceof OWLSubClassOfAxiom || a instanceof OWLEquivalentClassesAxiom || a instanceof OWLDisjointClassesAxiom);
}
// We want to remove the ontology from the manager
manager.removeOntology(testOntology);
} catch (OWLOntologyCreationException e) {
log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
assertTrue(false);
} catch (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
Aggregations