Skip to content

Commit

Permalink
[#76] implement toString() method to show basic type of variables whe…
Browse files Browse the repository at this point in the history
…n logging variable binding
  • Loading branch information
palagdan authored and blcham committed Aug 14, 2024
1 parent fe991de commit 88f2231
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,29 @@ public void load(final InputStream is, final String lang) throws IOException {

@Override
public String toString() {
return binding.asMap().toString();
return binding.asMap()
.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> toString(e.getValue())
))
.toString();
}

private static String toString(RDFNode node) {
if (node.isLiteral()) {
return "\"" + node.asLiteral().getLexicalForm() + "\"";
} else if (node.isURIResource() || node.isResource()) {
return "<" + node.asResource().getURI() + ">";
} else {
return node.toString();
}
}

public String toTruncatedString() {
return binding.asMap().entrySet().stream()
.map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), getTruncatedValue(e.getValue().toString()))).
.map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), getTruncatedValue(toString(e.getValue())))).
collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString();
}

Expand Down

0 comments on commit 88f2231

Please sign in to comment.