2012-03-15 67 views
2

我想爲我的測試服務器構建正確的查詢,並且遇到了我無法定義PREFIX的問題。OpenRDF芝麻:無法定義前綴

例如,這個查詢的工作:

select * where 
{ 
    ?stayingURL <http://localhost/resource_lng> ?lng . 
    ?stayingURL <http://localhost/resource_staying_date> ?date . 
    ?stayingURL <http://localhost/resource_address> ?address . 
} 
LIMIT 100 

我嘗試按日期添加過濾器,就像這樣:

select * where 
{ 
    ?stayingURL <http://localhost/resource_lng> ?lng . 
    ?stayingURL <http://localhost/resource_staying_date> ?date . 
    ?stayingURL <http://localhost/resource_address> ?address . 
    FILTER (?date > "2012-01-01"^^xsd:date) 
} 
LIMIT 100 

現在我得到了以下錯誤: 「MALFORMED QUERY: org.openrdf.query.parser.sparql.ast.VisitorException: QName 'xsd:date' uses an undefined prefix

好的,我嘗試通過將以下行添加到查詢的開頭來手動聲明此前綴:

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

現在,我得到這個錯誤:

MALFORMED QUERY: Encountered " "<" "< "" at line 1, column 14. 
Was expecting: 
<Q_IRI_REF> ... 

這對我來說很陌生,但無論如何,我試圖把它直接寫,沒有任何前綴:

select * where 
{ 
?stayingURL <http://localhost/resource_lng> ?lng . 
?stayingURL <http://localhost/resource_staying_date> ?date . 
?stayingURL <http://localhost/resource_address> ?address . 
FILTER (?date > "2012-01-01"^^<http://www.w3.org/2001/XMLSchema#date>) 
} 
LIMIT 100 

結果幾乎是一樣的:

MALFORMED QUERY: Encountered " "<" "< "" at line 1, column 228. 
Was expecting one of: 
    <Q_IRI_REF> ... 
    <PNAME_NS> ... 
    <PNAME_LN> ... 

我在做什麼錯?

這是我的服務器地址:http://176.34.226.101:8080/openrdf-sesame/repositories/ecomobile

+2

你如何將查詢發送到你的服務器?第二個查詢引用「第1行第228列」中的錯誤的事實表明您將它編碼爲HTTP請求中的參數。您確定在此請求中正確編碼了「<" and ">」字符嗎? – Jan 2012-03-15 19:19:53

+0

@Jan,謝謝,這個問題真的是在網址編碼;但我想知道爲什麼第一個查詢的作品?它也包含'<' '>'字符。 – 2012-03-16 04:35:15

回答

4

它爲我,如果我URI編碼所有query參數:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
select * where 
{ 
?stayingURL <http://localhost/resource_lng> ?lng . 
?stayingURL <http://localhost/resource_staying_date> ?date . 
?stayingURL <http://localhost/resource_address> ?address . 
FILTER (?date > "2012-01-01"^^<http://www.w3.org/2001/XMLSchema#date>) 
} 
LIMIT 100 

這將是請求:

http://176.34.226.101:8080/openrdf-sesame/repositories/ecomobile?query=PREFIX%20xsd%3A%20%3Chttp%3A//www.w3.org/2001/XMLSchema%23%3E%20select%20%2A%20where%0A%7B%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_lng%3E%20%3Flng%20.%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_staying_date%3E%20%3Fdate%20.%0A%20%20%20%3FstayingURL%20%3Chttp%3A//localhost/resource_address%3E%20%3Faddress%20.%0A%20%20%20FILTER%20%28%3Fdate%20%3E%20%222012-01-01%22%5E%5Exsd%3Adate%29%0A%7D%0ALIMIT%20100

道歉的神祕不可讀URI一...縮短版本:

http://bit.ly/xTQhSV

+0

謝謝,這個問題真的是在網址編碼;但我想知道爲什麼第一個查詢的作品?它也包含'<' '>'字符。 – 2012-03-16 04:36:05