首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >列出jena的qualifiedCardinality限制资源

列出jena的qualifiedCardinality限制资源
EN

Stack Overflow用户
提问于 2016-12-27 05:05:00
回答 1查看 234关注 0票数 1

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

有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2017-09-07 22:23:20

该代码片段显示它是OWL2本体。org.apache.jena.ontology).仅支持OWL1 (请参见软件包Jena但是您也可以选择使用来自ONT-API的,它完全类似于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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41336267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档