BindingSet changes in version 6

I have seen that good old org.openrdf.query.BindingSet has been wraped/replaced by com.stardog.stark.query.BindingSet in Stardog 6.

I used to do something similar to:

TupleQueryResult qResult = query.execute()) {
      while (qResult.hasNext()) {
          BindingSet bindingSet =;
          // Check first if getValue() is not null or face NullPointer
          String val = bindingSet.getValue("label").stringValue()

Now it seems I can do something similar:
String val = bindingSet.get("label").toString()

But this is now giving me additional datatype information, such as: ^^<>

My questions are:

  • Is what I am doing the most efficient way to get the results from a query?
  • How can I simply get the value, with no associated datatype, as I used to?

(By the way, the latest DOCs are outdated, they still use TupleQueryResult)

I have found a way for the second question, although I'm not sure this is the right way:
String val = bindingSet.literal("label").get().label()

To retrieve the string value or label of a Value, it's best practice to use the static Value.lex(Value v) method. That handles not only Literal values, but also BNodes. The stark BindingSet methods now return a Java 8 Optional of the value, so you can easily deal with that by doing:

String val = bindingSet.literal("label").map(Value::lex)

As far as the most efficient way to get the results from a query, the stark suite also supports Java 8's Stream, which allows for some functional and efficient result processing:

try(SelectQueryResult r = query.execute()) {
    .map(bindingSet -> bindingSet.literal("label").map(Value::lex))
1 Like

Thanks. I realised late that it was an Optional. Thanks for confirming the way to deal with it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.