Skip to content

Commit ee593b7

Browse files
committed
switch to pyld to do flatten/compaction, add codemeta to context
1 parent afd432a commit ee593b7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

.github/scripts/write_repo_contents.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io
1010
import json
1111
from datetime import datetime
12+
from pyld import jsonld
13+
1214

1315

1416
# Environment variables
@@ -38,11 +40,25 @@
3840
# Convert dictionary to metadata json
3941
metadata = dict_to_metadata(data, flat_compact_crate=False, timestamp= timestamp)
4042

43+
try:
44+
flattened = jsonld.flatten(json.loads(rocrate))
45+
#compact against the default schemas:
46+
default_context = rocratedict['@context']
47+
#compacted = jsonld.compact(flattened,
48+
# ctx = ["https://w3id.org/ro/crate/1.1/context",
49+
# "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld"])
50+
flat_compacted = jsonld.compact(flattened,
51+
ctx = default_context)
52+
53+
except:
54+
flat_compacted = dict_to_metadata(data, flat_compact_crate=True, timestamp= timestamp)
55+
56+
4157
#FOR TESTING - print out dictionary as a comment
4258
issue.create_comment("# M@TE crate \n"+str(metadata))
4359

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

0 commit comments

Comments
 (0)