[英]Access ontology through OWL API
我想使用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");
}
}
}
裝載和修改本體OWLAPI的例子是在這里你會發現兩者的一般性介紹和一組具體的例子。 如果您需要某些特定代碼的幫助,可以將其發布到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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.