3

我正在对我的一个仅支持 Sparql 1.0 的 sparql 端点运行 sparql 查询。
我正在尝试使用以下查询从商店获取用户列表:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX tmp: <http://example.com/schema/temp#>
PREFIX resource: <http://example.com/2010/record/schema#>
Describe ?userURI
WHERE 
{
    ?userURI rdf:type resource:User.
    OPTIONAL
    {               
        ?userURI tmp:dataCleanupStatus ?cleanUpStatus.
        ?userURI tmp:lastDataCleanupDate ?cleanUpDate.                  
    }
    FILTER 
    ( 
        (!bound(?cleanUpStatus) || ?cleanUpStatus !="Running")
    )
                    FILTER(    
        (!bound(?cleanUpDate) || ?cleanUpDate < "2012-04-11" )
    )

}

通过上述查询,我​​试图获取用户,其中:

  1. 清理状态三元组不存在,或者状态不是“正在运行”
  2. clearnUpDate 三元组要么不存在,要么小于指定日期。

它没有返回它应该返回的记录。
你可能会说我应该使用xsd函数,但是,它们仅在 Sparql 1.1 中受支持


请指教。
修改后的查询:


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX tmp: <http://example.com/schema/temp#>
PREFIX resource: <http://example.com/2010/record/schema#>
Describe ?userURI
WHERE 
{
    ?userURI rdf:type resource:User.
    OPTIONAL
    {               
        ?userURI tmp:dataCleanupStatus ?cleanUpStatus.

    }

    OPTIONAL
    {               
        ?userURI tmp:lastDataCleanupDate ?cleanUpDate.                  
    }
    FILTER 
    ( 
        !bound(?cleanUpStatus) || ?cleanUpStatus !="Running"
    )
    FILTER
    (    
        !bound(?cleanUpDate) || ?cleanUpDate < "2012-04-11" 
    )

}


4

1 回答 1

6

问题可能出在日期比较中,假设它xsd:date在原始数据中存储为类型化文字。如果没有类型转换,您无法将字符串与日期进行比较。

一些事情要尝试:

?cleanUpDate < "2012-04-11"^^xsd:date    # Compare against date
STR(?cleanUpDate) < "2012-04-11"         # Convert to string before comparison

此外,根据数据的结构,您可能需要两个单独OPTIONAL的块用于?cleanUpStatus?cleanUpDate

于 2012-04-13T10:05:02.443 回答