繁体   English   中英

使用 jena 列出qualifiedCardinality 限制的资源

[英]list resources of qualifiedCardinality restriction with jena

我是 jena 库的新手,想列出qualifiedCardinality 限制的所有资源、属性和数据类型。

我的限制:

...
<rdfs:subClassOf>
  <owl:Restriction>
    <owl:onProperty         rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#sensingMethodUsed"/>
    <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/>
    <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
  </owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
  <owl:Restriction>
    <owl:onProperty rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#featureOfInterest"/>
    <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/>
    <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality>
  </owl:Restriction>
</rdfs:subClassOf>
...

所需的字符串输出:

qualcard sensingMethodUsed nonNegativeIteger 1 Sensing                        
qualcard featureOfInterest nonNegativeIteger 1 FeatureOfInterest

请有人可以帮助我。

该片段显示它是 OWL2 本体。 Jena 仅支持 OWL1(参见包org.apache.jena.ontology )。 但是作为一个选项,您可以使用来自ONT-API 的com.github.owlcs.ontapi.jena.model.OntModel ,它完全类似于org.apache.jena.ontology.OntModel但适用于 OWL2 规范。 ONT-API 是一个基于 jena 的库。

见示例:

    // build the model with qualified exact cardinality object property restrictions:
    String ns = "http://purl.oclc.org/NET/ssnx/ssn#";
    OntModel m = OntModelFactory.createModel();
    m.setNsPrefixes(OntModelFactory.STANDARD);
    OntObjectProperty op1 = m.createObjectProperty(ns + "sensingMethodUsed");
    OntClass c1 = m.createOntClass(ns + "Sensing");
    OntObjectProperty op2 = m.createObjectProperty(ns + "featureOfInterest");
    OntClass c2 = m.createOntClass(ns + "FeatureOfInterest");
    m.createOntClass("http://example.com#clazz")
            .addSuperClass(m.createObjectCardinality(op1, 1, c1))
            .addSuperClass(m.createObjectCardinality(op2, 1, c2));

    // printing:
    m.write(System.out, "rdf/xml");
    System.out.println();
    // list all exact cardinality restrictions:
    m.ontObjects(OntClass.ObjectCardinality.class).forEach(c -> {
        int cardinality = c.getCardinality();
        OntClass onClass = c.getValue(); // cannot be null, owl:Thing if it is unqualified restriction
        OntObjectProperty onProperty = c.getProperty();
        OntDataRange dt = m.getDatatype(XSD.nonNegativeInteger); // only this DT is allowed
        System.out.printf("qualcard %s %s %d %s%n",
                onProperty.getLocalName(), dt.getLocalName(), cardinality, onClass.getLocalName());
    });

此示例的输出为:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:eg="http://www.example.org/"
    xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:ja="http://jena.hpl.hp.com/2005/11/Assembler#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:rss="http://purl.org/rss/1.0/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:Ontology/>
  <owl:Class rdf:about="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/>
  <owl:Class rdf:about="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/>
  <owl:Class rdf:about="http://example.com#clazz">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/>
        <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >1</owl:qualifiedCardinality>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="http://purl.oclc.org/NET/ssnx/ssn#featureOfInterest"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/>
        <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >1</owl:qualifiedCardinality>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="http://purl.oclc.org/NET/ssnx/ssn#sensingMethodUsed"/>
        </owl:onProperty>
      </owl:Restriction>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>

qualcard featureOfInterest nonNegativeInteger 1 FeatureOfInterest
qualcard sensingMethodUsed nonNegativeInteger 1 Sensing

暂无
暂无

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

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