use of org.semanticweb.owlapi.model.OWLClass 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.OWLClass in project stanbol by apache.
the class OWLAPIToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the OWL ontology for the test. Simply add the axioms: AndreaNuzzolese isA Person -> class
* assertion axiom EnricoDaga isA Person -> class assertion axiom AndreaNuzzolese knows EnricoDaga ->
* object property assertion axiom
*/
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
try {
ontology = manager.createOntology(org.semanticweb.owlapi.model.IRI.create(ns + "testOntology"));
} catch (OWLOntologyCreationException e) {
log.error(e.getMessage());
}
if (ontology != null) {
OWLClass personClass = factory.getOWLClass(org.semanticweb.owlapi.model.IRI.create(foaf + "Person"));
OWLNamedIndividual andreaNuzzoleseOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "AndreaNuzzolese"));
OWLNamedIndividual enricoDagaOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "EnricoDaga"));
OWLObjectProperty knowsOWL = factory.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(foaf + "knows"));
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(personClass, andreaNuzzoleseOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(personClass, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(knowsOWL, andreaNuzzoleseOWL, enricoDagaOWL);
manager.addAxiom(ontology, axiom);
}
/*
* Set-up the Clerezza model for the test. As before simply add the triples: AndreaNuzzolese isA
* Person EnricoDaga isA Person AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class JenaToOwlConvert method EntityOwlToJenaResource.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts any thingths relatives to an OWL entity in an iterator over Jena statement
*
* @param entity
* {It could be a class, an object property or a data property}
* @param owlmodel
* {OWLOntology model where to retrieve information about the entity}
* @param format
* {RDF/XML or TURTLE}
* @return {An iterator over jena statement}
*/
public synchronized StmtIterator EntityOwlToJenaResource(OWLEntity entity, OWLOntology owlmodel, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("EntityOwlToJenaResource::: " + e);
}
}
available = false;
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
// If the entity is a class
if (entity.isOWLClass()) {
OWLClass owldata = entity.asOWLClass();
Iterator<OWLClassAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
// If the entity is a data property
if (entity.isOWLDataProperty()) {
OWLDataProperty owldata = entity.asOWLDataProperty();
Iterator<OWLDataPropertyAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
// If the entity is an object property
if (entity.isOWLObjectProperty()) {
OWLObjectProperty owldata = entity.asOWLObjectProperty();
Iterator<OWLObjectPropertyAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
// If the entity is a data type
if (entity.isOWLDatatype()) {
OWLDatatype owldata = entity.asOWLDatatype();
Iterator<OWLDatatypeDefinitionAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
// If the entity is an individual
if (entity.isOWLNamedIndividual()) {
OWLNamedIndividual owldata = entity.asOWLNamedIndividual();
Iterator<OWLIndividualAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
// If the entity is an annotations property
if (entity.isOWLAnnotationProperty()) {
OWLAnnotationProperty owldata = entity.asOWLAnnotationProperty();
Iterator<OWLAnnotationAxiom> entityaxiom = owlmodel.getAxioms(owldata).iterator();
while (entityaxiom.hasNext()) manager.addAxiom(ontology, entityaxiom.next());
Iterator<OWLAnnotationAssertionAxiom> annotations = entity.getAnnotationAssertionAxioms(owlmodel).iterator();
while (annotations.hasNext()) manager.addAxiom(ontology, annotations.next());
}
OntModel ontmodel = ModelOwlToJenaConvert(ontology, format);
StmtIterator statement = ontmodel.listStatements();
available = true;
notifyAll();
return statement;
} catch (OWLOntologyCreationException eoc) {
System.err.print("EntityOwlToJenaResource::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class TestOntologySpaces method setup.
@BeforeClass
public static void setup() throws Exception {
factory = onManager.getOntologySpaceFactory();
if (factory == null)
fail("Could not instantiate ontology space factory");
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
OWLDataFactory df = mgr.getOWLDataFactory();
ont = mgr.createOntology(baseIri);
inMemorySrc = new RootOntologySource(ont);
// Let's state that Linus is a human being
OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
mgr.applyChange(new AddAxiom(ont, linusIsHuman));
ont2 = mgr.createOntology(baseIri2);
minorSrc = new RootOntologySource(ont2);
dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
minorSrc = new RootOntologySource(ont2);
}
use of org.semanticweb.owlapi.model.OWLClass in project stanbol by apache.
the class RuleListWriter method writeTo.
@Override
public void writeTo(RuleList ruleList, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType mediaType, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
Logger log = LoggerFactory.getLogger(getClass());
log.debug("Rendering the list of recipes.");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntology ontology;
try {
ontology = manager.createOntology();
String recipeClassURI = Symbols.Recipe.toString().replace("<", "").replace(">", "");
IRI recipeClassIRI = IRI.create(recipeClassURI);
OWLClass owlRecipeClass = factory.getOWLClass(recipeClassIRI);
String ruleClassURI = Symbols.Rule.toString().replace("<", "").replace(">", "");
IRI ruleClassIRI = IRI.create(ruleClassURI);
OWLClass owlRuleClass = factory.getOWLClass(ruleClassIRI);
String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
IRI descriptionIRI = IRI.create(descriptionURI);
OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
String hasRuleURI = Symbols.hasRule.toString().replace("<", "").replace(">", "");
IRI hasRuleIRI = IRI.create(hasRuleURI);
OWLObjectProperty hasRule = factory.getOWLObjectProperty(hasRuleIRI);
String ruleBodyURI = Symbols.ruleBody.toString().replace("<", "").replace(">", "");
IRI ruleBodyIRI = IRI.create(ruleBodyURI);
OWLDataProperty ruleBody = factory.getOWLDataProperty(ruleBodyIRI);
String ruleHeadURI = Symbols.ruleHead.toString().replace("<", "").replace(">", "");
IRI ruleHeadIRI = IRI.create(ruleHeadURI);
OWLDataProperty ruleHead = factory.getOWLDataProperty(ruleHeadIRI);
if (ruleList != null) {
for (Rule rule : ruleList) {
String recipeId = rule.getRecipe().getRecipeID().toString().replace("<", "").replace(">", "");
IRI reicpeIRI = IRI.create(recipeId);
OWLIndividual owlRecipe = factory.getOWLNamedIndividual(reicpeIRI);
String ruleId = rule.getRuleID().toString().replace("<", "").replace(">", "");
IRI ruleIRI = IRI.create(ruleId);
OWLIndividual owlRule = factory.getOWLNamedIndividual(ruleIRI);
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(owlRecipeClass, owlRecipe);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(owlRuleClass, owlRule);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(hasRule, owlRecipe, owlRule);
manager.addAxiom(ontology, axiom);
String recipeDescription = rule.getRecipe().getRecipeDescription();
String ruleDescription = rule.getDescription();
if (recipeDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRecipe, recipeDescription);
manager.addAxiom(ontology, axiom);
}
if (ruleDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRule, ruleDescription);
manager.addAxiom(ontology, axiom);
}
String ruleContent = rule.toString();
String[] parts = ruleContent.split("\\->");
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleBody, owlRule, parts[0]);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleHead, owlRule, parts[1]);
manager.addAxiom(ontology, axiom);
}
}
if (mediaType.toString().equals(KRFormat.RDF_XML)) {
try {
manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.OWL_XML)) {
try {
manager.saveOntology(ontology, new OWLXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.MANCHESTER_OWL)) {
try {
manager.saveOntology(ontology, new ManchesterOWLSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.FUNCTIONAL_OWL)) {
try {
manager.saveOntology(ontology, new OWLFunctionalSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.TURTLE)) {
try {
manager.saveOntology(ontology, new TurtleOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.RDF_JSON)) {
Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
RdfJsonSerializingProvider provider = new RdfJsonSerializingProvider();
provider.serialize(out, mGraph, SupportedFormat.RDF_JSON);
}
} catch (OWLOntologyCreationException e1) {
log.error("An error occurred.", e1);
}
out.flush();
}
Aggregations