我有一个返回一些结果的 SPARQL 查询。我需要让用户选择他接下来将使用哪些结果。我已经用扫描仪对此进行了编码,但我现在想将其转换为 JOptionPane 对话框,以便它对用户更加友好。我认为它是通过JOptionPane.showInputDialog
. 但是,我不知道如何以正确的格式“翻译”JOptionPane 的对象列表中的 Jena ResultSet,然后提取选定的元素。我怎么能做到这一点?
Query query = QueryFactory.create(queryString);
QueryExecution qe= QueryExecutionFactory.create(query, model);
ResultSet resultset = qe.execSelect();
ResultSet results = ResultSetFactory.copyResults(resultset);
final ResultSet results2 = ResultSetFactory.copyResults(results);
System.out.println( "== Available Options ==" );
ResultSetFormatter.out(System.out, results, query);
System.out.println( "== Select Option ==" );
System.out.println( "== Type 0,1,2,3.. to choose Option ==" );
Scanner input = new Scanner( System.in );
final String inputs ;
inputs = input.next();
final String[] indices = inputs.split("\\s*,\\s*");
final List<QuerySolution> selectedSolutions = new ArrayList<QuerySolution>( indices.length ) {{
final List<QuerySolution> solutions = ResultSetFormatter.toList( results2 );
for ( final String index : indices ) {
add( solutions.get( Integer.valueOf( index )));
}
}};
String s = selectedSolutions.toString();
Pattern p = Pattern.compile("#([^>]+)>");
Matcher m = p.matcher(s);