Search in sources :

Example 11 with OntModel

use of com.hp.hpl.jena.ontology.OntModel 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);
    }
}
Also used : OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) ObjectProperty(com.hp.hpl.jena.ontology.ObjectProperty) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OntClass(com.hp.hpl.jena.ontology.OntClass) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty)

Example 12 with OntModel

use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.

the class JenaToOwlConvert method DataPropOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLDataProperty of OWL to DatatypeProperty of Jena
     * 
     * @param data
     *            {An OWLDataProperty object}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {A DatatypeProperty object}
     */
public synchronized DatatypeProperty DataPropOwlToJena(OWLDataProperty data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("DataPropOwlToJena::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        OWLDataFactory factory = manager.getOWLDataFactory();
        OWLDeclarationAxiom declarationAxiom = factory.getOWLDeclarationAxiom(data);
        manager.addAxiom(ontology, declarationAxiom);
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.getDatatypeProperty(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("DataPropOwlToJena::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 13 with OntModel

use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.

the class JenaToOwlConvert method AnnotationPropJenaToOwl.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single AnnotationProperty of Jena to an OWLAnnotationProperty of OWL
     * 
     * @param jenadata
     *            {Jena DatatypeProperty object}
     * @param format
     *            {RDF/XML}
     * @return {An OWLAnnotationProperty object}
     */
public synchronized OWLAnnotationProperty AnnotationPropJenaToOwl(AnnotationProperty jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("AnnotationPropJenaToOwl::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        model.createAnnotationProperty(jenadata.getURI());
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getAnnotationPropertiesInSignature().iterator().next();
    } catch (Exception e) {
        System.err.print("AnnotationPropJenaToOwl::: ");
        e.printStackTrace();
        return null;
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 14 with OntModel

use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.

the class JenaToOwlConvert method ClassOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLClass of OWLAPI to an OntClass of Jena
     * 
     * @param data
     *            {An OWLClass}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An OntClass}
     */
public synchronized OntClass ClassOwlToJena(OWLClass data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ClassOwlToJena::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        OWLDataFactory factory = manager.getOWLDataFactory();
        OWLDeclarationAxiom declarationAxiom = factory.getOWLDeclarationAxiom(data);
        manager.addAxiom(ontology, declarationAxiom);
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.getOntClass(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("ClassOwlToJena::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 15 with OntModel

use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.

the class JenaToOwlConvert method DataPropJenaToOwl.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a DatatypeProperty of Jena to and OWLDataProperty of owl
     * 
     * @param jenadata
     *            {Jena DatatypeProperty object}
     * @param format
     *            {RDF/XML}
     * @return {An OWLDataProperty}
     */
public synchronized OWLDataProperty DataPropJenaToOwl(DatatypeProperty jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("DataPropJenaToOwl::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        model.createDatatypeProperty(jenadata.getURI());
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getDataPropertiesInSignature().iterator().next();
    } catch (Exception e) {
        System.err.print("DataPropJenaToOwl::: ");
        e.printStackTrace();
        return null;
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

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