按日期和月份过滤SPARQL结果 [英] Filtering SPARQL results by day and month

查看:116
本文介绍了按日期和月份过滤SPARQL结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 http://dbpedia.org/snorql 网站启动一些基本请求,例如

I'm currently using the http://dbpedia.org/snorql website to launch some basic request like the one below:

PREFIX dbpedia0: <http://dbpedia.org/ontology/>
SELECT ?body ?value WHERE {
?body a dbpedia0:Person.
?body dbpedia0:birthDate ?value.
}
ORDER BY ?value

我想找到一种方法筛选结果,以便仅选择在 X Y 日出生的人(无论出生年份)。我一直在尝试使用许多方法来做到这一点,例如:

I would like to find a way of filtering the results so that only people born on day X month Y are being selected (no matter the birth year). I have been trying to do so with many approaches like:

1)基本过滤: FILTER(xsd:date(?value)= 2000 -01-01 ^^ xsd:date)
但是我现在不怎么精确地说明我不在乎年份...

1) Basic filtering: FILTER(xsd:date(?value) = "2000-01-01"^^xsd:date) But I don't now how to precise the fact that I don't care about the year...

2)使用 MONTH() DAY()函数导致代表月和日的整数值...但是这些似乎不起作用,因为据说我的日期类型是无效的输入参数。

2) Use the MONTH() and DAY() functions that should lead to integer values representing month and day... But these don't seem to work as my date type is said to be an invalid input argument.

3)转换日期转换为字符串变量。然后测试此字符串变量的结尾字符(对应于月和日)是否与所需的月和日匹配。类似于: FILTER(STRENDS(CONVERT(CHAR,?value), 01-01)= true)

3) Convert the date into a string variable. And then test if the ending characters of this string variable (corresponding to month and day) match the required month and day. That would be something like : FILTER(STRENDS(CONVERT(CHAR, ?value),"01-01") = true)

显然,以上所列方法均无法正常工作...哈哈。
请不要怪我的请求语法不佳,因为我只是从SPARQL命令开始。

Apparently, none of the methods listed above is properly working... haha. Please don't blame me for the poor syntax of my request as I'm just beginning with SPARQL commands.

我将非常感谢您的帮助

推荐答案

您会收到错误消息,因为(如我在评论中所说)并非所有文字键入 xsd:date ,或者可以是 CAST 过滤器可以工作

You get an error because (as I said in comment) not all literals are of, or can be CAST to, type xsd:date. A filter for that could work

PREFIX dbpedia0: <http://dbpedia.org/ontology/>
SELECT ?body ?value WHERE 
  { 
    ?body  a                   dbpedia0:Person  . 
    ?body  dbpedia0:birthDate  ?value           . 
           FILTER (   datatype(?value) = xsd:date
                   &&     year(?value) = 2000
                  )
  } 
limit 10

错误:

Virtuoso 22003 Error SR586: Incomplete RDF box as argument 0 for year().

另一种尝试 cast 的尝试使我印象 FILTER 参数以任意顺序执行,并导致另一个错误:

Another try with casting leads me to the impression that the FILTER arguments are executed in arbitrary order, and lead to another error:

PREFIX dbpedia0: <http://dbpedia.org/ontology/>
SELECT ?body ?value 
WHERE 
  { 
    ?body  a                   dbpedia0:Person  . 
    ?body  dbpedia0:birthDate  ?value           . 
           FILTER (         datatype(?value) = xsd:date 
                   && year(xsd:date(?value)) = 2000
                  )
  } 
limit 10

错误:

Virtuoso 22007 Error DT001: Function year needs a datetime, date or time as argument 1, not an arg of type DB_NULL (204)

使用sub- SELECT 似乎可行,但不适用于

Using sub-SELECTs seems to work, but not for

PREFIX dbpedia0: <http://dbpedia.org/ontology/>

SELECT ?body ?value 
WHERE 
  { 
           FILTER ( year(xsd:date(?value)) = 2000 )
    { 
      SELECT ?body ?value 
      WHERE 
        { 
          ?body  a                   dbpedia0:Person  . 
          ?body  dbpedia0:birthDate  ?value           . 
                 FILTER ( datatype(?value) = xsd:date )
        }
    }
  }
limit 10

错误:

Virtuoso 22003 Error SR586: Incomplete RDF box as argument 1 for xqf_str_parse().

仅在子目录中包含 LIMIT SELECT 它对我有用:

Only with a LIMIT inside the sub-SELECT it works for me:

PREFIX dbpedia0: <http://dbpedia.org/ontology/>

SELECT ?body ?value 
WHERE 
  { 
           FILTER ( year(xsd:date(?value)) = 2000 )
      {
        SELECT ?body ?value 
        WHERE 
          { 
            ?body  a                   dbpedia0:Person  . 
            ?body  dbpedia0:birthDate  ?value           . 
                   FILTER ( datatype(?value) = xsd:date )
          }
        LIMIT 10
      }
   }
LIMIT 10

我不知道Virtuoso怎么了。

I don't know what's going wrong with Virtuoso here.

这篇关于按日期和月份过滤SPARQL结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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