Search in sources :

Example 1 with DatatypeProperty

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

the class ConversionTester method testModelJenaToOwlConvert.

public void testModelJenaToOwlConvert() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = mgr.getOWLDataFactory();
    String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
    OWLOntology owl = null;
    try {
        model.read(dul, RDFXML);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not load ontology");
    }
    try {
        owl = j2o.ModelJenaToOwlConvert(model, RDFXML);
        if (owl == null) {
            fail("Some errors occur");
        } else {
            ExtendedIterator<OntClass> jenaclass = model.listNamedClasses();
            int jenaclassset = jenaclass.toSet().size();
            jenaclass = model.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 = model.listObjectProperties();
            int jenapropset = jenaprop.toSet().size();
            jenaprop = model.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 = model.listDatatypeProperties();
            int jenadataset = jenadata.toSet().size();
            jenadata = model.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(owl);
    }
}
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) 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 2 with DatatypeProperty

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

the class ConversionTester method testDataPropOwlToJena.

public void testDataPropOwlToJena() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = mgr.getOWLDataFactory();
    OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
    DatatypeProperty jdp = null;
    try {
        jdp = j2o.DataPropOwlToJena(dp, RDFXML);
        if (jdp == null) {
            fail("Some errors accour");
        } else {
            assertEquals(jdp.getURI(), dp.getIRI().toString());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caught");
    } finally {
        assertNotNull(jdp);
    }
}
Also used : OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException)

Example 3 with DatatypeProperty

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

the class ConversionTester method testResourceJenaToOwlAxiom.

public void testResourceJenaToOwlAxiom() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    OntClass jenaclass = model.createClass(CLAZZ.toString());
    ObjectProperty jenaobprop = model.createObjectProperty(OP.toString());
    DatatypeProperty jenadataprop = model.createDatatypeProperty(DP.toString());
    Individual jenasub = model.createIndividual(SUBJECT.toString(), jenaclass);
    Individual jenaobj = model.createIndividual(OBJECT.toString(), jenaclass);
    AnnotationProperty jenaanno = model.createAnnotationProperty(label.toString());
    Literal value = model.createTypedLiteral(VALUE, DATATYPE.toString());
    model.add(jenasub, jenaobprop, jenaobj);
    model.add(jenasub, jenadataprop, value);
    model.add(jenasub, jenaanno, "Lucy", "en");
    Set<OWLAxiom> owlaxiom = null;
    try {
        owlaxiom = j2o.ResourceJenaToOwlAxiom(jenasub, RDFXML);
        if (owlaxiom == null) {
            fail("Some errors occur");
        } else {
            StmtIterator str = model.listStatements();
            int count = 0;
            while (str.hasNext()) {
                Statement stm = str.next();
                Resource subject = stm.getSubject();
                if (SUBJECT.toString().equals(subject.getURI()))
                    count++;
            }
            if (count == owlaxiom.size()) {
                assertEquals(count, owlaxiom.size());
            } else {
                fail("The number of axioms don't match the number of statement");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(owlaxiom);
    }
}
Also used : OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) ObjectProperty(com.hp.hpl.jena.ontology.ObjectProperty) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) AnnotationProperty(com.hp.hpl.jena.ontology.AnnotationProperty) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) Individual(com.hp.hpl.jena.ontology.Individual) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) Literal(com.hp.hpl.jena.rdf.model.Literal) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OntClass(com.hp.hpl.jena.ontology.OntClass) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty)

Example 4 with DatatypeProperty

use of com.hp.hpl.jena.ontology.DatatypeProperty 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 5 with DatatypeProperty

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

the class ConversionTester method testDataPropJenaToOwl.

public void testDataPropJenaToOwl() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    DatatypeProperty jp = model.createDatatypeProperty(DP.toString());
    OWLDataProperty wp = null;
    try {
        wp = j2o.DataPropJenaToOwl(jp, RDFXML);
        if (wp == null) {
            fail("Some problem accours");
        } else {
            assertEquals(wp.getIRI().toURI().toString(), jp.getURI());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(wp);
    }
}
Also used : OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OntModel(com.hp.hpl.jena.ontology.OntModel) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException)

Aggregations

DatatypeProperty (com.hp.hpl.jena.ontology.DatatypeProperty)5 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)5 OntModel (com.hp.hpl.jena.ontology.OntModel)4 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)4 ObjectProperty (com.hp.hpl.jena.ontology.ObjectProperty)3 OntClass (com.hp.hpl.jena.ontology.OntClass)3 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)3 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 OWLClass (org.semanticweb.owlapi.model.OWLClass)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 AnnotationProperty (com.hp.hpl.jena.ontology.AnnotationProperty)1 Individual (com.hp.hpl.jena.ontology.Individual)1 Literal (com.hp.hpl.jena.rdf.model.Literal)1 Resource (com.hp.hpl.jena.rdf.model.Resource)1 Statement (com.hp.hpl.jena.rdf.model.Statement)1 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1