我在测试Androjena api时遇到问题。在我的系统中,我必须通过发送查询来询问dbpedia数据集。
这是我的班级:
.controller('myCtrl', function ($scope) {
$scope.visible = true;
$scope.refresh = '';
});
我用作APi,androjena_O5.jar,arqoid_0.5.jar,icu4j-3.4.5.jar,iri-0.8.jar,lucenoid_3.0.2,sl4j-android-1.6.1-RC1.jar
但是当我执行代码时,我收到了这个错误:
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.ResultSetFactory;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
import android.os.AsyncTask;
public class QueryDBpedia extends AsyncTask <String, Void, List<String>>{
//@Override
protected List<String> doInBackground(String... keyword) {
List<String> list=null;
String sparqlQuery=
"PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"prefix foaf: <http://xmlns.com/foaf/0.1/> \n"+
"select distinct ?Nom ?resource ?url where {\n" +
"?resource rdfs:label ?Nom.\n" +
"?resource foaf:isPrimaryTopicOf ?url.\n" +
"FILTER langMatches( lang(?Nom), \"EN\" ).\n" +
"?Nom <bif:contains> \"Apple\".\n"+
"} LIMIT 10" ;
System.out.println(sparqlQuery);
String service= "http://dbpedia.org/sparql";
Query qur=QueryFactory.create(sparqlQuery);
QueryExecution exec =QueryExecutionFactory.sparqlService(service,qur );
try{
ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );
while ( results.hasNext() ) {
RDFNode s= results.next().get( "resource" );
list.add(s.toString());
System.out.print(s.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
finally{exec.close();}
return list;
}}}
似乎它是一个api的问题,可以帮助我