0

我在 jena fuseki rdf 商店中有很多图形名称,这些是我的图形名称:

| <http://stormsmacs/tests/2015-03-03T04:27:57Z> |
| <http://stormsmacs/tests/2015-03-03T05:20:59Z> |
| <http://stormsmacs/tests/2015-03-03T05:22:29Z> |
| <http://stormsmacs/tests/2015-03-03T05:25:03Z> |
| <http://stormsmacs/tests/2015-03-03T05:27:01Z> |
| <http://stormsmacs/tests/2015-03-03T05:30:37Z> |
| <http://stormsmacs/tests/2015-03-03T05:44:02Z> |
| <http://stormsmacs/tests/2015-03-03T05:52:19Z> |
| <http://stormsmacs/tests/2015-03-03T05:58:47Z> |

等等。如何过滤图表以获取两个日期之间的所有图表?

非常感谢!

4

1 回答 1

2

当我们有实际数据可以使用时会更容易。请务必提供我们将来可以使用的数据。对于这种情况,我刚刚使用values块将带有嵌入日期时间的 URI 绑定到?dateUri变量。查询中的注释解释了正在发生的事情。总体思路是将 URI 转换为字符串,去掉公共前缀,将后缀转换为xsd:dateTime,并基于它进行过滤。

prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select ?dateTime where {
  #-- the "dates" encoded in URIs
  values ?dateUri { <http://stormsmacs/tests/2015-03-03T04:27:57Z>
                    <http://stormsmacs/tests/2015-03-03T05:20:59Z>
                    <http://stormsmacs/tests/2015-03-03T05:22:29Z>
                    <http://stormsmacs/tests/2015-03-03T05:25:03Z>
                    <http://stormsmacs/tests/2015-03-03T05:27:01Z>
                    <http://stormsmacs/tests/2015-03-03T05:30:37Z>
                    <http://stormsmacs/tests/2015-03-03T05:44:02Z>
                    <http://stormsmacs/tests/2015-03-03T05:52:19Z>
                    <http://stormsmacs/tests/2015-03-03T05:58:47Z> }

  #-- an arbitrary begin and end date                    
  values ?begin { "2015-03-03T05:22:29Z"^^xsd:dateTime }
  values ?end   { "2015-03-03T05:44:02Z"^^xsd:dateTime }

  #-- extract the dateTime portion from the URI string, and convert
  #-- it to an xsd:dateTime.
  bind( xsd:dateTime(strafter(str(?dateUri),"http://stormsmacs/tests/")) as ?dateTime )

  #-- filter results based on the begin and end time
  filter( ?begin <= ?dateTime && ?dateTime <= ?end )
}
----------------------------------------
| dateTime                             |
========================================
| "2015-03-03T05:22:29Z"^^xsd:dateTime |
| "2015-03-03T05:25:03Z"^^xsd:dateTime |
| "2015-03-03T05:27:01Z"^^xsd:dateTime |
| "2015-03-03T05:30:37Z"^^xsd:dateTime |
| "2015-03-03T05:44:02Z"^^xsd:dateTime |
----------------------------------------
于 2015-03-10T14:25:17.310 回答