-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_site.py
49 lines (43 loc) · 1.55 KB
/
make_site.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
from jinja2 import Environment, FileSystemLoader, select_autoescape
from rdflib import Namespace, BNode, RDF, RDFS, Graph
class SiteBuilder:
def __init__(self, constraints_json_file: str):
with open(constraints_json_file, 'r') as f:
self.constraints = json.load(f)
def build_definitions(self):
# list of dictionaries, each with:
# - class (concept URI)
# - name
# - label
# - immediate_subgraph (cbd)
# - see also (all constraints and rules)
definitions = []
for concept, defn in self.constraints.items():
print(concept)
print(json.dumps(defn, indent=2))
print('---')
definitions.append({
"class": concept,
"name": defn["stable_id"],
"label": defn["label"],
"immediate_subgraph": defn["cbd"],
})
return definitions
def build(self):
env = Environment(
loader=FileSystemLoader('templates'),
autoescape=select_autoescape()
)
template = env.get_template("index.html")
definitions = self.build_definitions()
#prop_defns = self.build_property_shapes()
# Now render the template
with open("index.html", "w") as f:
f.write(template.render(
concepts=definitions,
#property_shapes=[d.to_dict() for d in prop_defns],
))
if __name__ == "__main__":
builder = SiteBuilder("constraints.json")
builder.build()