Skip to content

rescheming 2: electric pakalu#38

Merged
AcipenserSturio merged 8 commits intomainfrom
reschema
May 4, 2025
Merged

rescheming 2: electric pakalu#38
AcipenserSturio merged 8 commits intomainfrom
reschema

Conversation

@hecko-yes
Copy link
Copy Markdown
Collaborator

@hecko-yes hecko-yes commented Apr 24, 2025

changes:

  • original-title and original-authors are now subfields of original (potentially allowing for expansion if desired?)
    • i put it under tags, imagining it as the last entry in a series of "what is the work" followed by "how to get it"; putting it under license might've made as much sense but ¯_(ツ)_/¯
  • all optionals and nullishes have been replaced with nullables, aka every field must be explicitly nulled and can't simply be absent (i still don't like it much but it's what the sturgeon ordered)
    • as a side effect of how i did it it also sorts everything in accordance with the schema which i do like :3

same wrapper code as in #36

inner code used (cc0)
    # original work data nesting
    originables = ["title", "authors"]
    if any(f"original-{k}" in data for k in originables):
        data["original"] = CommentedMap(
            {k: data[f"original-{k}"] for k in originables if f"original-{k}" in data}
        )
        for k in originables:
            if f"original-{k}" in data:
                del data[f"original-{k}"]
        for prev in [
            "tags",
            "date-precision",
            "date",
            "proofreaders",
            "authors",
            "description",
            "title",
        ]:
            if prev in data:
                make_neighbors(prev, "original")
                break

    # universal nullening and sorting
    fields = [
        "title",
        "description",
        "authors",
        "translators",
        "proofreaders",
        "date",
        "tags",
        "original",
        "license",
        "sources",
        "archives",
        "preprocessing",
        "accessibility-notes",
        "notes",
    ]
    for k in fields:
        if k not in data:
            data[k] = None
    for k1, k2 in zip(fields[:-1], fields[1:]):
        make_neighbors(k1, k2)

    originables = ["title", "authors"]
    if data["original"]:

        def make_neighbors_o(anchor_key, move_key):
            to_move = data["original"].pop(move_key)
            pos = list(data["original"].keys()).index(anchor_key)
            data["original"].insert(pos + 1, move_key, to_move)

        for k in originables:
            if k not in data["original"]:
                data["original"][k] = None
        for k1, k2 in zip(originables[:-1], originables[1:]):
            make_neighbors_o(k1, k2)

@AcipenserSturio AcipenserSturio merged commit 471f77d into main May 4, 2025
1 check passed
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