我是sementic网站的新手。我试图在文件上写入SPARQL描述查询的结果。我一次又一次得到一行。有人可以帮我解决这个问题。
如果选择是最佳选择,请告知我。
public void getResourceDescription(String rname){
String desptstring ="Prefix dbo: <http://dbpedia.org/resource/>\n" +
"Describe ?r where{" +
" <"+rname+"> ?r ?o." +
"}";
Writer writer = null;
Query des_query = QueryFactory.create(desptstring);
QueryExecution des_Exe = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", des_query);
try {
Model model = des_Exe.execDescribe();
//model = (Model) set;
//ResultSet description_result = des_Exe.execSelect();
StringWriter strwrt = new StringWriter();
//for ( ; description_result.hasNext() ; ) {
//QuerySolution res = description_result.nextSolution();
Abbreviated abb = new Abbreviated();
abb.write(model, strwrt, null);
//System.out.println(res);
File file = new File("D:\\newfile.txt");
file.createNewFile();
Files.write(Paths.get("D:\\newfile.txt"), strwrt.toString().getBytes(), StandardOpenOption.APPEND);
// }
}
catch (Exception e) {
e.printStackTrace();
}
finally {
des_Exe.close();
}
} // ending of the GetResourceDescription Method