简体   繁体   English

SPARQL - 获取类的对象属性和数据类型属性的确切类型

[英]SPARQL - Get object properties and exact type of datatype properties of a class

I want to get all the properties of a class.我想获得一个类的所有属性。 If a property is a datatype property I want to know its exact type ie float, integer, date etc.如果属性是数据类型属性,我想知道它的确切类型,即浮点、整数、日期等。

Running the following query I get only if a property is an object property or a datatype property仅当属性是对象属性或数据类型属性时,我才会运行以下查询

SELECT ?class ?property ?type
WHERE {
    ?resource ?property ?target .
    ?property rdfs:domain ?class .
    ?resource a ?class .
    ?property rdf:type ?type .

} }

Results结果

:Store  :location http://www.w3.org/2002/07/owl#ObjectProperty
:Product :price http://www.w3.org/2002/07/owl#DatatypeProperty

How can I specify the type of a property if it is a datatype property?如果它是数据类型属性,我如何指定属性的类型? For example, I would like to know not only that price is a DatatypeProperty but it is a float.例如,我想知道价格不仅是 DatatypeProperty,而且是浮点数。

Thank you.谢谢你。

The datatype gets specified as the range ( rdfs:range ) of a datatype property.数据类型被指定为数据类型属性的范围( rdfs:range )。

SELECT ?class ?property ?type ?range
WHERE {

    ?resource ?property ?target .
    ?resource a ?class .
    ?property rdf:type ?type .

    OPTIONAL {    
      ?property rdfs:domain ?class .
    }

    OPTIONAL {
      ?property rdfs:range ?range .
    }

}

(I used OPTIONAL so that your query also lists properties for which no domain and/or range is specified.) (我使用了OPTIONAL以便您的查询还列出未指定域和/或范围的属性。)

Result: Screenshot结果:截图

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

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