-
Notifications
You must be signed in to change notification settings - Fork 5
Changed format how to save scripts #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@MSattrtand we need to make a plan how to do it in a manageable way ... |
dacec8e to
e68da6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments
s-pipes-core/src/test/java/cz/cvut/spipes/util/JenaUtilsTest.java
Outdated
Show resolved
Hide resolved
s-pipes-core/src/main/java/cz/cvut/spipes/util/SPipesTurtleWriter.java
Outdated
Show resolved
Hide resolved
|
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. |
s-pipes-core/src/main/java/cz/cvut/spipes/util/SPipesNodeFormatter.java
Outdated
Show resolved
Hide resolved
4066edb to
9180570
Compare
|
We did not resolve strange behaviour of multiline literals as discussed in #427 (comment) |
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.