经过几个小时的调试后,我在这里写... 以下代码不是
public String search(@QueryParam("query") String search_string, @QueryParam("match_type") @DefaultValue("") String match_type, @QueryParam("terminology") @DefaultValue("") List<String> terminology_list)
throws ServletException, IOException
{
VirtGraph set = new VirtGraph (hostURL, userName, password);
ByteArrayOutputStream out = new ByteArrayOutputStream();
search_string = search_string.replaceAll(java.util.regex.Pattern.quote(" "), " and ") ;
String text="";
for(String term_items:terminology_list) {
if(!match_type.equals("exact")) {
text="select ?uri, ?label where { " +
"quad map virtrdf:DefaultQuadMap " +
"{ graph ?g { ?uri ?p ?label . ?label bif:contains '" +
search_string +
"' option ( score ?sc ) . }}} " +
"order by desc ( ?sc * 3e-1 + sql:rnk_scale ( <LONG::IRI_RANK> ( ?uri ) ) ) limit 20 offset 0";
}
else if(match_type.equals("exact")) {
text="select ?uri, ?label where { quad map virtrdf:DefaultQuadMap { graph <"
+term_items+"> { ?uri ?p ?label.FILTER (?label = '"+search_string+"'@en) .}}}";
}
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(text, set);
ResultSet results = vqe.execSelect();
ResultSetFormatter.outputAsJSON(out, results);
}
return out.toString();
}
问题出现在else if
语句中,因为无论我在链接中声明的列表中有多少项,执行结束时的结果集都是空的。
例如,如果在链接中我输入&amp; terminology = test ,则转换为:
text="select ?uri, ?label where { quad map virtrdf:DefaultQuadMap { graph <**test**> { ?uri ?p ?label.FILTER (?label = '"+search_string+"'@en) .}}}";
有趣的是,在端点上运行sparql查询确实会返回结果。只有在eclipse中运行时,它才会发生!
我也不能说else
语句之后的代码中还有任何错误,因为if
语句使用相同的代码并且它正在正常运行..