-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-dev.py
executable file
·45 lines (37 loc) · 1.45 KB
/
build-dev.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
#!/usr/bin/env python3
from glob import glob
import os
from rdflib import Graph
import re
import logging
# Configure root logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logging.basicConfig(format='%(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', level=logging.DEBUG)
def copy_ontologies():
"""Copy ontologies to web path."""
map = {
"modules": "ontology",
"demo": "demo"
}
for type in ["modules", "demo"]:
# publish ontologies
for source in sorted(glob(f"ontology/{type}/*/*/*", recursive=True)):
if not source.endswith(".ttl"):
continue
parts = re.match(f"ontology/{type}/([^/]*)/([^/]*)", source)
name = parts.group(1)
version = parts.group(2)
target = f"docs/{map[type]}/{name}/{version}/"
os.makedirs(target, exist_ok=True)
logging.debug(f"Source:\t{source}")
logging.debug(f"Name:\t{name}")
logging.debug(f"Target:\t{target}")
g = Graph()
g.parse(source)
g.serialize(destination=f"{target}{name}.ttl", format="turtle")
g.serialize(destination=f"{target}{name}.rdf", format="xml")
g.serialize(destination=f"{target}{name}.owl", format="xml")
g.serialize(destination=f"{target}{name}.jsonld", format="json-ld")
if __name__ == "__main__":
copy_ontologies()