简体   繁体   中英

Access ontology through OWL API

I would like to have access to my ontology and SWRL rule through OWL API using Eclipse. Can anyone help with the exact procedure that can tell me what to do?

I have tried the following code but I do not seem to get any response from it. Please bear in mind that my Java skills are very poor.

I would need an exact procedure on how to go about and resolve this issue.

The code that I have already is:

public static void main(String[] args) {
  File file = new File("file:c:/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
  OWLOntologyManager m = OWLManager.createOWLOntologyManager();
  OWLDataFactory f = OWLManager.getOWLDataFactory();
  OWLOntology o = null;

  public void testAddAxioms() {
    try {
        o = m.loadOntologyFromOntologyDocument(Ont_Base_IRI);
        OWLClass clsA = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassA"));
        OWLClass clsB = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassB"));
        OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
        AddAxiom addAxiom1 = new AddAxiom(o, ax1);
        m.applyChange(addAxiom1);

        for (OWLClass cls : o.getClassesInSignature()) {
            EditText edit = (EditText) findViewById(R.id.editText1);
            edit.setText((CharSequence) cls);
        }

        m.removeOntology(o);
    } catch (Exception e) {
        EditText edit = (EditText) findViewById(R.id.editText1);
        edit.setText("Not successfull");
    }
  }
}

OWLAPI examples for loading and modifying an ontology are here You'll find both a general introduction and a set of specific examples. If you need help with some particular piece of code, you can post to the OWLAPI mailing list.

A version of the code that compiles:

import java.io.File;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Snippet {

    public static void main(String[] args) throws OWLOntologyCreationException {
        File file = new File(
                "file:///c/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        OWLDataFactory f = OWLManager.getOWLDataFactory();
        OWLOntology o;
        o = m.loadOntologyFromOntologyDocument(file);
        OWLClass clsA = f.getOWLClass(IRI.create("urn:test#ClassA"));
        OWLClass clsB = f.getOWLClass(IRI.create("urn:test#ClassB"));
        OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
        AddAxiom addAxiom1 = new AddAxiom(o, ax1);
        m.applyChange(addAxiom1);
        for (OWLClass cls : o.getClassesInSignature()) {
            System.out.println(cls.getIRI());
        }
        m.removeOntology(o);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM