Search in sources :

Example 11 with OWLAnnotationProperty

use of org.semanticweb.owlapi.model.OWLAnnotationProperty in project stanbol by apache.

the class ConversionTester method testAnnotationPropOwlToJena.

public void testAnnotationPropOwlToJena() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = mgr.getOWLDataFactory();
    OWLAnnotationProperty wp = factory.getOWLAnnotationProperty(IRI.create(label));
    AnnotationProperty jp = null;
    try {
        jp = j2o.AnnotationPropOwlToJena(wp, RDFXML);
        if (jp == null) {
            fail("Some errors occur");
        } else {
            assertEquals(wp.getIRI().toURI().toString(), jp.getURI());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(jp);
    }
}
Also used : OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) AnnotationProperty(com.hp.hpl.jena.ontology.AnnotationProperty) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException)

Example 12 with OWLAnnotationProperty

use of org.semanticweb.owlapi.model.OWLAnnotationProperty 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

OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)12 OWLClass (org.semanticweb.owlapi.model.OWLClass)8 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)7 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)7 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)7 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)6 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)6 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)6 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)6 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)6 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)6 IRI (org.semanticweb.owlapi.model.IRI)5 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)5 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)5 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)5 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)5 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)3 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)3 OWLDatatype (org.semanticweb.owlapi.model.OWLDatatype)3 AnnotationProperty (com.hp.hpl.jena.ontology.AnnotationProperty)2