在SPARQL日期范围过滤器 [英] Filter by date range in SPARQL

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

问题描述

我正在使用Jena的SPARQL引擎,并尝试在日期范围内编写一个查询来过滤,因为我需要在固定日期之后找到属性的值。



我的日期属性格式如下:

  Fri May 23 10:20:13 IST 2014 

如何编写SPARQL查询以获取其他日期大于此值的属性?

解决方案

使用您的数据格式,您不能过滤范围,而不添加自定义扩展功能到ARQ(其适用于高级用户),因为您需要解析和解释日期时间字符串。



您应该做的是将数据转换为标准日期时间格式 xsd:dateTime 所有SPARQL实现都需要支持。有关此格式的详细信息,请参阅 XML模式第2部分:数据类型规范。 / p>

您的具体示例日期将如下转换:

  2014-05 -23T10:20:13 + 05:30 

你必须确保你声明它是当您在数据和查询中使用它时,键入的类型为 xsd:dateTime 的文字。例如可读的 Turtle RDF语法:

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

:主题:日期2014-05-23T10:20:13 + 05:30^^ xsd:dateTime。

然后,您可以编写一个按照以下日期范围进行过滤的SPARQL查询:

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

SELECT *
WHERE
{
?s:date?date。
FILTER(?date>2014-05-23T10:20:13 + 05:30^^ xsd:dateTime)
}

查找所有记录,其中?date 是在给定日期之后


I am using Jena's SPARQL engine and trying to write a query to filter on a date range as I need to find the value of a property after a fixed date.

My date property is in the following format:

 Fri May 23 10:20:13 IST 2014 

How do I write a SPARQL query to get other properties with dates greater than this?

解决方案

With your data in that format you can't filter on a range of it without adding a custom extension function to ARQ (which is intended for advanced users) since you would need to parse and interpret the date time string.

What you should instead be doing is translating your data into the standard date time format xsd:dateTime that all SPARQL implementations are required to support. See the XML Schema Part 2: Datatypes specification for details of this format.

Your specific example date would translate as follows:

2014-05-23T10:20:13+05:30

And you must ensure that you declare it to be a typed literal of type xsd:dateTime when you use it in data and queries. For example in the readable Turtle RDF syntax:

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

:subject :date "2014-05-23T10:20:13+05:30"^^xsd:dateTime .

You could then write a SPARQL query that filters by range of dates like so:

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

SELECT *
WHERE
{
  ?s :date ?date .
  FILTER (?date > "2014-05-23T10:20:13+05:30"^^xsd:dateTime)
}

This finds all records where ?date is after the given date

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

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