此代码打印: [( ?Random = http://www.semanticweb.org/vassilis/ontologies/2013/5/Test#Hello ), ( ?Random = http://www.semanticweb.org/vassilis/ontologies/ 2013/5/测试#再见)]
我需要一个结果集格式,以便只打印 # 和 > 之间的部分。例如,它应该打印:你好,再见,我该怎么做?提前致谢
public class QuerySolutionsFromIndicesExample {
final static String modelText = "" +
"@prefix bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Onto#>.\n" +
"@prefix ex: <http://example.org/>.\n" +
"\n" +
"ex:Giraffe a bio:Animal .\n" +
"ex:Dog a bio:Animal .\n" +
"ex:Cat a bio:Animal . \n" +
"ex:WoollyMammoth a bio:Animal.\n" +
"";
final static String sparqlQuery = "" +
"prefix bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Onto#>\n" +
"\n" +
"select ?animal where {\n" +
" ?animal a bio:Animal\n" +
"}\n" +
"";
public static void main(String[] args) {
final Model model = ModelFactory.createDefaultModel();
model.read( new ByteArrayInputStream( modelText.getBytes()), null, "TTL" );
final ResultSet results = ResultSetFactory.copyResults( QueryExecutionFactory.create( sparqlQuery, model ).execSelect() );
System.out.println( "== All Solutions ==" );
ResultSetFormatter.out( results );
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( results );
for ( final String index : indices ) {
add( solutions.get( Integer.valueOf( index )));
}
}};
System.out.println( "== Selected Solutions ==" );
System.out.println( selectedSolutions );
}
}