我有一个rdf文件,我希望看到的数量少于30的书。但它不会产生任何输出。
这是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>brown@gmail.com</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>smith@gmail.com</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网站和许多网站,无论我尝试过什么都无法解决问题。我有2个来源,其数量少于30个。所以我该如何解决这个问题? 感谢。
答案 0 :(得分:0)
<booktique:amount>12</booktique:amount>
是一个包含字符&#34; 1&#34;的字符串值。和&#34; 2&#34;。这不是一个数字。
您需要:
xsd:integrer(?x) < 30
中的整数。