use of org.semanticweb.owlapi.model.OWLNamedIndividual 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.OWLNamedIndividual 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.OWLNamedIndividual in project stanbol by apache.
the class OntologyNetworkConfigurationUtils method getScopeObjectPropertyValues.
/**
* Utility method to get all the values of an object property of a Scope
*
* @param ontology
* @param individualIRI
* @param op
* @return
*/
private static String[] getScopeObjectPropertyValues(OWLOntology ontology, String individualIRI, OWLObjectProperty op) {
Set<OWLIndividual> scopes = cScope.getIndividuals(ontology);
List<String> result = new ArrayList<String>();
OWLIndividual iiScope = null;
// Optimised loop.
for (OWLIndividual ind : scopes) {
if (ind.isAnonymous())
continue;
if (((OWLNamedIndividual) ind).getIRI().toString().equals(individualIRI)) {
iiScope = ind;
break;
}
}
if (iiScope != null) {
}
for (OWLIndividual iScope : scopes) {
if (iScope.isNamed()) {
if (((OWLNamedIndividual) iScope).getIRI().toString().equals(individualIRI)) {
Set<OWLIndividual> values = iScope.getObjectPropertyValues(op, ontology);
Iterator<OWLIndividual> it = values.iterator();
while (it.hasNext()) {
OWLIndividual i = it.next();
if (i.isNamed())
result.add(((OWLNamedIndividual) i).getIRI().toString());
}
}
}
}
return result.toArray(EMPTY_IRI_ARRAY);
}
use of org.semanticweb.owlapi.model.OWLNamedIndividual in project stanbol by apache.
the class OntologyNetworkConfigurationUtils method getLibraryObjectPropertyValues.
/**
* Utility method to get all the values of a property from a Library subject
*
* @param ontology
* @param individualIRI
* @param op
* @return
*/
private static String[] getLibraryObjectPropertyValues(OWLOntology ontology, String individualIRI, OWLObjectProperty op) {
Set<OWLIndividual> scopes = cLibrary.getIndividuals(ontology);
List<String> result = new ArrayList<String>();
for (OWLIndividual iLibrary : scopes) {
if (iLibrary.isNamed()) {
if (((OWLNamedIndividual) iLibrary).getIRI().toString().equals(individualIRI)) {
Set<OWLIndividual> values = iLibrary.getObjectPropertyValues(op, ontology);
Iterator<OWLIndividual> it = values.iterator();
while (it.hasNext()) {
OWLIndividual i = it.next();
if (i.isNamed())
result.add(((OWLNamedIndividual) iLibrary).getIRI().toString());
}
}
}
}
return result.toArray(EMPTY_IRI_ARRAY);
}
use of org.semanticweb.owlapi.model.OWLNamedIndividual in project stanbol by apache.
the class ScopeSetRenderer method getScopes.
public static OWLOntology getScopes(Set<Scope> scopes) {
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntology ont = null;
try {
ont = mgr.createOntology();
} catch (OWLOntologyCreationException e) {
LoggerFactory.getLogger(ScopeSetRenderer.class).error("KReS :: could not create empty ontology for rendering scopes.", e);
return null;
}
List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
// The ODP metadata vocabulary is always imported.
// TODO : also import the ONM meta when it goes online.
additions.add(new AddImport(ont, __factory.getOWLImportsDeclaration(IRI.create("http://www.ontologydesignpatterns.org/schemas/meta.owl"))));
for (Scope scope : scopes) {
OWLNamedIndividual iScope = __factory.getOWLNamedIndividual(IRI.create(scope.getDefaultNamespace() + scope.getID()));
OWLAxiom ax = __factory.getOWLClassAssertionAxiom(cScope, iScope);
additions.add(new AddAxiom(ont, ax));
}
mgr.applyChanges(additions);
return ont;
}
Aggregations