Skip to content

Commit

Permalink
small ugly hack rewriting context to force our rdf implementation to …
Browse files Browse the repository at this point in the history
…fully serialize codemeta:referencePublication #18
  • Loading branch information
proycon committed Aug 25, 2022
1 parent fc3b599 commit 96c1b38
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion codemeta/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ def init_context(no_cache=False):
r = requests.get(remote, headers={ "Accept": "application/json+ld;q=1.0,application/json;q=0.9,text/plain;q=0.5" })
r.raise_for_status()
with open(localfile, 'wb') as f:
f.write(r.content.replace(b'"softwareRequirements": { "@id": "schema:softwareRequirements", "@type": "@id"},',b'"softwareRequirements": { "@id": "schema:softwareRequirements" },'))
f.write(r.content.replace(b'"softwareRequirements": { "@id": "schema:softwareRequirements", "@type": "@id"},',b'"softwareRequirements": { "@id": "schema:softwareRequirements" },') \
# ^-- rdflib gets confused by this definition in codemeta which we already
# have in schema .org(without an extra @type: @id), ensure the two are
# equal (without the @type)
.replace(b'"referencePublication": { "@id": "codemeta:referencePublication", "@type": "@id"},',b'"referencePublication": { "@id": "codemeta:referencePublication" },'))
# ^--- with rdflib @type: @id here, rdflib (and our code) doesn't embed the full referencePublication as we want. Trick the serialiser by rewriting this part of the context.


def bind_graph(g: Graph):
g.bind('schema', SDO)
Expand Down

0 comments on commit 96c1b38

Please sign in to comment.