Skip to content

Commit

Permalink
switch to pyld to do flatten/compaction, add codemeta to context
Browse files Browse the repository at this point in the history
  • Loading branch information
dansand committed Apr 26, 2024
1 parent afd432a commit ee593b7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/scripts/write_repo_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io
import json
from datetime import datetime
from pyld import jsonld



# Environment variables
Expand Down Expand Up @@ -38,11 +40,25 @@
# Convert dictionary to metadata json
metadata = dict_to_metadata(data, flat_compact_crate=False, timestamp= timestamp)

try:
flattened = jsonld.flatten(json.loads(rocrate))
#compact against the default schemas:
default_context = rocratedict['@context']
#compacted = jsonld.compact(flattened,
# ctx = ["https://w3id.org/ro/crate/1.1/context",
# "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld"])
flat_compacted = jsonld.compact(flattened,
ctx = default_context)

except:
flat_compacted = dict_to_metadata(data, flat_compact_crate=True, timestamp= timestamp)


#FOR TESTING - print out dictionary as a comment
issue.create_comment("# M@TE crate \n"+str(metadata))

# Move files to repo
model_repo.create_file("ro-crate-metadata.json","add ro-crate",metadata)
model_repo.create_file("ro-crate-metadata.json","add ro-crate",flat_compacted)
#we should do this this as part of the copy to website action
model_repo.create_file("website_material/ro-crate-metadata.json","add ro-crate",metadata)

Expand Down

0 comments on commit ee593b7

Please sign in to comment.