(rdf4j-stardog) API mapping of BNodes modifying their IDs

Hi all, when mapping data from RDF4J to the Stardog model implementation and vice versa, the methods used to convert Values seem to be modifying bNodes IDs. E.g.:

    if (theValue instanceof com.stardog.stark.BNode) {
                return SimpleValueFactory.getInstance().createBNode(theValue.toString());

If my initial value was a bNode with the ID _:b0 a new bNode with the ID _:_:b0 is created.

I encountered this behaviour in both the toSesameValue() and toRDF4jValue() methods.

I think a solution to this could be casting the value to a BNode to obtain its ID and then using that value to create the new instance. E.g.:

    if ( theValue instanceof com.stardog.stark.BNode ) {
    	return SimpleValueFactory.getInstance().createBNode( ( (BNodeImpl) theValue ).id() );

I'm currently working with Stardog v6.1.2


In the case of passing the stark BNode into createBNode, you will want to use theValue.id() instead of theValue.toString(), as toString() returns the prefixed ID (_:b0) and id() would return just the "b0" part.

Edit: This is exactly what you suggested. That is the right way. I had somehow missed that theValue was of type Value and not explicitly BNode.

Instead of editing my reply again, I'll just post that we also provide a nicer way to accomplish this. You can use the static method Value.lex(theValue) to return just the ID. In fact this situation was one of the ones that method was specifically created for