Skip to content

Commit

Permalink
DATS metadata standards; pre loading JSON to avoid parsing errors aft…
Browse files Browse the repository at this point in the history
…erwards and to preserve remote @context URIs
  • Loading branch information
huberrob committed Nov 11, 2024
1 parent ed7a857 commit d14a7c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions fuji_server/controllers/fair_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ def harvest_all_metadata(self):
# self.retrieve_apis_standards()
# remove duplicates
if self.namespace_uri:
self.namespace_uri = [
ns for ns in self.namespace_uri if not isinstance(ns, list) and not isinstance(ns, dict)
]
self.namespace_uri = list(set(self.namespace_uri))

def harvest_re3_data(self):
Expand Down
14 changes: 6 additions & 8 deletions fuji_server/helper/metadata_collector_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ def set_namespaces(self, graph):
r"https?:\/\/vocab\.nerc\.ac\.uk\/collection\/[A-Z][0-9]+\/current\/",
r"https?:\/\/purl\.obolibrary\.org\/obo\/[a-z]+(\.owl|#)",
]
print(type(graph))

if isinstance(graph, rdflib.ConjunctiveGraph):
for c in graph.contexts():
print("CONTEXT: ", c)
try:
nm = graph.namespace_manager
possible = set(graph.predicates()).union(graph.objects(None, RDF.type))
Expand Down Expand Up @@ -293,16 +288,19 @@ def parse_metadata(self):
% (jsonld_source_url)
)
try:
print("#####################################", type(rdf_response))
# pre-check for valid json
json_valid = False
try:
json_ = json.loads(rdf_response)
if isinstance(json_, dict):
# add @context URIs to namespaces which are otherwise lost
if isinstance(json_.get("@context"), list):
self.namespaces.extend(json_.get("@context"))
elif json_.get("@context"):
for j_ctx in json_.get("@context"):
if isinstance(j_ctx, str):
self.namespaces.append(str(j_ctx))
elif isinstance(j_ctx, dict):
self.namespaces.extend(j_ctx.values())
elif isinstance(json_.get("@context"), str):
self.namespaces.append(str(json_.get("@context")))
json_valid = True
except Exception:
Expand Down

0 comments on commit d14a7c4

Please sign in to comment.