Search in sources :

Example 21 with OntModel

use of com.hp.hpl.jena.ontology.OntModel 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;
    }
}
Also used : OWLDatatype(org.semanticweb.owlapi.model.OWLDatatype) OWLClassAxiom(org.semanticweb.owlapi.model.OWLClassAxiom) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) OWLIndividualAxiom(org.semanticweb.owlapi.model.OWLIndividualAxiom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLObjectPropertyAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAxiom) OWLDatatypeDefinitionAxiom(org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom) OWLDataPropertyAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAxiom) OWLAnnotationAxiom(org.semanticweb.owlapi.model.OWLAnnotationAxiom) OWLClass(org.semanticweb.owlapi.model.OWLClass)

Aggregations

OntModel (com.hp.hpl.jena.ontology.OntModel)21 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)20 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)15 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)9 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)6 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)6 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)5 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)5 DatatypeProperty (com.hp.hpl.jena.ontology.DatatypeProperty)4 ObjectProperty (com.hp.hpl.jena.ontology.ObjectProperty)4 OntClass (com.hp.hpl.jena.ontology.OntClass)4 Statement (com.hp.hpl.jena.rdf.model.Statement)4 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)4 OWLClass (org.semanticweb.owlapi.model.OWLClass)4 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)4 OWLDeclarationAxiom (org.semanticweb.owlapi.model.OWLDeclarationAxiom)4 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)3 AnnotationProperty (com.hp.hpl.jena.ontology.AnnotationProperty)2 Resource (com.hp.hpl.jena.rdf.model.Resource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2