本文介绍了APACHE Jena Ont模型对owl:maxQualifiedCardinality和owl:minQualifiedCardinality的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用APACHE Jena ONT模型来解析RDF/XML OWL文件并对其进行处理.在当前的ONT模型中, owl:maxQualifiedCardinality owl:minQualifiedCardinality 的限制在ONT模型中无法识别.我还查看了org.apache.jena.ontology软件包的 Restriction接口 ,发现不支持这些限制,而是支持owl:minCardinality和owl:maxCardinality.我现在想知道Jena ONT模型是否可以考虑这些限制:owl:maxQualifiedCardinality,owl:minQualifiedCardinality

I am using APACHE Jena ONT model to parse RDF/XML OWL files and process them. With the current ONT model, restrictions with owl:maxQualifiedCardinality and owl:minQualifiedCardinality are not recognized in the ONT model. I also looked into the Restriction interface of org.apache.jena.ontology package and found that these restrictions are not supported, instead owl:minCardinality and owl:maxCardinality are supported. I am wondering now if there is a way that Jena ONT model can also consider these restrictions : owl:maxQualifiedCardinality, owl:minQualifiedCardinality

如果您能告诉我您的工作经历,我将很高兴.使用Jena ont模型处理此类限制并处理其数据

I will be happy if you can let me know your experience w.r.t. handlinge such restrictions and processing their data with Jena ont model

<owl:Class rdf:about="http://test#Numeric">
    <rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://test#hasUnit"/>
            <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxQualifiedCardinality>
            <owl:onClass rdf:resource="http://test#Scale"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:label>Numeric</rdfs:label>
</owl:Class>

推荐答案

Apache Jena本体API(org.apache.jena.ontology.OntModel)不支持OWL2 DL.您可以查看基于Jena的替代方法(即 ONT-API ).这是OWL-2的另一个专用耶拿接口,它支持诸如owl:maxQualifiedCardinality

Apache Jena ontology API (org.apache.jena.ontology.OntModel) does not support OWL2 DL.You can take a look at the Jena-based alternative (i.e. ONT-API). This is another jena interface special for OWL-2, which supports such things as owl:maxQualifiedCardinality

示例:

    OntModel m = OntModelFactory.createModel();
    m.setID("http://test");
    OntObjectProperty property = m.createObjectProperty("http://test#hasUnit");
    OntClass clazz = m.createOntClass("http://test#Numeric");
    clazz.addLabel("Numeric", null);
    clazz.addSuperClass(m.createOntClass("http://test#Characteristic"))
            .addSuperClass(m.createObjectMaxCardinality(property, 1,
                    m.createOntClass("http://test#Scale")));

    StringWriter sw = new StringWriter();
    m.write(sw, "rdf/xml");
    System.out.println(sw);

    // another way to create OntGraphModel:
    InputStream in = new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8));
    OntModel reloaded = OntManagers.createONT().loadOntologyFromOntologyDocument(in).asGraphModel();
    int cardinality = reloaded.ontObjects(OntClass.ObjectMaxCardinality.class)
            .mapToInt(OntClass.CardinalityRestrictionCE::getCardinality)
            .findFirst().orElseThrow(IllegalStateException::new);
    System.out.println(cardinality);

输出:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://test"/>
  <owl:Class rdf:about="http://test#Characteristic"/>
  <owl:Class rdf:about="http://test#Scale"/>
  <owl:Class rdf:about="http://test#Numeric">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onClass rdf:resource="http://test#Scale"/>
        <owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >1</owl:maxQualifiedCardinality>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="http://test#hasUnit"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
    <rdfs:label>Numeric</rdfs:label>
  </owl:Class>
</rdf:RDF>

1

如果您认为原始的Jena Ontology API更方便,则可以将图形传递回org.apache.jena.ontology.OntModel接口:

And if you think that the original Jena Ontology API is more convenient, you can pass the graph back to org.apache.jena.ontology.OntModel interface:

OntModel jena = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, reloaded);
        jena.write(System.out, "rdf/xml");

这篇关于APACHE Jena Ont模型对owl:maxQualifiedCardinality和owl:minQualifiedCardinality的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 18:22