在Sparql查询中过滤不起作用

时间:2012-04-13 08:27:19

标签: rdf sparql

我正在对我的一个仅支持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 triple不存在或者小于指定的日期。
  3. 它没有返回它应该返回的记录。
    您可能会说我应该使用 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" 
        )
    
    }
    


1 个答案:

答案 0 :(得分: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块。

相关问题