2016-04-23 59 views
0

我有一個rdf文件,我想看看那些數量少於30的書。但它不會產生任何輸出。jena sparql過濾器doen沒有給出任何輸出

下面是RDF文件:

<?xml version="1.0" encoding="UTF-8"?> 

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:booktique ="http://www.w3.org/2001/booktique-rdf/3.0#">

<rdf:Description rdf:about="http://booktique.com/books/124"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Book"/> 
     <booktique:bookID>124</booktique:bookID> 
     <booktique:title>Geography</booktique:title> 
     <booktique:price>10$</booktique:price> 
     <booktique:author rdf:resource="http://booktique.com/authors/12999"/> 
     <booktique:publisher rdf:resource="http://booktique.com/publishers/Mcgill"/> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/books/258"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Book"/> 
     <booktique:bookID>258</booktique:bookID> 
     <booktique:title>Physics</booktique:title> 
     <booktique:price>20$</booktique:price> 
     <booktique:author rdf:resource="http://booktique.com/authors/12999"/> 
     <booktique:publisher rdf:resource="http://booktique.com/publishers/Swan"/> 
    </rdf:Description>` 

    <rdf:Description rdf:about="http://booktique.com/books/356"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Book"/> 
     <booktique:bookID>356</booktique:bookID> 
     <booktique:title>Phyton</booktique:title> 
     <booktique:price>25$</booktique:price> 
     <booktique:author rdf:resource="http://booktique.com/authors/13274"/> 
     <booktique:publisher rdf:resource="http://booktique.com/publishers/Connoly"/> 
    </rdf:Description> 



    <rdf:Description rdf:about="http://booktique.com/authors/12999"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Author"/> 
     <booktique:name>James Brown</booktique:name> 
     <booktique:authorID>12999</booktique:authorID> 
     <booktique:e-mail>[email protected]</booktique:e-mail> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/authors/13274"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Author"/> 
     <booktique:name>Kelly Smith</booktique:name> 
     <booktique:authorID>13274</booktique:authorID> 
     <booktique:e-mail>[email protected]</booktique:e-mail> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/publishers/Connoly"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Publisher"/> 
     <booktique:name>Connoly</booktique:name> 
     <booktique:address>US</booktique:address> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/publishers/Mcgill"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Publisher"/> 
     <booktique:name>Mcgill</booktique:name> 
     <booktique:address>UK</booktique:address> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/publishers/Swan"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/Publisher"/> 
     <booktique:name>Swan</booktique:name> 
     <booktique:address>FRA</booktique:address> 
    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/sales/book/124"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/SalesOrder"/> 
     <booktique:bookID rdf:resource="http://booktique.com/books/124"/> 
     <booktique:amount>100</booktique:amount> 

    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/sales/book/258"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/SalesOrder"/> 
     <booktique:bookID rdf:resource="http://booktique.com/books/258"/> 
     <booktique:amount>12</booktique:amount> 

    </rdf:Description> 

    <rdf:Description rdf:about="http://booktique.com/sales/book/356"> 
     <rdf:type rdf:resource="http://booktique.com/Resource/SalesOrder"/> 
     <booktique:bookID rdf:resource="http://booktique.com/books/356"/> 
     <booktique:amount>20</booktique:amount> 

    </rdf:Description> 

JENA代碼:

static void sparqltest() 

{

FileManager.get().addLocatorClassLoader(Test.class.getClassLoader()); 
Model model= FileManager.get().loadModel("booktique.rdf"); 
String queryString="PREFIX rdf:<http://www.w3.org/2001/booktique-rdf/3.0#>"+ 
"SELECT * WHERE {?s rdf:amount ?x."+ 
        "FILTER (?x<30)}"; 
Query query= QueryFactory.create(queryString); 
QueryExecution qexec=QueryExecutionFactory.create(query, model); 

try { ResultSet results = qexec.execSelect();while (results.hasNext()){ QuerySolution soln = results.nextSolution(); Literal amount = soln.getLiteral("x"); System.out.println(amount); } }

我檢查了Apache Web站點和許多網站,無論我試過我解決不了的疑難問題有2個源,其量小於30.So我怎樣才能解決這個問題? 謝謝。

+0

難道是因爲一些缺失空格而導致查詢失敗?你的字符串連接沒有空格。 – marstran

+0

@marstan你的意思是空位嗎? – ekn

+0

您的查詢看起來像這樣:'PREFIX rdf: SELECT * WHERE {?s rdf:amount?x.FILTER(?x <30) }'。我不確定,但是在'>'和'S'之間以及'.'和'F'之間是否有空格? – marstran

回答

0

<booktique:amount>12</booktique:amount>是一個帶有字符「1」和「2」的字符串值。這不是一個數字。

您需要:

  1. 在數據,給屬性值數據類型。
  2. 將其轉換爲查詢中的整數xsd:integrer(?x) < 30