jena sparql 过滤器不提供任何输出
jena sparql filter doen not give any output
我有一个 rdf 文件,我想查看数量少于 30.But 它不产生任何输出的书籍。
这是 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网站和很多网站,怎么解决都解决不了 problem.I 有2个资源少于30.So 我怎么解决这个问题?
谢谢。
<booktique:amount>12</booktique:amount>
是一个包含字符“1”和“2”的字符串值。这不是一个数字。
您需要:
- 在数据中,为 属性 值指定数据类型。
- 在您的查询中将其转换为整数
xsd:integrer(?x) < 30
。
我有一个 rdf 文件,我想查看数量少于 30.But 它不产生任何输出的书籍。
这是 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网站和很多网站,怎么解决都解决不了 problem.I 有2个资源少于30.So 我怎么解决这个问题? 谢谢。
<booktique:amount>12</booktique:amount>
是一个包含字符“1”和“2”的字符串值。这不是一个数字。
您需要:
- 在数据中,为 属性 值指定数据类型。
- 在您的查询中将其转换为整数
xsd:integrer(?x) < 30
。