2016-12-05 86 views
-1

如何使用owl api創建子類?以下內容是使用protege生成的。如何使用OWL創建OWL中的子類2

<owl:Class rdf:about="http://www.semanticweb.org/muz_a/ontologies/2016/diseasesymptomogy-9#dizziness"> 
     <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/muz_a/ontologies/2016/diseasesymptomogy-9#symptom"/> 
     <rdfs:label>dizziness</rdfs:label> 
</owl:Class>` 
<owl:Class rdf:about="http://www.semanticweb.org/muz_a/ontologies/2016/diseasesymptomogy-9#dizziness"> 
     <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/muz_a/ontologies/2016/diseasesymptomogy-9#symptom"/> 
     <rdfs:label>dizziness</rdfs:label> 
</owl:Class> 
+3

你嘗試過什麼?什麼沒有工作呢? OWL-API有很好的文檔記錄,所以我假設你遇到了一些特殊問題? –

+3

閱讀OWL API文檔和例子是去... – AKSW

+0

@JoshuaTaylor即時消息沒有得到適當的輸出爲一個以上的IM,而具有這種類型 subclassof 類#A 類的方式#B subclassof 即使即時通訊使用此: OWLAxiom axiom_spec = df.getOWLSubClassOfAxiom(clsA,clsA_spec); 應該工作正常。對?? – Umar

回答

1

有關如何添加,刪除和保存對本體的更改的示例文檔here

https://github.com/owlcs/owlapi/blob/version4/contract/src/test/java/org/semanticweb/owlapi/examples/Examples.java

@Test 
public void shouldAddAxiom() throws Exception { 
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
    IRI ontologyIRI = IRI.create("http://www.co-ode.org/ontologies/testont.owl"); 
    IRI documentIRI = IRI.create("file:/tmp/MyOnt.owl"); 
    SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI); 
    manager.getIRIMappers().add(mapper); 
    OWLOntology ontology = manager.createOntology(ontologyIRI); 
    OWLDataFactory factory = manager.getOWLDataFactory(); 
    OWLClass clsA = factory.getOWLClass(IRI.create(ontologyIRI + "#A")); 
    OWLClass clsB = factory.getOWLClass(IRI.create(ontologyIRI + "#B")); 
    OWLAxiom axiom = factory.getOWLSubClassOfAxiom(clsA, clsB); 
    AddAxiom addAxiom = new AddAxiom(ontology, axiom); 
    manager.applyChange(addAxiom); 
    manager.saveOntology(ontology); 
} 
0
public void addSubClass() throws OWLOntologyCreationException, OWLOntologyStorageException { 
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
    OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("pathToFile"); 
    OWLDataFactory dataFactory = OWLManager.getOWLDataFactory(); 

    OWLClass parentC = dataFactory.getOWLClass(IRI.create(baseIRI, "parent"); 
    OWLClass childC = dataFactory.getOWLClass(IRI.create(baseIRI, "child"); 
    axiom = dataFactory.getOWLSubClassOfAxiom(childC, parentC); 

    Axiom addAxiom = new AddAxiom(ontology, axiom); 

    manager.applyChange(addAxiom); 
    manager.saveOntology(ontology); 
}