-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_rdf_data_files.py
63 lines (60 loc) · 2.39 KB
/
build_rdf_data_files.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pysparql_anything as pysa
import os
import yaml
from rdflib import Graph
action_path = os.path.dirname(__file__)
config = yaml.load(open('_config.yml','r'), Loader=yaml.Loader)
namespace = config['rdf']['namespace']
engine = pysa.SparqlAnything()
directory = './content/'
includes = './_includes/rdf/'
allgraph = Graph()
for root, dirs, files in os.walk(directory):
for filename in files:
if not filename.endswith('.md'):
continue
location = os.path.join(root, filename)
if "/.github/" in location:
continue
pre, ext = os.path.splitext(location)
output_includes = pre.replace("./content/", "./_includes/rdf/")
output = pre + ".schema.json"
output_includes = output_includes + ".schema.json"
pth = os.path.dirname(os.path.abspath(output))
pth_includes = os.path.dirname(os.path.abspath(output_includes))
if not os.path.exists(pth):
os.makedirs(pth)
if not os.path.exists(pth_includes):
os.makedirs(pth_includes)
g = engine.construct(q=action_path + '/components-to-rdf.sparql', v={'componentFile': location, 'namespace': namespace}) #
allgraph = allgraph + g
f = open(output, 'w')
f.write(g.serialize(format='json-ld'))
f1 = open(output_includes, 'w')
f1.write(g.serialize(format='json-ld'))
### WPs
directory = './pages/work-packages'
for root, dirs, files in os.walk(directory):
for filename in files:
if not filename.endswith('.md'):
continue
location = os.path.join(root, filename)
if "/.github/" in location:
continue
pre, ext = os.path.splitext(location)
g = engine.construct(q=action_path + '/components-to-rdf.sparql', v={'componentFile': location, 'namespace': namespace}) #
allgraph = allgraph + g
### Pilots
directory = './pages/pilots'
for root, dirs, files in os.walk(directory):
for filename in files:
if not filename.endswith('.md'):
continue
location = os.path.join(root, filename)
if "/.github/" in location:
continue
pre, ext = os.path.splitext(location)
g = engine.construct(q=action_path + '/components-to-rdf.sparql', v={'componentFile': location, 'namespace': namespace}) #
allgraph = allgraph + g
feco = open("ecosystem.nt", 'w')
feco.write(allgraph.serialize(format='nt'))