【问题标题】:Access ontology through OWL API通过OWL API访问本体
【发布时间】:2014-04-05 03:36:44
【问题描述】:

我想使用 Eclipse 通过 OWL API 访问我的本体和 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");
    }
  }
}

【问题讨论】:

  • 这段代码的意图是正确的,但是,如图所示,我怀疑它是否可以编译。您有一个嵌套在 main 方法中的方法,我没有看到 Ont_Base_IRI 的声明

标签: java ontology swrl owl-api


【解决方案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);
    }
}

【讨论】:

    猜你喜欢
    • 2018-03-18
    • 2013-05-12
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    相关资源
    最近更新 更多