我正在尝试获取在端点linkedlifedata.com/sparql 上进行的查询的结果集,而我要获取的对象是“指示”,它是一个段落。我如何在netbeans中打印它?代码是: -
String qs1 = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>"+
"PREFIX drugbank: <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/>"+
"select ?indication"+
"where {"+
"?drug drugbank:indication ?indication."+
"?drug drugbank:genericName ?drugname."+
"filter(regex(?drugname, 'Omalizumab','i'))"+
"}LIMIT 100 ";
com.hp.hpl.jena.query.Query query = QueryFactory.create(qs1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://linkedlifedata.com/sparql", query);
String o;
try{
ResultSet results = qexec.execSelect();
for ( ; results.hasNext() ; )
{
QuerySolution soln = results.nextSolution() ;
o = soln.get("indication").toString();
System.out.println(o);
}
}
finally {
qexec.close();
}
}
我应用了上述方法。但它显示空指针异常。查询运行良好(在端点上检查)。我之前使用 isLiteral() 函数获得了药物名称(一个小字符串),但是对于作为段落的“指示”,它没有发生。PLZ帮助,这是紧急的。谢谢