def hash_nanopub(nanopub: Mapping[str, Any]) -> str:
hash_list = []<EOL>hash_list.append(nanopub["<STR_LIT>"]["<STR_LIT:type>"].get("<STR_LIT:name>", "<STR_LIT>").strip())<EOL>hash_list.append(nanopub["<STR_LIT>"]["<STR_LIT:type>"].get("<STR_LIT:version>", "<STR_LIT>").strip())<EOL>if nanopub["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT>", False):<EOL><INDENT>hash_list.append(<EOL>nanopub["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT:name>", "<STR_LIT>").strip()<EOL>)<EOL>hash_list.append(<EOL>nanopub["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT:id>", "<STR_LIT>").strip()<EOL>)<EOL><DEDENT>elif nanopub["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT>", False):<EOL><INDENT>hash_list.append(nanopub["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT>", "<STR_LIT>").strip())<EOL><DEDENT>elif nanopub["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT>", False):<EOL><INDENT>hash_list.append(nanopub["<STR_LIT>"]["<STR_LIT>"].get("<STR_LIT>", "<STR_LIT>").strip())<EOL><DEDENT>assertions = []<EOL>for assertion in nanopub["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>if assertion.get("<STR_LIT>") is None:<EOL><INDENT>assertion["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>if assertion.get("<STR_LIT:object>") is None:<EOL><INDENT>assertion["<STR_LIT:object>"] = "<STR_LIT>"<EOL><DEDENT>assertions.append(<EOL>"<STR_LIT:U+0020>".join(<EOL>(<EOL>assertion["<STR_LIT>"].strip(),<EOL>assertion.get("<STR_LIT>", "<STR_LIT>").strip(),<EOL>assertion.get("<STR_LIT:object>", "<STR_LIT>").strip(),<EOL>)<EOL>).strip()<EOL>)<EOL><DEDENT>assertions = sorted(assertions)<EOL>hash_list.extend(assertions)<EOL>annotations = []<EOL>for anno in nanopub["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>annotations.append(<EOL>"<STR_LIT:U+0020>".join((anno.get("<STR_LIT:type>", "<STR_LIT>").strip(), anno.get("<STR_LIT:id>", "<STR_LIT>").strip())).strip()<EOL>)<EOL><DEDENT>annotations = sorted(annotations)<EOL>hash_list.extend(annotations)<EOL>np_string = "<STR_LIT:U+0020>".join([l.lower() for l in hash_list])<EOL>return "<STR_LIT>".format(CityHash64(np_string))<EOL>
Create CityHash64 from nanopub for duplicate check

    TODO - check that this hash value is consistent between C# and Python running on
    laptop and server

    Build string to hash

    Collect flat array of (all values.strip()):
        nanopub.type.name
        nanopub.type.version

        One of:
            nanopub.citation.database.name
            nanopub.citation.database.id

            OR

            nanopub.citation.database.uri

            OR

            nanopub.citation.database.reference

        Extend with sorted list of assertions (SRO as single string with space between S, R and O)

        Extend with sorted list of annotations (nanopub.annotations.type + ' ' + nanopub.annotations.id)

    Convert array to string by joining array elements separated by a space

    Create CityHash64(str) and return