Search in sources :

Example 1 with OWLObjectPropertyAxiom

use of org.semanticweb.owlapi.model.OWLObjectPropertyAxiom in project opentheso by miledrousset.

the class OwlApiTest_collection method printAxioms.

private static void printAxioms(Set<OWLAxiom> axioms) {
    Set<OWLAxiom> axIndividual = new HashSet<OWLAxiom>();
    Set<OWLAxiom> axDataProperty = new HashSet<OWLAxiom>();
    Set<OWLAxiom> axObjectProperty = new HashSet<OWLAxiom>();
    Set<OWLAxiom> axClass = new HashSet<OWLAxiom>();
    Set<OWLAxiom> axOther = new HashSet<OWLAxiom>();
    for (OWLAxiom a : axioms) {
        a.getSignature();
        if ((a instanceof OWLClassAxiom)) {
            axClass.add(a);
        } else if (a instanceof OWLDataPropertyAxiom) {
            axDataProperty.add(a);
        } else if (a instanceof OWLObjectPropertyAxiom) {
            axDataProperty.add(a);
        } else if (a instanceof OWLIndividualAxiom) {
            axIndividual.add(a);
        } else {
            axOther.add(a);
        }
    }
    System.out.println("ALL AXIOMS (" + axioms.size() + ")");
    for (OWLAxiom ax : axIndividual) {
        String line1;
        line1 = ax.toString() + " TYPE: Individual";
        if (line1.contains("Collection")) {
            System.out.println(line1);
            for (OWLAxiom ax2 : axOther) {
                String line2;
                line2 = ax2.toString() + " TYPE: collection";
                System.out.println(line2);
            }
            for (OWLAxiom ax1 : axDataProperty) {
                String line;
                line = ax1.toString() + " TYPE: DataProperty";
                System.out.println(line);
            }
            for (OWLAxiom ax2 : axObjectProperty) {
                String line;
                line = ax2.toString() + " TYPE: ObjectProperty";
                System.out.println(line);
            }
            for (OWLAxiom ax3 : axClass) {
                String line;
                line = ax3.toString() + " TYPE: Class";
                System.out.println(line);
            }
            for (OWLAxiom ax4 : axOther) {
                String line;
                line = ax4.toString() + " TYPE: Other";
                System.out.println(line);
            }
        }
    /*    else
            {
                System.out.println(line1);
                for (OWLAxiom ax2 : axOther) {
                    String line2;
                    line2 = ax2.toString() + " TYPE: Other";
                    System.out.println(line2);
                } 
                for (OWLAxiom ax1 : axDataProperty) {
                String line;
                line = ax1.toString() + " TYPE: DataProperty";
                System.out.println(line);
                }
                for (OWLAxiom ax2 : axObjectProperty) {
                    String line;
                    line = ax2.toString() + " TYPE: ObjectProperty";
                    System.out.println(line);
                }
                for (OWLAxiom ax3 : axClass) {
                    String line;
                    line = ax3.toString() + " TYPE: Class";
                    System.out.println(line);
                }
                for (OWLAxiom ax4 : axOther) {
                    String line;
                    line = ax4.toString() + " TYPE: Other";
                    System.out.println(line);
                }                
            }*/
    }
    for (OWLAxiom ax : axDataProperty) {
        String line;
        line = ax.toString() + " TYPE: DataProperty";
        System.out.println(line);
    }
    for (OWLAxiom ax : axObjectProperty) {
        String line;
        line = ax.toString() + " TYPE: ObjectProperty";
        System.out.println(line);
    }
    for (OWLAxiom ax : axClass) {
        String line;
        line = ax.toString() + " TYPE: Class";
        System.out.println(line);
    }
    for (OWLAxiom ax : axOther) {
        String line;
        line = ax.toString() + " TYPE: Other";
        System.out.println(line);
    }
    System.out.println("-----------------------------------");
}
Also used : OWLObjectPropertyAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAxiom) OWLDataPropertyAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAxiom) OWLIndividualAxiom(org.semanticweb.owlapi.model.OWLIndividualAxiom) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAxiom(org.semanticweb.owlapi.model.OWLClassAxiom) HashSet(java.util.HashSet)

Example 2 with OWLObjectPropertyAxiom

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

OWLClassAxiom (org.semanticweb.owlapi.model.OWLClassAxiom)2 OWLDataPropertyAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAxiom)2 OWLIndividualAxiom (org.semanticweb.owlapi.model.OWLIndividualAxiom)2 OWLObjectPropertyAxiom (org.semanticweb.owlapi.model.OWLObjectPropertyAxiom)2 OntModel (com.hp.hpl.jena.ontology.OntModel)1 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)1 HashSet (java.util.HashSet)1 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)1 OWLAnnotationAxiom (org.semanticweb.owlapi.model.OWLAnnotationAxiom)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLClass (org.semanticweb.owlapi.model.OWLClass)1 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)1 OWLDatatype (org.semanticweb.owlapi.model.OWLDatatype)1 OWLDatatypeDefinitionAxiom (org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom)1 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)1 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1