ods_to_rdf¶
ods_to_rdf
¶
Generate compass.ttl and vocab.ttl from a use case's source-data.ods.
COMPASS_USE_CASE (default oceancare) selects the directory under
src/ontology/. Pins link to other rows by id in their links column; the
predicate a link becomes depends on the dimension or class of its target.
Concepts carry no links.
Subject order, predicate order and float precision are fixed, so unchanged input produces byte-identical output.
SheetError
¶
Bases: Exception
A defect in the workbook, to be fixed there.
Row(number, sheet, cells)
dataclass
¶
One non-empty data row of a sheet.
Problems(items=list())
dataclass
¶
Collect workbook defects so one run reports all of them.
Fallbacks(counts=Counter())
dataclass
¶
Count the empty German cells that took the English text.
_resolve_use_case()
¶
Return COMPASS_USE_CASE from the environment, else the repo .env.
Source code in src/turtle-generator/ods_to_rdf.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
repo_relative(path)
¶
Return path relative to the repo root, or absolute if it lies outside.
Source code in src/turtle-generator/ods_to_rdf.py
172 173 174 175 176 177 | |
_cell_text(cell)
¶
Return a cell's stored number if it has one, else its displayed text.
Source code in src/turtle-generator/ods_to_rdf.py
206 207 208 209 210 211 212 213 | |
_row_values(row, width)
¶
Return the first width cell texts of a row, expanding repeated cells.
Source code in src/turtle-generator/ods_to_rdf.py
216 217 218 219 220 221 222 223 224 | |
read_sheet(name, columns)
¶
Read the non-empty rows of a workbook sheet whose header must equal columns.
Raises:
| Type | Description |
|---|---|
SheetError
|
The workbook or sheet is missing or empty, or the header differs. |
Source code in src/turtle-generator/ods_to_rdf.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
index_terms(concepts, pins, problems)
¶
Map every concept and pin id to its dimension or class.
Source code in src/turtle-generator/ods_to_rdf.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
parse_links(row, kinds, problems)
¶
Group the targets in a pin's links cell by the predicate each becomes.
Source code in src/turtle-generator/ods_to_rdf.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
numeric_cell(row, column, problems, parse)
¶
Return the cell text, or "" after reporting a value parse rejects.
Source code in src/turtle-generator/ods_to_rdf.py
319 320 321 322 323 324 325 326 327 328 329 | |
bilingual(row, column, fallbacks)
¶
Return the English and German text of <column>_en / <column>_de.
An empty German cell takes the English text and is noted in fallbacks.
Returns None when the English cell is empty.
Source code in src/turtle-generator/ods_to_rdf.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
order_key(triple)
¶
Sort key: predicate, then language, then value.
Source code in src/turtle-generator/ods_to_rdf.py
447 448 449 450 451 452 453 454 | |
validate(data, vocab)
¶
Raise SheetError unless the generated Turtle conforms to shapes.ttl.
Source code in src/turtle-generator/ods_to_rdf.py
533 534 535 536 537 538 539 540 541 542 543 544 | |
generate(fallbacks)
¶
Return the text of compass.ttl and vocab.ttl, noting German fallbacks.
Raises:
| Type | Description |
|---|---|
SheetError
|
The workbook has defects; the message lists all of them. |
Source code in src/turtle-generator/ods_to_rdf.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
main(argv=None)
¶
Run the command line; return the exit status.
Source code in src/turtle-generator/ods_to_rdf.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |