在SPARQL的CONSTRUCT模式中使用ORDER BY解决方案修饰符

时间:2014-02-26 00:27:03

标签: rdf sparql sesame openrdf

我按照SPARQL 1.1部分10.2 CONSTRUCT进行了以下SPARQL查询,该查询返回主题类型为Homework并且还有事件日期的所有三元组。

CONSTRUCT  { ?s ?p ?o } WHERE 
{
 GRAPH ?g { ?s ?p ?o } .
 { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>   
    <http://lod.isi.edu/ontology/syllabus/Homework> 
 }.

 { ?s <http://lod.isi.edu/ontology/syllabus/hasEventDate> ?date}.
}

现在,我想以事件日期?date的升序/降序检索结果。我尝试添加order by修饰符,如下所示,但OpenRDF工作台中存在解析错误。

CONSTRUCT  { ?s ?p ?o } WHERE 
{
 GRAPH ?g { ?s ?p ?o } .
 { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>   
    <http://lod.isi.edu/ontology/syllabus/Homework> 
 }.

 { ?s <http://lod.isi.edu/ontology/syllabus/hasEventDate> ?date}.
 ORDER BY DESC(?date)

}
Encountered " "order" "ORDER "" at line 9, column 6. Was expecting one of:
"(" ... "{" ... "}" ... "[" ... <NIL> ... <ANON> ... "optional" ...
"graph" ... "minus" ... "filter" ... "true" ... "false" ... "bind" ...
"service" ... "values" ... <Q_IRI_REF> ... <PNAME_NS> ... <PNAME_LN> ...
<BLANK_NODE_LABEL> ... <VAR1> ... <VAR2> ... <INTEGER> ... <INTEGER_POSITIVE> ...
<INTEGER_NEGATIVE> ... <DECIMAL> ... <DECIMAL_POSITIVE> ...
<DECIMAL_NEGATIVE> ... <DOUBLE> ... <DOUBLE_POSITIVE> ...
<DOUBLE_NEGATIVE> ... <STRING_LITERAL1> ... <STRING_LITERAL2> ...
<STRING_LITERAL_LONG1> ... <STRING_LITERAL_LONG2> ...

1 个答案:

答案 0 :(得分:2)

问题是您的ORDER BY子句在查询中的位置不正确。它应该在关闭括号之后关闭WHERE子句:

CONSTRUCT  { ?s ?p ?o } 
WHERE 
{
 GRAPH ?g { ?s ?p ?o } 
 ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://lod.isi.edu/ontology/syllabus/Homework> .
 ?s <http://lod.isi.edu/ontology/syllabus/hasEventDate> ?date .
}
ORDER BY ASC(?date)

另请注意,原始查询中的几个花括号虽然不是完全错误,但是多余的。