use of org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom 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.OWLObjectPropertyAssertionAxiom 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;
}
Aggregations