Skip to content

Commit 8b40695

Browse files
committed
initial commit -- working but incomplete schemas
0 parents  commit 8b40695

23 files changed

+710
-0
lines changed

definitions.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Dataset": {
3+
"properties": [
4+
["study", "nimads:Study"]
5+
]
6+
},
7+
"Study": {
8+
"properties": [
9+
["analysis", "nimads:Analysis"],
10+
["publication", "schema:ScholarlyArticle"],
11+
["condition", "nimads:Condition"]
12+
]
13+
},
14+
"Analysis": {
15+
"properties": [
16+
["image", "nimads:Image"],
17+
["point", "nimads:Point"],
18+
["condition", "nimads:Condition"],
19+
["weight", "schema:Float"]
20+
]
21+
},
22+
"Point": {
23+
"properties": [
24+
["coordinates", "nimads:Coordinates"],
25+
["space", "schema:Text"],
26+
["value", "nimads:Value"],
27+
["type", "schema:Text"]
28+
]
29+
},
30+
"Value": {
31+
"properties": [
32+
["type", "schema:Text"],
33+
["value", "schema:Float"]
34+
]
35+
},
36+
"Image": {
37+
"properties": [
38+
["space", "schema:Text"],
39+
["path", "schema:Text"],
40+
["valueType", "schema:Text"]
41+
]
42+
},
43+
"Condition": {
44+
"properties": []
45+
}
46+
}

generate_jsonld.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import json
2+
from collections import defaultdict
3+
import os
4+
5+
defs = json.load(open('definitions.json', 'r'))
6+
7+
classes = defaultdict(list)
8+
props = defaultdict(lambda: defaultdict(list))
9+
10+
wrap = lambda x: "nimads:{}".format(x) if ':' not in x else x
11+
12+
for t_name, data in defs.items():
13+
for p_name, p_type in data['properties']:
14+
## Type properties
15+
classes[t_name].append({
16+
"@id": wrap(p_name),
17+
"schema:domainIncludes": {"@id": wrap(t_name)}
18+
})
19+
# Property mappings
20+
props[p_name]["domainIncludes"].append({"@id": wrap(t_name)})
21+
props[p_name]["rangeIncludes"].append({"@id": wrap(p_type)})
22+
23+
if 'nimads' in p_type:
24+
p_type = p_type.split(':')[1]
25+
classes[p_type].append({
26+
"@id": wrap(p_name),
27+
"schema:rangeIncludes": {"@id": wrap(p_type)}
28+
})
29+
30+
context = {
31+
"schema": "http://schema.org/",
32+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
33+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
34+
"nimads": "http://neurostuff.org/nimads/"
35+
}
36+
37+
for c, c_props in classes.items():
38+
graph = [
39+
{
40+
"@id": wrap(c),
41+
"@type": "rdfs:Class",
42+
"rdfs:comment": "A NIMADS {}".format(c),
43+
"rdfs:label": c,
44+
"rdfs:subClassOf": {"@id": "schema:Thing"}
45+
}
46+
] + c_props
47+
48+
data = {
49+
"@context": context,
50+
"@graph": graph
51+
}
52+
53+
with open(os.path.join('nimads', c + '.jsonld'), 'w') as f:
54+
json.dump(data, f, indent=2)
55+
56+
for c, entries in props.items():
57+
data = {
58+
"@context": context,
59+
"@id": wrap(c),
60+
"@type": "rdf:Property",
61+
"rdfs:label": c
62+
}
63+
data.update(entries)
64+
with open(os.path.join('nimads', '_' + c + '.jsonld'), 'w') as f:
65+
json.dump(data, f, indent=2)

nimads/Dataset.jsonld

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@graph": [
9+
{
10+
"@id": "nimads:Dataset",
11+
"@type": "rdfs:Class",
12+
"rdfs:comment": "A NIMADS Dataset",
13+
"rdfs:label": "Dataset",
14+
"rdfs:subClassOf": {
15+
"@id": "schema:Thing"
16+
}
17+
},
18+
{
19+
"@id": "nimads:study",
20+
"schema:domainIncludes": {
21+
"@id": "nimads:Dataset"
22+
}
23+
}
24+
]
25+
}

nimads/_analysis.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:analysis",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "analysis",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Study"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "nimads:Analysis"
19+
}
20+
]
21+
}

nimads/_condition.jsonld

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:condition",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "condition",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Study"
14+
},
15+
{
16+
"@id": "nimads:Analysis"
17+
}
18+
],
19+
"rangeIncludes": [
20+
{
21+
"@id": "nimads:Condition"
22+
},
23+
{
24+
"@id": "nimads:Condition"
25+
}
26+
]
27+
}

nimads/_coordinates.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:coordinates",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "coordinates",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Point"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "nimads:Coordinates"
19+
}
20+
]
21+
}

nimads/_image.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:image",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "image",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Analysis"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "nimads:Image"
19+
}
20+
]
21+
}

nimads/_path.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:path",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "path",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Image"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "schema:Text"
19+
}
20+
]
21+
}

nimads/_point.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:point",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "point",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Analysis"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "nimads:Point"
19+
}
20+
]
21+
}

nimads/_publication.jsonld

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"nimads": "http://neurostuff.org/nimads/"
7+
},
8+
"@id": "nimads:publication",
9+
"@type": "rdf:Property",
10+
"rdfs:label": "publication",
11+
"domainIncludes": [
12+
{
13+
"@id": "nimads:Study"
14+
}
15+
],
16+
"rangeIncludes": [
17+
{
18+
"@id": "schema:ScholarlyArticle"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)