shacl2code 0.0.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shacl2code/__init__.py +4 -0
- shacl2code/__main__.py +12 -0
- shacl2code/context.py +167 -0
- shacl2code/lang/__init__.py +11 -0
- shacl2code/lang/common.py +144 -0
- shacl2code/lang/jinja.py +29 -0
- shacl2code/lang/jsonschema.py +51 -0
- shacl2code/lang/lang.py +19 -0
- shacl2code/lang/python.py +54 -0
- shacl2code/lang/templates/jsonschema.j2 +277 -0
- shacl2code/lang/templates/python.j2 +2054 -0
- shacl2code/main.py +139 -0
- shacl2code/model.py +293 -0
- shacl2code/urlcontext.py +23 -0
- shacl2code/version.py +1 -0
- shacl2code-0.0.11.dist-info/METADATA +205 -0
- shacl2code-0.0.11.dist-info/RECORD +20 -0
- shacl2code-0.0.11.dist-info/WHEEL +4 -0
- shacl2code-0.0.11.dist-info/entry_points.txt +2 -0
- shacl2code-0.0.11.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
{%- if schema_id %}
|
|
4
|
+
"$id": "{{ schema_id }}",
|
|
5
|
+
{%- endif %}
|
|
6
|
+
{%- if schema_title %}
|
|
7
|
+
"title": "{{ schema_title }}",
|
|
8
|
+
{%- endif %}
|
|
9
|
+
"$comment": "{{ disclaimer }}",
|
|
10
|
+
"type": "object",
|
|
11
|
+
|
|
12
|
+
"properties": {
|
|
13
|
+
{%- if context.urls %}
|
|
14
|
+
{%- if context.urls | length == 1 %}
|
|
15
|
+
"@context": {
|
|
16
|
+
"const": "{{ context.urls[0] }}"
|
|
17
|
+
}
|
|
18
|
+
{%- else %}
|
|
19
|
+
"@context": {
|
|
20
|
+
"type": "array",
|
|
21
|
+
"prefixItems": {
|
|
22
|
+
{%- for url in context.urls %}
|
|
23
|
+
{ "const": "{{ url }}" }{% if not loop.last %},{% endif %}
|
|
24
|
+
{%- endfor %}
|
|
25
|
+
},
|
|
26
|
+
"minContains": "{{ context.urls | length }}",
|
|
27
|
+
"maxContains": "{{ context.urls | length }}",
|
|
28
|
+
"items": false
|
|
29
|
+
}
|
|
30
|
+
{%- endif %}
|
|
31
|
+
{%- endif %}
|
|
32
|
+
},
|
|
33
|
+
{%- if context.urls %}
|
|
34
|
+
"required": ["@context"],
|
|
35
|
+
{%- endif %}
|
|
36
|
+
|
|
37
|
+
"oneOf": [
|
|
38
|
+
{
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": {
|
|
41
|
+
"@graph": {
|
|
42
|
+
"description": "Top level container for JSON-LD objects",
|
|
43
|
+
"type": "array",
|
|
44
|
+
"items": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"$ref": "#/$defs/AnyClass",
|
|
47
|
+
"unevaluatedProperties": false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": ["@graph"]
|
|
52
|
+
},
|
|
53
|
+
{ "$ref": "#/$defs/AnyClass" }
|
|
54
|
+
],
|
|
55
|
+
"unevaluatedProperties": false,
|
|
56
|
+
|
|
57
|
+
"$defs": {
|
|
58
|
+
{%- for class in classes %}
|
|
59
|
+
{#- Classes are divided into 2 parts. The properties are separated into a separate object #}
|
|
60
|
+
{#- so that a object can references the properties of its parent without needing the const #}
|
|
61
|
+
{#- @type tag #}
|
|
62
|
+
{%- if not class.is_abstract %}
|
|
63
|
+
"{{ varname(*class.clsname) }}": {
|
|
64
|
+
"allOf": [
|
|
65
|
+
{
|
|
66
|
+
"type": "object",
|
|
67
|
+
{%- if class.is_extensible %}
|
|
68
|
+
"unevaluatedProperties": true,
|
|
69
|
+
{%- endif %}
|
|
70
|
+
"properties": {
|
|
71
|
+
"{{ class.id_property or "@id" }}": { "$ref": "#/$defs/{{ class.node_kind.split("#")[-1] }}" },
|
|
72
|
+
"{{ context.compact("@type") }}": {
|
|
73
|
+
"oneOf": [
|
|
74
|
+
{%- if class.is_extensible %}
|
|
75
|
+
{ "$ref": "#/$defs/IRI" },
|
|
76
|
+
{%- endif %}
|
|
77
|
+
{ "const": "{{ context.compact_vocab(class._id) }}" }
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}{%- if class.node_kind == SH.IRI %},
|
|
81
|
+
"required": ["{{ class.id_property or "@id" }}"]
|
|
82
|
+
{%- endif %}
|
|
83
|
+
},
|
|
84
|
+
{ "$ref": "#/$defs/{{ varname(*class.clsname) }}_props" }
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{%- endif %}
|
|
88
|
+
"{{ varname(*class.clsname) }}_derived": {
|
|
89
|
+
{%- set ns = namespace(external_ref=False, local_ref=False, any_ref=False, json_refs=[]) %}
|
|
90
|
+
{%- for d in get_all_derived(class) + [class._id] %}
|
|
91
|
+
{%- set ns.json_refs = ns.json_refs + ["#/$defs/" + varname(*classes.get(d).clsname)] %}
|
|
92
|
+
{%- endfor %}
|
|
93
|
+
"anyOf": [
|
|
94
|
+
{%- if ns.json_refs %}
|
|
95
|
+
{
|
|
96
|
+
"type": "object",
|
|
97
|
+
{%- if not class.is_extensible %}
|
|
98
|
+
"unevaluatedProperties": false,
|
|
99
|
+
{%- endif %}
|
|
100
|
+
"anyOf": [
|
|
101
|
+
{%- for r in ns.json_refs %}
|
|
102
|
+
{ "$ref": "{{ r }}" }{% if not loop.last %},{% endif %}
|
|
103
|
+
{%- endfor %}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{%- endif %}
|
|
107
|
+
{ "$ref": "#/$defs/BlankNodeOrIRI" }
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"{{ varname(*class.clsname) }}_props": {
|
|
111
|
+
"allOf": [
|
|
112
|
+
{%- if class.parent_ids %}
|
|
113
|
+
{%- for parent in class.parent_ids %}
|
|
114
|
+
{ "$ref": "#/$defs/{{ varname(*classes.get(parent).clsname) }}_props" },
|
|
115
|
+
{%- endfor %}
|
|
116
|
+
{%- else %}
|
|
117
|
+
{ "$ref": "#/$defs/SHACLClass" },
|
|
118
|
+
{%- endif %}
|
|
119
|
+
{%- set required = [] %}
|
|
120
|
+
{
|
|
121
|
+
"type": "object",
|
|
122
|
+
"properties": {
|
|
123
|
+
{%- for prop in class.properties %}
|
|
124
|
+
{%- if not prop.min_count is none and prop.min_count > 0 %}
|
|
125
|
+
{{- required.append(prop.path) or "" }}
|
|
126
|
+
{%- endif %}
|
|
127
|
+
{%- set is_list = prop.max_count is none or prop.max_count != 1 %}
|
|
128
|
+
"{{ context.compact_vocab(prop.path) }}": {
|
|
129
|
+
{%- set prop_ref = "#/$defs/prop_" + varname(*class.clsname) + "_" + varname(prop.varname) %}
|
|
130
|
+
{%- if is_list %}
|
|
131
|
+
"oneOf": [
|
|
132
|
+
{
|
|
133
|
+
"type": "array",
|
|
134
|
+
{%- if prop.max_count is not none %}
|
|
135
|
+
"maxItems": {{ prop.max_count }},
|
|
136
|
+
{%- endif %}
|
|
137
|
+
{%- if prop.min_count is not none %}
|
|
138
|
+
"minItems": {{ prop.min_count }},
|
|
139
|
+
{%- endif %}
|
|
140
|
+
"items": {
|
|
141
|
+
"$ref": "{{ prop_ref }}"
|
|
142
|
+
}
|
|
143
|
+
}{% if allow_elided_lists %},
|
|
144
|
+
{
|
|
145
|
+
"$ref": "{{ prop_ref }}"
|
|
146
|
+
}
|
|
147
|
+
{%- endif %}
|
|
148
|
+
]
|
|
149
|
+
{%- else %}
|
|
150
|
+
"$ref": "{{ prop_ref }}"
|
|
151
|
+
{%- endif %}
|
|
152
|
+
}{% if not loop.last %},{% endif %}
|
|
153
|
+
{%- endfor %}
|
|
154
|
+
}{% if required %},
|
|
155
|
+
"required": [
|
|
156
|
+
{%- for r in required %}
|
|
157
|
+
"{{ context.compact_vocab(r) }}"{% if not loop.last %},{% endif %}
|
|
158
|
+
{%- endfor %}
|
|
159
|
+
]
|
|
160
|
+
{%- endif %}
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
},
|
|
164
|
+
{%- for prop in class.properties %}
|
|
165
|
+
"prop_{{ varname(*class.clsname) }}_{{ varname(prop.varname) }}": {
|
|
166
|
+
{%- if prop.enum_values %}
|
|
167
|
+
"enum": [
|
|
168
|
+
{%- for e in prop.enum_values %}
|
|
169
|
+
"{{ context.compact_vocab(e, prop.path) }}"{% if not loop.last %},{% endif %}
|
|
170
|
+
{%- endfor %}
|
|
171
|
+
]
|
|
172
|
+
{%- elif prop.class_id %}
|
|
173
|
+
"$ref": "#/$defs/{{ varname(*classes.get(prop.class_id).clsname) }}_derived"
|
|
174
|
+
{%- else %}
|
|
175
|
+
{%- if prop.datatype == "http://www.w3.org/2001/XMLSchema#string" %}
|
|
176
|
+
{%- if prop.pattern %}
|
|
177
|
+
"pattern": "{{ prop.pattern | replace("\\", "\\\\") }}",
|
|
178
|
+
{%- endif %}
|
|
179
|
+
"type": "string"
|
|
180
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#dateTime" %}
|
|
181
|
+
"type": "string",
|
|
182
|
+
"allOf": [
|
|
183
|
+
{
|
|
184
|
+
"pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](Z|[+-][0-9]{2}:[0-9]{2})?$"
|
|
185
|
+
}{%- if prop.pattern %},
|
|
186
|
+
{
|
|
187
|
+
"pattern": "{{ prop.pattern | replace("\\", "\\\\") }}"
|
|
188
|
+
}
|
|
189
|
+
{%- endif %}
|
|
190
|
+
]
|
|
191
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#dateTimeStamp" %}
|
|
192
|
+
"type": "string",
|
|
193
|
+
"allOf": [
|
|
194
|
+
{
|
|
195
|
+
"pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](Z|[+-][0-9]{2}:[0-9]{2})$"
|
|
196
|
+
}{%- if prop.pattern %},
|
|
197
|
+
{
|
|
198
|
+
"pattern": "{{ prop.pattern | replace("\\", "\\\\") }}"
|
|
199
|
+
}
|
|
200
|
+
{%- endif %}
|
|
201
|
+
]
|
|
202
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#anyURI" %}
|
|
203
|
+
{%- if prop.pattern %}
|
|
204
|
+
"pattern": "{{ prop.pattern | replace("\\", "\\\\") }}",
|
|
205
|
+
{%- endif %}
|
|
206
|
+
"$ref": "#/$defs/anyURI"
|
|
207
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#positiveInteger" %}
|
|
208
|
+
"type": "integer",
|
|
209
|
+
"minimum": 1
|
|
210
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#nonNegativeInteger" %}
|
|
211
|
+
"type": "integer",
|
|
212
|
+
"minimum": 0
|
|
213
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#integer" %}
|
|
214
|
+
"type": "integer"
|
|
215
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#boolean" %}
|
|
216
|
+
"type": "boolean"
|
|
217
|
+
{%- elif prop.datatype == "http://www.w3.org/2001/XMLSchema#decimal" %}
|
|
218
|
+
"oneOf": [
|
|
219
|
+
{
|
|
220
|
+
"type": "number"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"type": "string",
|
|
224
|
+
"pattern": "^-?[0-9]+(\\.[0-9]*)?$"
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
{%- else %}
|
|
228
|
+
{{- abort("Unknown data type " + prop.datatype) }}
|
|
229
|
+
{%- endif %}
|
|
230
|
+
{%- endif %}
|
|
231
|
+
},
|
|
232
|
+
{%- endfor %}
|
|
233
|
+
{%- endfor %}
|
|
234
|
+
"IRI": {
|
|
235
|
+
"type": "string",
|
|
236
|
+
"pattern": "^(?!_:).+:.+"
|
|
237
|
+
},
|
|
238
|
+
"BlankNode": {
|
|
239
|
+
"type": "string",
|
|
240
|
+
"pattern": "^_:.+"
|
|
241
|
+
},
|
|
242
|
+
"BlankNodeOrIRI": {
|
|
243
|
+
"oneOf": [
|
|
244
|
+
{ "$ref": "#/$defs/IRI" },
|
|
245
|
+
{ "$ref": "#/$defs/BlankNode" }
|
|
246
|
+
]
|
|
247
|
+
},
|
|
248
|
+
"anyURI": {
|
|
249
|
+
"type": "string"
|
|
250
|
+
},
|
|
251
|
+
"SHACLClass": {
|
|
252
|
+
"type": "object",
|
|
253
|
+
"properties": {
|
|
254
|
+
"{{ context.compact("@type") }}": {
|
|
255
|
+
"oneOf": [
|
|
256
|
+
{ "$ref": "#/$defs/IRI" },
|
|
257
|
+
{
|
|
258
|
+
"enum": [
|
|
259
|
+
{%- for class in concrete_classes %}
|
|
260
|
+
"{{ context.compact_vocab(class._id) }}"{% if not loop.last %},{% endif %}
|
|
261
|
+
{%- endfor %}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
"required": ["{{ context.compact("@type") }}"]
|
|
268
|
+
},
|
|
269
|
+
"AnyClass": {
|
|
270
|
+
"anyOf": [
|
|
271
|
+
{%- for class in concrete_classes %}
|
|
272
|
+
{ "$ref": "#/$defs/{{ varname(*class.clsname) }}" }{% if not loop.last %},{% endif %}
|
|
273
|
+
{%- endfor %}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|