Search in sources :

Example 1 with OntModel

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

the class JenaToOwlConvert method ClassJenaToOwl.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OntClass of Jena to an OWLClass of OWLAPI
     * 
     * @param jenadata
     *            {Jena class object}
     * @param format
     *            {RDF/XML}
     * @return {An OWLclass}
     */
public synchronized OWLClass ClassJenaToOwl(OntClass jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ClassJenaToOwl::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        model.createClass(jenadata.getURI());
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getClassesInSignature().iterator().next();
    } catch (Exception e) {
        System.err.print("ClassJenaToOwl::: ");
        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 2 with OntModel

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

the class JenaToOwlConvert method ResourceJenaToOwlAxiom.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts every statments relative to a resource in an a set of OWLAxiom objects
     * 
     * @param jenadata
     *            {A resource in the form (S,P,O), it could be any kind of resource (a class, a data property,
     *            an object property and an instance) except a litteral}
     * @param format
     *            {The format of the ontology, i.e. "RDF/XML"}
     * @return {A set of axiom in the form of Set<OWLAxiom>}
     */
public synchronized Set<OWLAxiom> ResourceJenaToOwlAxiom(Resource jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ResourceJenaToOwlAxiom::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        StmtIterator prop = jenadata.listProperties();
        while (prop.hasNext()) {
            Statement stat = prop.nextStatement();
            model.add(stat);
            RDFNode obj = stat.getObject();
            if (obj.isResource()) {
                if (!obj.isURIResource()) {
                    StmtIterator aux = ((Resource) obj).listProperties();
                    while (aux.hasNext()) {
                        Statement stataux = aux.nextStatement();
                        model.add(stataux);
                    }
                }
            }
        }
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getAxioms();
    } catch (Exception e) {
        System.err.print("ResourceJenaToOwlAxiom::: ");
        e.printStackTrace();
        return null;
    }
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) Statement(com.hp.hpl.jena.rdf.model.Statement) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Resource(com.hp.hpl.jena.rdf.model.Resource) OntModel(com.hp.hpl.jena.ontology.OntModel) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 3 with OntModel

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

the class JenaToOwlConvert method AxiomOwlToJenaResource.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a set of OWLAxiom in an iterator over jena statements
     * 
     * @param axioms
     *            {A set of aximos}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An iterator over statments}
     */
public synchronized StmtIterator AxiomOwlToJenaResource(Set<OWLAxiom> axioms, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("AxiomOwlToJenaResource::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        Iterator<OWLAxiom> axiom = axioms.iterator();
        while (axiom.hasNext()) manager.addAxiom(ontology, axiom.next());
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.listStatements();
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("AxiomOwlToJenaResource::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom)

Example 4 with OntModel

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

the class JenaToOwlConvert method AnnotationPropOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLAnnotationProperty of OWL to an AnnotationProperty of Jena
     * 
     * @param data
     *            {An OWLAnnotationProperty object}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An AnnotationProperty object}
     */
public synchronized AnnotationProperty AnnotationPropOwlToJena(OWLAnnotationProperty data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("AnnotationPropOwlToJena::: " + 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.getAnnotationProperty(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("AnnotationPropOwlToJena::: ");
        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 5 with OntModel

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

the class JenaToOwlConvert method ObjPropOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLObjectProperty of owl to an ObjectProperty of Jena
     * 
     * @param data
     *            {An OWLObjectProperty object}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An ObjectProperty}
     */
public synchronized ObjectProperty ObjPropOwlToJena(OWLObjectProperty data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ObjPropOwlToJena::: " + 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.getObjectProperty(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("ObjPropOwlToJena::: ");
        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)

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