Skip to content

Implement stable blank node ordering#66

Merged
atextor merged 2 commits into
cool-rdf:mainfrom
fkleedorfer:stable-blanknode-ordering
Jul 11, 2026
Merged

Implement stable blank node ordering#66
atextor merged 2 commits into
cool-rdf:mainfrom
fkleedorfer:stable-blanknode-ordering

Conversation

@fkleedorfer

Copy link
Copy Markdown
Contributor

Blank node ordering had been stable if formatting a preexisting serialization, but not stable for an in-memory graph. This commit introduces partial ordering of blank nodes - those that are to be serialized as siblings. Their ordering is based on a key calculated from the triples they appear in. If needed for disambiguation, this is done recursively 3 times. After that, blank nodes compare as equal and will be ordered randomly. Bnode comparison keys are cached in a bounded map holding 100 x max 3 keys (one for each recursion layer).

Blank node ordering had been consistent if formatting a preexisting ordering, but not predictable for an in-memory graph. This commit introduces partial ordering of blank nodes - those that are to be serialized as siblings. Their ordering is based on a key calculated from the triples they appear in. If needed for disambiguation, this is done recursively 3 times. After that, blank nodes compare as equal and will be ordered randomly. Bnode comparison keys are cached in a bounded map holding 100 x max 3 keys (one for each recursion layer).
@fkleedorfer
fkleedorfer force-pushed the stable-blanknode-ordering branch 2 times, most recently from fa98e04 to b69aac0 Compare July 8, 2026 13:10
@fkleedorfer

fkleedorfer commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@atextor The PR for diffplug/spotless is already underway, but I don't want to merge before we get this PR here into a cool-rdf release (if you want it), so spotless can use the stable blank node order when the PR there is merged.

The formatting style option `preserveBlankNodeLabelsAndOrdering` (default `true`) is added that governs whether the ordering and labels of blank nodes found in the source document is to be used or overriden according to the result of the stable blank node ordering algorithm. When `false` rdf parsing is done without using the blank node aware parser necessary for preserving ordering and labels.
@fkleedorfer

Copy link
Copy Markdown
Contributor Author

Done

@atextor atextor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for your contribution @fkleedorfer !

@atextor
atextor merged commit 42064bc into cool-rdf:main Jul 11, 2026
1 check passed
@atextor

atextor commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

@atextor The PR for diffplug/spotless is already underway, but I don't want to merge before we get this PR here into a cool-rdf release (if you want it), so spotless can use the stable blank node order when the PR there is merged.

For completness' sake: Yes, I'd like to do a release with the fix as soon as I have time for it.

@atextor

atextor commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

@fkleedorfer cool-rdf 2.0.1 including the fix has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants