问题描述
该代码用于从Java程序查询dbpedia,然后在html页面中显示结果
the code is for querying dbpedia from java program and then displaying the result in html page
package jenaamem;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
public class db2
{
static public void main(String...argv)
{
try {
String queryStr = "SELECT * WHERE{ ?s ?p ?o . ?o bif:contains' barack and obama and america' OPTION (score ?sc) } ORDER BY DESC (?sc) LIMIT 10 ";
Query query = QueryFactory.create(queryStr);
// Remote execution.
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
// Set the DBpedia specific timeout.
((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
// Execute.
ResultSet rs = qexec.execSelect();
ResultSetFormatter.out(System.out, rs, query);
qexec.close();
} catch (Exception e) {
}
}
}
此处我在此代码中面临的问题是bif:contains显示错误,我什至尝试过然后我的问题仍在继续。
here the problem i am facing in this code is that bif:contains is showing error, i even tried then also my problem continues.
推荐答案
bif:contains
是带前缀的名称,但您还没有t为其定义了前缀,因此ARQ解析器会抛出错误,
bif:contains
is a prefixed name but you haven't defined a prefix for it so the ARQ parser throws an error as it should
不幸的是, bif:contains
是一个Virtuoso特定的扩展名,实际上没有任何关联的前缀,因此您无法定义它。但是,您可以将其包含在<
和>
中,以便ARQ将其视为URI,Virtuoso仍然可以理解即在查询中使用< bif:contains>
。
Unfortunately bif:contains
is a Virtuoso specific extension and doesn't actually have any associated prefix so you can't define it. However you can enclose it in <
and >
so that ARQ treats it like a URI and Virtuoso will still understand it i.e. use <bif:contains>
in your query instead.
这篇关于尝试通过我的Java程序查询dbpedia时发生bif:contain错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!