Search in sources :

Example 6 with OWLObjectPropertyAssertionAxiom

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

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

the class RegistryUtils method getType.

@Deprecated
public static Type getType(final OWLIndividual ind, Set<OWLOntology> ontologies) {
    // 0 is for library, 1 is for ontology (more in the future?)
    final int[] pointsFor = new int[] { 0, 0 };
    final int[] pointsAgainst = new int[] { 0, 0 };
    OWLAxiomVisitor v = new OWLAxiomVisitorAdapter() {

        @Override
        public void visit(OWLClassAssertionAxiom axiom) {
            if (ind.equals(axiom.getIndividual())) {
                OWLClassExpression type = axiom.getClassExpression();
                if (cRegistryLibrary.equals(type)) {
                    pointsFor[0]++;
                    pointsAgainst[1]++;
                } else if (cOntology.equals(type)) {
                    pointsFor[1]++;
                    pointsAgainst[0]++;
                }
            }
        }

        @Override
        public void visit(OWLObjectPropertyAssertionAxiom axiom) {
            OWLObjectPropertyExpression prop = axiom.getProperty();
            if (ind.equals(axiom.getSubject())) {
                if (hasOntology.equals(prop)) {
                    pointsFor[0]++;
                    pointsAgainst[1]++;
                } else if (isOntologyOf.equals(prop)) {
                    pointsFor[1]++;
                    pointsAgainst[0]++;
                }
            } else if (ind.equals(axiom.getObject())) {
                if (isOntologyOf.equals(prop)) {
                    pointsFor[0]++;
                    pointsAgainst[1]++;
                } else if (hasOntology.equals(prop)) {
                    pointsFor[1]++;
                    pointsAgainst[0]++;
                }
            }
        }
    };
    // TODO use this strategy in the single pass algorithm for constructing the model.
    for (OWLOntology o : ontologies) for (OWLAxiom ax : o.getAxioms()) ax.accept(v);
    if (pointsFor[0] > 0 && pointsAgainst[0] == 0)
        return Type.LIBRARY;
    if (pointsFor[1] > 0 && pointsAgainst[1] == 0)
        return Type.ONTOLOGY;
    // Cannot determine registries, since they have no associated individual.
    return null;
}
Also used : OWLAxiomVisitor(org.semanticweb.owlapi.model.OWLAxiomVisitor) OWLObjectPropertyExpression(org.semanticweb.owlapi.model.OWLObjectPropertyExpression) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) OWLAxiomVisitorAdapter(org.semanticweb.owlapi.util.OWLAxiomVisitorAdapter)

Aggregations

OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)7 OWLObjectPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom)7 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)6 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)6 OWLClass (org.semanticweb.owlapi.model.OWLClass)5 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)5 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)5 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)5 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)5 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)5 IRI (org.semanticweb.owlapi.model.IRI)4 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)4 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)3 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)3 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)3 Statement (com.hp.hpl.jena.rdf.model.Statement)2 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)2 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)2 OWLAxiomVisitor (org.semanticweb.owlapi.model.OWLAxiomVisitor)2 OWLClassExpression (org.semanticweb.owlapi.model.OWLClassExpression)2