问题
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) {
}
}
}
here the problem i am facing in this code is that bif:contains is showing error, i even tried then also my problem continues.
回答1:
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
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.
来源:https://stackoverflow.com/questions/15876916/bifcontain-error-occurs-when-try-to-query-dbpedia-through-my-java-program