Search in sources :

Example 11 with OWLDataProperty

use of org.semanticweb.owlapi.model.OWLDataProperty 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 12 with OWLDataProperty

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

the class ConversionTester method testEntityOwlToJenaResource.

public void testEntityOwlToJenaResource() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLOntology ont = null;
    StmtIterator resource = null;
    try {
        ont = mgr.createOntology();
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
        fail("Could not load ontology");
    }
    OWLDataFactory factory = mgr.getOWLDataFactory();
    OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
    OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
    OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
    OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
    OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
    OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
    OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
    OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
    OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
    // Classe
    OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
    // obj prop
    OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
    // data prop
    OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
    // subject
    OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
    // object
    OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
    // Istanza
    OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
    // Istanza
    OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
    // Obj
    OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
    // prop
    // tra
    // individui
    OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, sub, // Dataprop all'istanza;
    literal1);
    // Annotazione
    OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
    mgr.addAxiom(ont, daxiomcls);
    mgr.addAxiom(ont, daxiomop);
    mgr.addAxiom(ont, daxiomdp);
    mgr.addAxiom(ont, daxiomsub);
    mgr.addAxiom(ont, daxiomobj);
    mgr.addAxiom(ont, axiomsub);
    mgr.addAxiom(ont, axiomobj);
    mgr.addAxiom(ont, axiomop);
    mgr.addAxiom(ont, axiomvalue);
    mgr.addAxiom(ont, axioman);
    Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
    try {
        resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
        if (resource == null) {
            fail("Some errors accour");
        } else {
            int cont = 0;
            while (resource.hasNext()) {
                Statement stm = resource.nextStatement();
                IRI subres = IRI.create(stm.getSubject().getURI());
                if (("<" + subres + ">").equals(daxiomsub.getEntity().toString()))
                    cont++;
            }
            assertEquals(ind.size(), (cont - 1));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(resource);
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLDatatype(org.semanticweb.owlapi.model.OWLDatatype) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) Statement(com.hp.hpl.jena.rdf.model.Statement) OWLIndividualAxiom(org.semanticweb.owlapi.model.OWLIndividualAxiom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 13 with OWLDataProperty

use of org.semanticweb.owlapi.model.OWLDataProperty 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 14 with OWLDataProperty

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

Example 15 with OWLDataProperty

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

the class DatavaluedPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
    RuleAtom argument2 = tmp.getArgument2();
    SWRLAtom arg1Atom = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom predicateAtom = (SWRLAtom) adapter.adaptTo(datatypeProperty, SWRLRule.class);
    SWRLAtom arg2Atom = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLDataProperty owlDataProperty;
    SWRLIArgument swrliArgument;
    SWRLDArgument swrldArgument;
    if (predicateAtom instanceof ArgumentSWRLAtom) {
        owlDataProperty = factory.getOWLDataProperty(IRI.create(((ArgumentSWRLAtom) predicateAtom).getId()));
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (arg1Atom instanceof ArgumentSWRLAtom) {
        swrliArgument = (SWRLIArgument) ((ArgumentSWRLAtom) arg1Atom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (arg2Atom instanceof ArgumentSWRLAtom) {
        swrldArgument = (SWRLDArgument) ((ArgumentSWRLAtom) arg2Atom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) factory.getSWRLDataPropertyAtom(owlDataProperty, swrliArgument, swrldArgument);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLIArgument(org.semanticweb.owlapi.model.SWRLIArgument) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Aggregations

OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)15 OWLClass (org.semanticweb.owlapi.model.OWLClass)10 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)10 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)10 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)9 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)9 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)8 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)6 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)6 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)6 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)6 IRI (org.semanticweb.owlapi.model.IRI)5 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)5 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)5 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)5 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)5 DatatypeProperty (com.hp.hpl.jena.ontology.DatatypeProperty)4 OntModel (com.hp.hpl.jena.ontology.OntModel)4 OWLDatatype (org.semanticweb.owlapi.model.OWLDatatype)4 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)3