简体   繁体   English

通过OWL API访问本体

[英]Access ontology through OWL API

I would like to have access to my ontology and SWRL rule through OWL API using Eclipse. 我想使用Eclipse通过OWL API访问我的本体和SWRL规则。 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. 请记住,我的Java技能很差。

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. 装载和修改本体OWLAPI的例子是在这里你会发现两者的一般性介绍和一组具体的例子。 If you need help with some particular piece of code, you can post to the OWLAPI mailing list. 如果您需要某些特定代码的帮助,可以将其发布到OWLAPI邮件列表。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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