1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# sisudoc-ocda-lib
The **object-centric document abstraction as a library**: the model, and
loaders for each of the forms it is written in.
**One implementation per language, in a directory named for the language.**
Written by Claude (Anthropic), working in Claude Code from the specification,
at the direction of and reviewed by Ralph Amissah.
| | |
|--------------------|---------|
| [`dlang/`](dlang/) | D |
| [`gleam/`](gleam/) | Gleam |
## What it is for
The first programs written from the specification were two readers,
`sisudoc-ssp-reader` and `sisudoc-ocda-db-reader`, each reading one
serialisation and printing. They are published frozen, as the record of
readers written from the specification alone, and their work is now done by
`ocda-read`, below. A **writer** needs neither: it needs the document.
```
.ssp ─┐
├─> the model ─> a writer
.ocda.db ─┘
```
So this library holds the model and both loaders, and **a writer cannot
tell which serialisation it was handed** - exactly as spine's own writers
cannot, since spine 0.25.0.
That is the whole of the idea. The writers are functions from the model to
bytes, and the reader is a program over the model.
## The reader
```sh
ocda-read [--tree|--html|--llm-text|--llm-jsonl|--images|--verify --image-dir=<d>|
--languages|--files|--report-unknown|--validate]
<file>.ssp | <file>.ocda.db | <file>.sisupod [lang]
```
One reader, in each language, where the two earlier readers had a parser
each. Built on this library, **every mode reads every form, and every mode
that describes the document says the same thing of its `.ssp`, `.ocda.db`
and `.sisupod`**, for every document-language of the markup document
samples. Two modes describe the file instead, and differ as the files do:
`--languages` lists the one language a `.ssp` holds and every language of
the other two, and `--files` finds carried files only in a `.ocda.db`. The
D reader has every mode of both earlier readers; the Gleam one the modes
the Gleam readers had (the summary, `--tree`, `--languages`, `--files`,
`--report-unknown`), and in those **its output is the D one's, byte for
byte**.
It is in each language's `src/read/`, and not part of the library: a
program using the library does not build it (in D, by dub configuration;
in Gleam a dependant compiles it and does not use it, Gleam building
everything in `src/`).
Writing it found one defect in the library: **the database loader could
not say what it had not understood**. It asks for columns by name, and so
never saw the ones it did not ask for, and reported that it had understood
everything. It now counts them on the conditions under which the `.ssp`
writes the same property, and the report is the same from either form.
## The checks that matter
The checks are run over the markup document samples
([sisudoc-spine-samples](https://git.sisudoc.org/sisudoc-spine-samples)),
built by spine with `--show-abstraction --ocda-db --pod2`, which writes each
document's `.ssp`, its `.ocda.db` and its pod.
The claim above is only true if the loaders agree, so the library asks. Two
programs, in each language:
```sh
ocda-agree <doc>.ssp <doc>.ocda.db [lang] # do the two loaders agree?
ocda-dump <file>.ssp|<file>.ocda.db [lang] # the whole model, canonically
```
`agree` compares two models within one language. **`dump` is the stronger
of the two**, and the reason it exists: it writes the entire loaded model
out in a fully determined form, and the D and the Gleam library write it
*byte for byte alike*. So four questions can be asked, all of them with
`diff`, and each holds for every document-language:
| | |
|-----------------------------|---------------|
| D: `.ssp` == `.ocda.db` | **every one** |
| Gleam: `.ssp` == `.ocda.db` | **every one** |
| `.ssp`: D == Gleam | **every one** |
| `.ocda.db`: D == Gleam | **every one** |
None of those held at first.
## What the checks found
### the ten-field check: a blank first text line
An object whose **first text line is blank** lost it. The loader decided
whether to start a new line by asking whether the accumulated text was
empty, which is not the same question as whether a line has been seen. Of
the markup document samples **seven documents have verse opening on a blank
line**, and in every one of them the blank was dropped.
Nothing else had caught it. The two `.ssp` readers had been compared on
*section counts*, which this does not change. It took loading the same
document two ways and comparing the objects.
Fixed here and in the `.ssp` reader, `sisudoc-ssp-reader`, which carried the
same code.
### the whole-model dump: four more
The ten-field check was enough for that and not enough for anything
subtler. Dumping the whole model found four further disagreements between
the two loaders:
1. **`.identifier` and `.anchor`.** The `.ssp` emits a property only when it
carries information, so the identifier is absent when it is simply the
ocn and the anchor is absent when it is the segment name; the database
stores both unconditionally. Over one document that is **1,314
identifiers and 69 anchors**. The loaders now derive them, which is what
the model means.
2. **`make` and `doc_has`.** The database has one metadata table where the
text form has three blocks, and tells them apart by a key prefix. The
loaders unprefix them, so a writer asks `make["footer"]` whichever
serialisation it was handed.
3. **The JSON columns were scanned rather than parsed.** Phobos writes `/`
as `\/`, so every heading containing a slash came back with a backslash
in it: **every document-language** differed on `heading_ancestors_text`
and nothing else had shown it.
4. **`translation.ocn_aligned`** is in the database and cannot be in a
`.ssp`, which is one language and cannot know whether the languages
share a numbering. It is a fact about the *file*, so the loaders leave
it out rather than letting a writer tell which serialisation it was
given.
The first three are defects. The fourth is a real asymmetry between the two
serialisations, and naming it is the useful part.
## What it reads, and what it does not
| | | |
|-----------------------|------------------------------------------------------------------|-------------------|
| `.ssp` | yes | |
| `.ocda.db` | yes, any language of it | |
| `.sisupod` | yes, any language it carries | D only, see below |
| `.zip` pod | yes, any language it carries | |
| `.sst`, `.ssm` markup | **no, and not planned**: that is a parser, which is spine's work | |
| a url | no | |
A pod carries the abstraction only when spine was asked for it: `--pod2`
puts it in, `--source` does not. A pod without one is refused with a message
saying which flag makes a pod this library can read, because that is a fact
about the pod rather than about the library.
**Over the markup document samples, a `.sisupod` gives the same model as the
`.ssp` beside it, for every document-language: byte identical dumps.** A
writer over the library therefore gained a third input form without being
touched, which is the point of the dispatch being in one place.
### the one thing the Gleam library cannot do
A `.sisupod` is **one zstd frame wrapping** the zip. The D library reads both
through a declared `libzstd`. The Gleam library reads the **zip and not the
frame**, because the only zstd on the BEAM is a NIF that clones zstd from
github in its own build and so cannot be built in a sandbox without patching
it.
So a `.zip` pod is read in both languages, a `.sisupod` in D only, and the
Gleam refusal says why and says `zstd -d` rather than claiming the file is
malformed. It is a packaging limit, not anything about the format, and it is
the only place the two libraries differ in what they accept.
`ocda/load` is the one place in each language that decides what a path is,
so a new input form is added once and every reader and writer gains it.
## Building and use
`nix build` in `dlang/` or `gleam/`. See [`dlang/README.md`](dlang/README.md)
and [`gleam/README.md`](gleam/README.md) for the modules, the programs and
using the library from another program.
## The format
Specified in
[**sisudoc-abstraction-format**](https://git.sisudoc.org/sisudoc-abstraction-format):
`ocda-model.md` for the model this library implements, and the two format
specifications for the loaders. Section 4 of
`ocda-db-format-specification.md` gives the column by column correspondence
the `load_db` of each language follows.
At format **2.1**; the library's version follows the format's major and
minor parts.
## License
AGPL-3.0-or-later: the license text is in [`LICENSE`](LICENSE), the notice in
[`COPYRIGHT`](COPYRIGHT).
|