use of org.semanticweb.owlapi.model.OWLDataProperty in project stanbol by apache.
the class ConversionTester method testDataPropOwlToJena.
public void testDataPropOwlToJena() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = mgr.getOWLDataFactory();
OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
DatatypeProperty jdp = null;
try {
jdp = j2o.DataPropOwlToJena(dp, RDFXML);
if (jdp == null) {
fail("Some errors accour");
} else {
assertEquals(jdp.getURI(), dp.getIRI().toString());
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caught");
} finally {
assertNotNull(jdp);
}
}
use of org.semanticweb.owlapi.model.OWLDataProperty 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.OWLDataProperty in project stanbol by apache.
the class ConversionTester method testModelOwlToJenaConvert.
public void testModelOwlToJenaConvert() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntologyManager mgrf = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = mgrf.getOWLDataFactory();
String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
OWLOntology owl = null;
OntModel jena = null;
try {
owl = mgr.loadOntologyFromOntologyDocument(IRI.create(dul));
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Could not load ontology");
}
try {
jena = j2o.ModelOwlToJenaConvert(owl, "RDF/XML");
if (jena == null) {
fail("Some errors occur");
} else {
ExtendedIterator<OntClass> jenaclass = jena.listNamedClasses();
int jenaclassset = jenaclass.toSet().size();
jenaclass = jena.listNamedClasses();
Set<OWLClass> owlclass = owl.getClassesInSignature();
int countclass = 0;
while (jenaclass.hasNext()) if (owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI()))))
countclass++;
if (countclass == jenaclassset)
assertEquals(countclass, jenaclassset);
else
fail("Error in number of classes");
ExtendedIterator<ObjectProperty> jenaprop = jena.listObjectProperties();
int jenapropset = jenaprop.toSet().size();
jenaprop = jena.listObjectProperties();
Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
int countprop = 0;
while (jenaprop.hasNext()) if (owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI()))))
countprop++;
if (countprop == jenapropset)
assertEquals(countprop, jenapropset);
else
fail("Error in number of object properties");
ExtendedIterator<DatatypeProperty> jenadata = jena.listDatatypeProperties();
int jenadataset = jenadata.toSet().size();
jenadata = jena.listDatatypeProperties();
Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
int countdata = 0;
while (jenadata.hasNext()) if (owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI()))))
countdata++;
if (countdata == jenadataset)
assertEquals(countdata, jenadataset);
else
fail("Error in number of data properties");
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(jena);
}
}
use of org.semanticweb.owlapi.model.OWLDataProperty in project stanbol by apache.
the class ConversionTester method testDataPropJenaToOwl.
public void testDataPropJenaToOwl() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OntModel model = ModelFactory.createOntologyModel();
DatatypeProperty jp = model.createDatatypeProperty(DP.toString());
OWLDataProperty wp = null;
try {
wp = j2o.DataPropJenaToOwl(jp, RDFXML);
if (wp == null) {
fail("Some problem accours");
} else {
assertEquals(wp.getIRI().toURI().toString(), jp.getURI());
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(wp);
}
}
use of org.semanticweb.owlapi.model.OWLDataProperty in project stanbol by apache.
the class DatavaluedPropertyAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
IObjectAtom argument1 = tmp.getArgument1();
IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
RuleAtom argument2 = tmp.getArgument2();
SWRLAtom arg1Atom = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
SWRLAtom predicateAtom = (SWRLAtom) adapter.adaptTo(datatypeProperty, SWRLRule.class);
SWRLAtom arg2Atom = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLDataProperty owlDataProperty;
SWRLIArgument swrliArgument;
SWRLDArgument swrldArgument;
if (predicateAtom instanceof ArgumentSWRLAtom) {
owlDataProperty = factory.getOWLDataProperty(IRI.create(((ArgumentSWRLAtom) predicateAtom).getId()));
} else {
throw new RuleAtomCallExeption(getClass());
}
if (arg1Atom instanceof ArgumentSWRLAtom) {
swrliArgument = (SWRLIArgument) ((ArgumentSWRLAtom) arg1Atom).getSwrlArgument();
} else {
throw new RuleAtomCallExeption(getClass());
}
if (arg2Atom instanceof ArgumentSWRLAtom) {
swrldArgument = (SWRLDArgument) ((ArgumentSWRLAtom) arg2Atom).getSwrlArgument();
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) factory.getSWRLDataPropertyAtom(owlDataProperty, swrliArgument, swrldArgument);
}
Aggregations