-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodo.py
133 lines (108 loc) · 3.86 KB
/
dodo.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# encoding=utf8
from doit import get_var
from roald import Roald
import logging
import logging.config
logging.config.fileConfig('logging.cfg', )
logger = logging.getLogger(__name__)
import data_ub_tasks
config = {
'dumps_dir': get_var('dumps_dir', '/opt/data.ub/www/default/dumps'),
'dumps_dir_url': get_var('dumps_dir_url', 'http://data.ub.uio.no/dumps'),
'graph': 'http://data.ub.uio.no/tekord',
'fuseki': 'http://localhost:3030/ds',
'basename': 'tekord',
'git_user': 'ubo-bot',
'git_email': '[email protected]',
}
def task_fetch_core():
logger.info('Checking for updated files')
yield {
'doc': 'Fetch remote core files that have changed',
'basename': 'fetch',
'name': None
}
yield data_ub_tasks.git_pull_task_gen(config)
for file in [
{
'remote': 'https://mapper.biblionaut.net/export/real_tekord_mappings.ttl',
'local': 'src/real_tekord_mappings.ttl'
}
]:
yield data_ub_tasks.fetch_remote_gen(file['remote'], file['local'], ['fetch_core:git-pull'])
def task_build():
def build_dist(task):
logger.info('Building new dist')
roald = Roald()
roald.load('src/tekord.xml', format='bibsys', language='nb')
roald.set_uri_format(
'http://data.ub.uio.no/%s/c{id}' % config['basename'])
roald.save('%s.json' % config['basename'])
logger.info('Wrote %s.json', config['basename'])
includes = [
'%s.scheme.ttl' % config['basename'],
'ubo-onto.ttl'
]
mappings = [
'src/real_tekord_mappings.ttl'
]
# 1) MARC21
marc21options = {
'vocabulary_code': 'tekord',
'created_by': 'NO-TrNTNU'
}
roald.export('dist/%s.marc21.xml' %
config['basename'], format='marc21', **marc21options)
logger.info('Wrote dist/%s.marc21.xml', config['basename'])
# 2) RDF (core)
roald.export('dist/%s.ttl' % config['basename'],
format='rdfskos',
include=includes,
add_same_as=['http://ntnu.no/ub/data/tekord#{id}']
)
logger.info('Wrote dist/%s.core.ttl', config['basename'])
# 3) RDF (core + mappings)
roald.export('dist/%s.complete.ttl' % config['basename'],
format='rdfskos',
include=includes,
mappings_from=mappings,
add_same_as=['http://ntnu.no/ub/data/tekord#{id}']
)
logger.info('Wrote dist/%s.complete.ttl', config['basename'])
return {
'doc': 'Build distribution files (RDF/SKOS + MARC21XML) from source files',
'actions': [
'mkdir -p dist',
build_dist,
],
'file_dep': [
'src/tekord.xml',
'src/real_tekord_mappings.ttl',
'ubo-onto.ttl',
'%s.scheme.ttl' % config['basename']
],
'targets': [
'%s.json' % config['basename'],
'dist/%s.marc21.xml' % config['basename'],
'dist/%s.ttl' % config['basename'],
'dist/%s.complete.ttl' % config['basename']
]
}
# def task_git_push():
# return data_ub_tasks.git_push_task_gen(config)
def task_publish_dumps():
return data_ub_tasks.publish_dumps_task_gen(config['dumps_dir'], [
'%s.marc21.xml' % config['basename'],
'%s.ttl' % config['basename'],
'%s.complete.ttl' % config['basename']
])
def task_build_mappings():
return data_ub_tasks.build_mappings_gen(
['src/real_tekord_mappings.ttl'],
'dist/tekord_realfagstermer.mappings.nt',
'http://data.ub.uio.no/tekord'
)
def task_fuseki():
return data_ub_tasks.fuseki_task_gen(config, [
'dist/%(basename)s.complete.ttl',
])