jena sparql过滤器doen没有给出任何输出

问题描述:

我有一个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 '和'S'之间以及'.'和'F'之间是否有空格? – marstran

<booktique:amount>12</booktique:amount>是一个带有字符“1”和“2”的字符串值。这不是一个数字。

您需要:

  1. 在数据,给属性值数据类型。
  2. 将其转换为查询中的整数xsd:integrer(?x) < 30