Skip to content

Conversation

@MSattrtand
Copy link
Collaborator

Resolves kbss-cvut/s-pipes-editor-ui#203

There are no parameters that would satisfy our requirements in the standard Jena Writer, so I had to implement our own version of the serialiser.

@MSattrtand MSattrtand requested a review from blcham August 14, 2025 10:18
@blcham
Copy link
Contributor

blcham commented Oct 16, 2025

@MSattrtand we need to make a plan how to do it in a manageable way ...

@MSattrtand MSattrtand force-pushed the improve-script-format branch from dacec8e to e68da6f Compare October 22, 2025 11:51
Copy link
Contributor

@blcham blcham left a comment

Choose a reason for hiding this comment

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

see my comments

@MSattrtand
Copy link
Collaborator Author

MSattrtand commented Oct 23, 2025

In SPipesNodeFormatter:

formatNode is an entry point for formatting any node. It decides what to do next based on the node type. If the node is not a literal or a blank node, we can delegate its formatting to NodeFormatterTTL from Jena

formatBlank handles blank nodes specifically. In short, it decides whether to inline the blank node as a property list (when it is used only once) or to assign/print a label (when it is referenced multiple times). It first checks if a stable label has already been assigned in bnodeLabels and prints that directly. If not, it looks at the node’s in‑degree: nodes with in‑degree ≤1 are expanded inline with their properties, while nodes with higher in‑degree are given a label (_:bX) so that all references remain consistent.

formatLiteral handles literals. If it's not a multiline literal, it's delegated to NodeFormatterTTL. If it is, then it prints it itself.

formatBNodeAsPropertyList expands a blank node inline as a Turtle property list.

printProperty prints a single predicate–object pair inside a property list.

formatPredicate: If it's an rdf:type predicate, then it prints "a"; otherwise, it's delegated to NodeFormatterTTL

In SPipesFormatter:

assignBNodeLabels iterates over all subjects in the graph. For each blank node that is referenced more than once, assign some stable label, like _:b0.

buildSubjectMap iterates over all triples in the graph, tracks how many times each blank node is referenced as an object.

writeTo is an entry point for serialisation. Writes prefixes with the Jena function. Calls writeTriples to serialise the graph body.

writeTriples iterates over the sorted list of subjects. Skips inline‑only blank nodes that are referenced elsewhere. Prints the subject via nodeFormatter. Calls writePredicates to print predicate–object lists. Ends each subject block with . and a newline.

NodeCategory, category, SUBJECT_COMPARATOR and sortSubjects are used to define the ordering of subjects and sort them.

writePredicates Iterates over predicates for a subject. Prints each predicate. Calls formatPredicate. Prints all objects of that predicate. Objects are separated by ",", predicates by ";".

Overall:

SPipesNodeFormatter operates at the level of a single node. It's responsible for using "a" instead of rdf:type and proper blank node formatting.

SPipesFormatter works on a higher level on the whole graph, controls where different blank nodes are defined, keeps the structure of all triples, including keeping rdf:type as a first predicate on the next line after ?s and keeps ";" after every triple, including the last one.

@blcham blcham force-pushed the improve-script-format branch from 4066edb to 9180570 Compare October 24, 2025 11:55
@blcham
Copy link
Contributor

blcham commented Oct 24, 2025

We did not resolve strange behaviour of multiline literals as discussed in #427 (comment)

@blcham blcham merged commit 418f93f into main Oct 24, 2025
3 checks passed
@blcham blcham deleted the improve-script-format branch October 24, 2025 12:53
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.

Change format how to save scripts

3 participants