I'm attempting to do some graph normalization following the URDNA2015 algorithm.
If I'm understanding the spec, blank nodes should have labels like _:c14nX where X is an incrementing counter.
I can produce a graph that has blank nodes with these labels, but when serializing the graph to NTRIPLES these run through NodeFmtLib#encodeBNodeLabel which performs some encoding -- at the very least always prefixes the resulting node with 'B'. For example c14n92 -> Bc14n92 or _:c14n92 -> BX5FX3Ac14n92 due to hex encoding.
My serialization code is very basic currently:
StringWriter sw = new StringWriter();
RDFDataMgr.write(sw, normalizedGraph, Lang.NTRIPLES);
What is the suggested way of having finer control over this serialization?
EDIT: One approach I found that works, but I'm not sure if it is the recommended way:
RDFWriterRegistry.register(RDFFormat.NTRIPLES_UTF8, new CustomWriterGraphRIOTFactory());
Then implement a chain of classes that override:
- WriterGraphRIOTFactory
- NTriplesWriter
- StreamRDFLib
- WriterStreamRDFPlain
- NodeFormatter
to ultimately get to a place of overriding formatBNode:
public class CustomNodeFormatter extends NodeFormatterNT {
public CustomNodeFormatter(CharSpace charSpace) {
super(charSpace);
}
@Override
public void formatBNode(AWriter w, String label) {
w.print(label);
}
}