如何检索OWL枚举数据类型表达式的元素? [英] How to retrieve elements of OWL enumerated datatype expression?

查看:173
本文介绍了如何检索OWL枚举数据类型表达式的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用哪个SPARQL查询来显示两个数据类型的并集的所有值?另外,如何计算此数据类型联合中的值数量?每个数据类型都用DataOneOf(...)公理定义.

What SPARQL query should I use to show all values of union of two datatypes? Additionally how can I count the number of values in this union of datatypes? Each datatype was defined with DataOneOf(...) axiom.

首先,我应该使用什么SPARQL查询来显示所选数据类型的所有值?

to start with something: what SPARQL query should I use to show all values of the selected datatype?

推荐答案

将来,如果您可以提供我们可以使用的最少数据,那将变得更加容易.这也将使问题更清楚.据我了解,您已经使用dataOneOf构造定义了一些数据类型来枚举多个文字.首先,让我们创建一些样本数据.这是一个具有两个属性的OWL本体,每个属性都有一个范围内的数据类型表达式.其中一个具有{"one","two"}作为范围,另一个具有{1,2}:

In the future, it would be much easier if you can provide minimal data that we can work with. It would also make the question a bit clearer. As I understand it, you've defined some datatypes using the dataOneOf construct to enumerate several literals. First, let's create some sample data. Here's an OWL ontology with two properties, each of which has an enmerated datatype expression as its range. One of them has {"one", "two"} as the range, and the other has {1, 2}:

@prefix :      <http://example.org/datatypes#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

:p1     a           owl:DatatypeProperty ;
        rdfs:range  [ a          rdfs:Datatype ;
                      owl:oneOf  [ a          rdf:List ;
                                   rdf:first  1 ;
                                   rdf:rest   [ a          rdf:List ;
                                                rdf:first  2 ;
                                                rdf:rest   ()

                                              ]
                                 ]
                    ] .

:p2     a           owl:DatatypeProperty ;
        rdfs:range  [ a          rdfs:Datatype ;
                      owl:oneOf  [ a          rdf:List ;
                                   rdf:first  "one" ;
                                   rdf:rest   [ a          rdf:List ;
                                                rdf:first  "two" ;
                                                rdf:rest   ()

                                              ]
                                 ]
                    ] .

请注意,数据类型表达式中的可能值列表以RDF列表形式给出.使用属性路径查询RDF列表是最简单的,并且在Stack Overflow上还有很多其他示例.查询看起来像这样,它将检索数据类型以及它们的每个元素以及这些元素的数据类型(如果您也需要的话).

Notice that the list of possible values in the datatype expression are given as an RDF list. It's easiest to query RDF lists using property paths, and there are lots of other examples of that here on Stack Overflow. Here's what the query could look like that will retrieve the datatypes along with each of their elements and the datatype of those elements (in case you want that, too).

prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

select ?dt ?element ?elementType {
  ?dt a rdfs:Datatype ;
      owl:oneOf/rdf:rest*/rdf:first ?element .
  bind(datatype(?element) as ?elementType)
}

---------------------------------------------------------------
| dt   | element | elementType                                |
===============================================================
| _:b0 | "one"   | <http://www.w3.org/2001/XMLSchema#string>  |
| _:b0 | "two"   | <http://www.w3.org/2001/XMLSchema#string>  |
| _:b1 | 1       | <http://www.w3.org/2001/XMLSchema#integer> |
| _:b1 | 2       | <http://www.w3.org/2001/XMLSchema#integer> |
---------------------------------------------------------------

请注意,此类数据类型通常由空白节点表示,这意味着它们具有关联的IRI.例如,在这种情况下,它们显示为_:b0和_:b1.不过,希望您可以通过某种方式来识别您感兴趣的特定数据类型表达式,例如,通过询问某些特定属性的范围或类似的范围.

Note that often time such datatypes are represented by blank nodes, which means that they don't have associated IRIs. In this case, for example, they show up as _:b0 and _:b1. Hopefully, though, you have some way to identify the particular datatype expressions that you're interested in, e.g., by asking for the range of some particular property, or something like that.

这篇关于如何检索OWL枚举数据类型表达式的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆