Skip to content

Commit 7acba36

Browse files
authored
Merge branch 'master' into master
2 parents d7052d8 + 3a09b62 commit 7acba36

File tree

8 files changed

+66
-9
lines changed

8 files changed

+66
-9
lines changed

reproschema/jsonldutils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
def 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()

reproschema/tests/contexts/base

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"prov": "http://www.w3.org/ns/prov#",
1313
"pav": "http://purl.org/pav/",
1414
"nidm": "http://purl.org/nidash/nidm#",
15+
"uuid": "http://uuid.repronim.org/",
1516
"reproschema": "http://schema.repronim.org/"
1617
}
1718
}

reproschema/tests/data/activities/activity1.jsonld

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
"es": "Durante las últimas 2 semanas, ¿con qué frecuencia le han molestado los siguintes problemas?"
1313
},
1414
"messages": [
15-
{
16-
"message": "Test message: Triggered when item1 value is greater than 1",
17-
"jsExpression": "item1 > 1"
18-
}
19-
],
15+
{
16+
"message": "Test message: Triggered when item1 value is greater than 1",
17+
"jsExpression": "item1 > 1"
18+
}
19+
],
20+
"compute": [
21+
{
22+
"variableName": "activity1_total_score",
23+
"jsExpression": "item1 + item2"
24+
}
25+
],
2026
"ui": {
2127
"addProperties": [
2228
{ "isAbout": "items/item1.jsonld",

reproschema/tests/data/activities/items/item1.jsonld

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
"value": 3
4949
}
5050
]
51-
}
51+
},
52+
"additionalNotesObj": [
53+
{
54+
"source": "redcap",
55+
"column": "notes",
56+
"value": "some extra note"
57+
}
58+
]
5259

5360
}

reproschema/tests/data/protocols/protocol1_embed.jsonld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"@context": "../../contexts/generic",
2+
"@context": "../../contexts/generic",
33
"@type": "reproschema:Protocol",
44
"@id": "protocol1.jsonld",
55
"prefLabel": {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"@context": "../../contexts/generic",
3+
"@type": "reproschema:Response",
4+
"@id": "uuid:fc963765-1f1b-4ad9-bc4b-0d21b9de5acb",
5+
"wasAttributedTo": {
6+
"@id": "uuid:2b0aab3d-495f-4eee-98a5-4284b3268a56",
7+
"subject_id": "6aabb03d-9e5f-ae5e-c4a5-21b9b326868a"
8+
},
9+
"isAbout": "../activities/items/item1.jsonld",
10+
"value": 1
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"@context": "../../contexts/generic",
3+
"@type": "reproschema:ResponseActivity",
4+
"@id": "uuid:96496a96-50d6-4b87-a65e-468420e7c80d",
5+
"used": [
6+
"../activities/items/item1.jsonld",
7+
"../activities/activity1.jsonld",
8+
"../protocols/protocol1.jsonld"
9+
],
10+
"inLanguage": "en",
11+
"startedAtTime": "2020-07-23T22:15:37.675Z",
12+
"endedAtTime": "2020-07-23T22:15:50.293Z",
13+
"wasAssociatedWith": {
14+
"version": "0.0.1",
15+
"url": "https://schema.repronim.org/ui/#/",
16+
"@id": "https://github.com/ReproNim/reproschema-ui"
17+
},
18+
"prov:generated": "uuid:85d18360-1787-4d3d-b72e-b543ca9b4b1a"
19+
}

reproschema/tests/test_validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def test_type_error():
1515

1616

1717
def test_url():
18-
url = "https://raw.githubusercontent.com/ReproNim/reproschema-py/master/reproschema/tests/data/activities/activity1.jsonld"
18+
url = "https://raw.githubusercontent.com/ReproNim/reproschema/1.0.0-rc1/examples/activities/activity1.jsonld"
1919
assert validate(os.path.abspath("reproschema-shacl.ttl"), url)

0 commit comments

Comments
 (0)