有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

通过owlapi访问java本体

我想通过使用Eclipse的OWLAPI访问我的本体和SWRL规则。有谁能帮我做一个确切的程序,告诉我该怎么做

我尝试了以下代码,但似乎没有得到任何响应。请记住,我的Java技能非常差

我需要一个关于如何着手和解决这个问题的确切程序

我已经掌握的代码是:

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

共 (1) 个答案

  1. # 1 楼答案

    用于加载和修改本体的OWLAPI示例有here 你会发现一个一般性的介绍和一组具体的例子。如果您需要某些特定代码的帮助,可以发布到OWLAPI邮件列表

    编译以下内容的代码版本:

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