个别说明(owl-api)

时间:2018-09-20 14:40:33

标签: java owl owl-api

我想使用Java owl-api添加此断言(来自Protégé“个人描述” ):

person hasProperty only (ClassA or ClassB )

为:

<ClassAssertion>
  <ObjectAllValuesFrom>
    <ObjectProperty IRI=“#hasProperty”/>
      <ObjectUnionOf>
        <Class IRI=“#ClassA”/>
        <Class IRI=“#ClassB”/>
       </ObjectUnionOf>
   </ObjectAllValuesFrom>
  <NamedIndividual IRI=“#Person”/>
</ClassAssertion

我该怎么办?

OWLClass c1 = factory.getOWLClass(":ClassA", prefix );

OWLClass c2 = factory.getOWLClass(":ClassB", prefix );

OWLObjectProperty p = factory.getOWLObjectProperty("hasProperty", prefix);

OWLObjectIntersectionOf u = factory.getOWLObjectUnionOf(c1, c2);

OWLClassExpression e = factory.getOWLClass(property, u);

manager.addAxiom(owlOntology, factory.getOWLClassAssertionAxiom(p, person, e));

1 个答案:

答案 0 :(得分:0)

您编写的代码存在一些问题:

OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
OWLDataFactory factory=manager.getOWLDataFactory();
String str = "urn:test:ontology";
OWLOntology owlOntology=manager.createOntology(IRI.create(str));
String prefix=str+"#";

OWLClass c1 = factory.getOWLClass( prefix ,"ClassA");
OWLClass c2 = factory.getOWLClass( prefix, "ClassB" );
OWLObjectProperty p = factory.getOWLObjectProperty( prefix, "hasProperty");
OWLObjectUnionOf u = factory.getOWLObjectUnionOf(c1, c2);
OWLClassExpression e = factory.getOWLObjectAllValuesFrom(p, u);
OWLNamedIndividual person=factory.getOWLNamedIndividual(prefix, "Person");
manager.addAxiom(owlOntology, factory.getOWLClassAssertionAxiom(e, person));
// don't forget to save the ontology
manager.saveOntology(owlOntology, ... output stream here...);