RDF wyświetla tematy z ich obiektami w jednej linii

Mam plik RDF i muszę wyodrębnić z niego pewne informacje i zapisać je w pliku. Zrozumiałem, jak to działa, ale utknąłem z tym:

String queryString = "select ?person ?children where { ?person ?hasChildren ?children}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();     
while (result.hasNext()) {
    BindingSet bindingSet = result.next();
    Value p1 = bindingSet.getValue("person");
    Value p2 = bindingSet.getValue("child");
    println(p1 + " has children " + p2 +"");
}
result.close();

Otrzymane dane są następujące:

http://example.org/people/person1 has children http://example.org/people/child1
http://example.org/people/person1 has children http://example.org/people/child2

Nie widzę, jak wyświetlić wszystkie osoby z ich obiektami w tym formacie:

person1 has children child1 and child2

Jak można to zrobić?

questionAnswers(1)

yourAnswerToTheQuestion