2016-12-05 84 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); 
}