Off the top of my head a simple way to do this for a Model is something like this:
Model model = ... // your model with blank nodes
Model converted = model.stream.map(st -> convert(st)).collect(ModelCollector.toModel());
Statement convert(Statement st) {
var subject = st.getSubject();
var object = st.getObject();
if (!(subject.isBNode() || object.isBNode())) {
return st;
}
IRI newSubject = subject.isBNode() ? Values.iri("http://example.org/", subject.stringValue()) : (IRI) subject;
Value newObject = object.isBNode() ? Values.iri("http://example.org/", object.stringValue()) : object;
return Values.statement(newSubject, st.getPredicate(), newObject, st.getContext());
}
Of course, what's also possible is to do the conversion while parsing (so before you even have created a Model object for it), something like this:
RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
Model model = new TreeModel();
parser.setRDFHandler(new StatementCollector(model));
parser.parse(input);
model.forEach(System.out::println); // will print out the model to show all bnodes converted to IRIs
Cheers,
Jeen