繁体   English   中英

如何使用OWL 2在OWL中创建子类

[英]How to create subclasses in OWL using OWL 2

如何使用owl API创建子类? 使用protege生成了以下内容。

<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>

此处提供的文档提供有关如何添加,删除和保存对本体所做的更改的示例。

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);
}
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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM