88def load_file (path_or_url , started = False , http_kwargs = {}):
99 try :
1010 data = jsonld .expand (path_or_url )
11+ if len (data ) == 1 :
12+ if "@id" not in data [0 ]:
13+ data [0 ]["@id" ] = path_or_url
1114 except jsonld .JsonLdError as e :
1215 if 'only "http" and "https"' in str (e ):
1316 lgr .debug ("Reloading with local server" )
@@ -18,7 +21,9 @@ def load_file(path_or_url, started=False, http_kwargs={}):
1821 if "port" not in http_kwargs :
1922 raise KeyError ("port key missing in http_kwargs" )
2023 port = http_kwargs ["port" ]
21- base_url = f"http://localhost:{ port } /{ root } /"
24+ base_url = f"http://localhost:{ port } /"
25+ if root :
26+ base_url += f"{ root } /"
2227 with open (path_or_url ) as json_file :
2328 data = json .load (json_file )
2429 try :
@@ -28,6 +33,9 @@ def load_file(path_or_url, started=False, http_kwargs={}):
2833 finally :
2934 if not started :
3035 stop_server (stop )
36+ if len (data ) == 1 :
37+ if "@id" not in data [0 ]:
38+ data [0 ]["@id" ] = base_url + os .path .basename (path_or_url )
3139 else :
3240 raise
3341 return data
@@ -99,5 +107,10 @@ def to_newformat(path, format):
99107 import rdflib as rl
100108
101109 g = rl .Graph ()
110+ g .bind ("rs" , "http://schema.repronim.org/" )
111+ g .bind ("sdo" , "http://schema.org/" )
112+ g .bind ("nidm" , "http://purl.org/nidash/nidm#" )
113+ g .bind ("skos" , "http://www.w3.org/2004/02/skos/core#" )
114+ g .bind ("prov" , "http://www.w3.org/ns/prov#" )
102115 g .parse (data = nt , format = "nt" )
103116 return g .serialize (format = format ).decode ()
0 commit comments