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