2014-03-03 55 views
0

我想通過使用Eclipse的OWL API訪問我的本體和SWRL規則。任何人都可以幫助確切的程序,可以告訴我該怎麼做?通過OWL API訪問本體

我試過下面的代碼,但我似乎沒有得到任何迴應。請記住,我的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"); 
    } 
    } 
} 
+0

這段代碼的意圖是正確的,但是,因爲它顯示,我懷疑它編譯。你有一個嵌套在main方法中的方法,並且我沒有看到Ont_Base_IRI的聲明 – Ignazio

回答

0

裝載和修改本體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); 
    } 
}