Skip to content

Wrong parents for items with keys containing bracketed text #38

Description

@xadler1

Hello, I have sumbled upon a bug in code generating skos structure dump.

The python script assumes that keys consist of only single characters and therefore removing last character always yields its parent. This works fine most of the time, but several key subtrees contain bracketed text.

        for k in obj.get("K", {}).get("S", []):
            thek = ""
            theuri = nn
            for kk in k:
                thek = thek + kk
                lastk = f"{nn}(+{thek})"
                kuri = f"http://iconclass.org/{quote(lastk)}"
                nuri = f"http://iconclass.org/{quote(theuri)}"
                F.write(
                    f"<{nuri}> <http://www.w3.org/2004/02/skos/core#narrower> <{kuri}> .\n"
                )
                F.write(
                    f"<{kuri}> <http://www.w3.org/2004/02/skos/core#broader> <{nuri}> .\n"
                )
                theuri = lastk

This results in an incorrect parent structure, for example items
https://iconclass.org/25D3(+2(...)).json
https://iconclass.org/49D352(...)(+52(GYROSCOPE)).json
have nonexistent parents.

A crude but working fix could be something like:

        for k in obj.get("K", {}).get("S", []):
            thek = ""
            theuri = nn
            openpar = false
            for kk in k:
                if not openpar and kk == "(":
                    openpar = True
                    continue
                if openpar and kk == ")":
                    openpar = False
                if openpar:
                    continue

                thek = thek + kk
                lastk = f"{nn}(+{thek})"
                kuri = f"http://iconclass.org/{quote(lastk)}"
                nuri = f"http://iconclass.org/{quote(theuri)}"
                F.write(
                    f"<{nuri}> <http://www.w3.org/2004/02/skos/core#narrower> <{kuri}> .\n"
                )
                F.write(
                    f"<{kuri}> <http://www.w3.org/2004/02/skos/core#broader> <{nuri}> .\n"
                )
                theuri = lastk

This should work for any bracketed text which doesn't contain parenthesis.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions