-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatterns.py
472 lines (323 loc) · 14.3 KB
/
patterns.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
from cromulent.model import factory, Group, DigitalObject
from cromulent.vocab import Type, Set, LinguisticObject, Name, InformationObject, Creation, VisualItem, Identifier, Production, HumanMadeObject, Dimension, MeasurementUnit, TimeSpan, Place, Person, Language, DigitalService
# ==========================
def set_pattern(data,globalvars):
types = globalvars['types']
uris = globalvars['uris']
# identifier and label
id = data["type_id"]
label = data["_label"]
set = Set(ident= uris["aat"] + str(id), label=label)
# classified_as
set.classified_as = type_pattern(id, globalvars)
# subject_of web page
if "homepage" in data["subject_of"][0]:
set.subject_of = web_page_pattern(data["subject_of"][0]["homepage"], globalvars)
# subject_of iiif
set.subject_of = iiif_pattern(data["subject_of"][0]["iiif"], globalvars)
# identifiers
if "name" in data["identified_by"]:
set.identified_by = name_pattern(data["identified_by"]["name"], globalvars)
if "pia-id" in data["identified_by"]:
set.identified_by = identifier_pattern(
data["identified_by"]["pia-id"], globalvars)
if "sgv-signature" in data["identified_by"]:
set.identified_by = identifier_pattern(
data["identified_by"]["sgv-signature"], globalvars)
if "description" in data:
lo_type = Type(id= "http://vocab.getty.edu/aat/300435416", label="Description")
lo_type.classified_as = Type(id="http://vocab.getty.edu/aat/300418049", label="Brief Text")
lo = LinguisticObject(id="", content=data["description"])
lo.classified_as = lo_type
set.referred_to_by = lo
return set
def humanmadeobject_pattern(data, globalvars):
types = globalvars['types']
uris = globalvars['uris']
# identifier and label
id = data["type_id"]
label = data["_label"]
hmo = HumanMadeObject(ident=uris["aat"] + str(id), label=label)
# classified_as
hmo.classified_as = type_pattern(id, globalvars)
# member_of collection
hmo.member_of = collection_pattern(data, globalvars)
# subject_of web page
hmo.subject_of = web_page_pattern(data["subject_of"][0], globalvars)
# subject_of iiif
hmo.subject_of = iiif_pattern(data["subject_of"][1], globalvars)
# not supported in cromulent
# hmo_1.current_owner = Group(ident="", label="")
# production
if "produced_by" in data:
hmo.produced_by = produced_by_pattern(data["produced_by"], globalvars)
# dimensions
# no data available at moment
# shows
if "shows" in data and data["_label"] != "":
hmo.shows = shows_pattern(data["shows"], globalvars)
# representation
# digital object
id_digital_object = data["representation"][0]["digital_surrogate"]["id"]
digital_object = DigitalObject(ident="", label="")
digital_object.format = "image/jpeg"
digital_object.access_point = DigitalObject(
ident=id_digital_object, label='Image in full resolution')
digital_object.classified_as = Type(
id="http://vocab.getty.edu/aat/300215302", label="Digital Image")
if "iiif_image_api" in data["representation"][0]:
iiif_image_api = data["representation"][0]["iiif_image_api"]["id"]
digital_object.digitally_available_via = digital_service_pattern(
data, types, iiif_image_api)
# visualitem
label_visual_item = data["representation"][0]["digital_surrogate"]["_label"]
visual_item = VisualItem(id="", label=label_visual_item)
visual_item.digitally_shown_by = digital_object
hmo.representation = visual_item
# identifiers
if "name" in data["identified_by"]:
hmo.identified_by = name_pattern(data["identified_by"]["name"], globalvars)
if "pia-id" in data["identified_by"]:
hmo.identified_by = identifier_pattern(
data["identified_by"]["pia-id"], globalvars)
if "sgv-signature" in data["identified_by"]:
hmo.identified_by = identifier_pattern(
data["identified_by"]["sgv-signature"], globalvars)
if "creator-assigned" in data["identified_by"]:
hmo.identified_by = identifier_pattern(
data["identified_by"]["creator-assigned"], globalvars)
return hmo
def digital_object_pattern(data, globalvars):
types = globalvars['types']
uris = globalvars['uris']
id = data["type_id"]
label = data["_label"]
# identifier and label
digital_object = DigitalObject(ident=uris["aat"] + str(id), label=label)
# classified_as
digital_object.classified_as = type_pattern(id, globalvars)
# member_of collection
digital_object.member_of = collection_pattern(data, globalvars)
# subject_of web page
digital_object.subject_of = web_page_pattern(data["subject_of"][0], globalvars)
# subject_of iiif
digital_object.subject_of = iiif_pattern(data["subject_of"][1], globalvars)
# not supported in cromulent
# digital_object_1.current_owner = Group(ident="", label="")
# creation and production
if "created_by" in data:
digital_object.created_by = creation_pattern(data["created_by"], globalvars)
# digitally_shows
if "digitally_shows" in data and data["_label"] != "":
digital_object.digitally_shows = digitally_shows_pattern(
data["digitally_shows"], globalvars)
# identifiers
if "name" in data["identified_by"]:
digital_object.identified_by = name_pattern(data["identified_by"]["name"], globalvars)
if "pia-id" in data["identified_by"]:
digital_object.identified_by = identifier_pattern(
data["identified_by"]["pia-id"], globalvars)
if "sgv-signature" in data["identified_by"]:
digital_object.identified_by = identifier_pattern(
data["identified_by"]["sgv-signature"], globalvars)
if "creator-assigned" in data["identified_by"]:
digital_object.identified_by = identifier_pattern(
data["identified_by"]["creator-assigned"], globalvars)
# access point
if "access_point" in data:
digital_object.access_point = DigitalObject(
ident=data["access_point"]["id"], label=data["access_point"]["_label"])
# digitally available via
if "iiif_image_api" in data:
digital_object.digitally_available_via = digital_service_pattern(
data, globalvars, data["iiif_image_api"])
return digital_object
# ==================================
def digital_service_pattern(data, types, iiif_image_api):
digital_service = DigitalService(label="IIIF Image API", ident="")
digital_service.format = "application/ld+json"
digital_service.access_point = DigitalObject(ident=iiif_image_api)
digital_service.conforms_to = InformationObject(
ident="http://iiif.io/api/image/3/context.json")
return digital_service
def type_pattern(id, globalvars):
types = globalvars.get('types')
uris = globalvars.get("uris")
selected_type = types.get(id)
label = selected_type.get("label")
type = Type(ident=uris["aat"] + str(id), label=label)
work_id = 300435443
work = types.get(work_id)
label = work.get("label")
type.classified_as = Type(
ident=uris["aat"] + str(work_id), label=label)
return type
def collection_pattern(data, globalvars):
id = data["member_of"][0]["id"]
label = data["member_of"][0]["_label"]
types = globalvars.get('types')
uris = globalvars.get("uris")
collection_type_id = 300025976
collection = Set(ident=id, label=label)
collection.classified_as = type_pattern(collection_type_id, globalvars)
return collection
def web_page_pattern(data, globalvars):
label = data["_label"]
access_point_id = data["access_point_id"]
web_page_type_id = 300264578
digital_object = DigitalObject(ident="", label=label)
digital_object.identified_by = Name(ident="", content=label)
digital_object.format = "text/html"
digital_object.access_point = DigitalObject(ident=access_point_id)
digital_object.classified_as = type_pattern(web_page_type_id, globalvars)
linguistic_object = LinguisticObject(ident="", label=label)
linguistic_object.digitally_carried_by = digital_object
return linguistic_object
def iiif_pattern(data, globalvars):
label = data["_label"]
access_point_id = data["access_point_id"]
iiif_id = "http://iiif.io/api/presentation/3/context.json"
digital_object = DigitalObject(ident="", label=label)
digital_object.format = "application/ld+json"
digital_object.access_point = DigitalObject(ident=access_point_id)
digital_object.conforms_to = InformationObject(ident=iiif_id, label="")
digital_object.identified_by = Name(ident="", label=label)
linguistic_object = LinguisticObject(ident="", label=label)
linguistic_object.digitally_carried_by = digital_object
return linguistic_object
def negative_pattern(data, globalvars):
label = data["_label"]
negative_type_id = 300128343
work_type_id = 300435443
# negative
hmo = HumanMadeObject(ident="", label=label)
hmo.classified_as = type_pattern(negative_type_id, globalvars)
# measurement dimension
# width
if "width" in data and data["width"] != "":
width = Dimension(ident="", label="")
width_type_id = 300055647
width.classified_as = type_pattern(width_type_id,globalvars)
width.value = data["width"]
width.unit = MeasurementUnit(
id=300379098, label="Centimetres")
hmo.dimension = width
# height
if "height" in data and data["height"] != "":
height = Dimension(ident="", label="")
height_type_id = 300055644
height.classified_as = type_pattern(height_type_id,globalvars)
height.value = data["height"]
height.unit = MeasurementUnit(
label="Centimetres", id=300379098)
hmo.dimension = height
return hmo
def produced_by_pattern(data, globalvars):
# production
production = Production(ident="", label="")
if "used" not in data or "produced_by_event" not in data["used"]:
return []
data_prod = data["used"]["produced_by_event"]
# production timespan
timespan = TimeSpan(ident="", label="")
timespan.begin_of_the_begin = data_prod["begin"]
timespan.end_of_the_end = data_prod["end"]
if data_prod["display_title"] != "":
name = Name(ident="", label="")
name.content = data_prod["display_title"]
name.classified_as = type_pattern(
"http://vocab.getty.edu/aat/300404669", globalvars)
timespan.identified_by = name
production.timespan = timespan
# production location
for place in data_prod["location"]:
if "id" in place and place["id"] != "":
pl = Place(ident=place["id"], label=place["_label"])
pl.identified_by = Identifier(
ident=place["id"], label='local identifier')
if place["geonames_id"] != "":
pl.identified_by = Identifier(
ident=place["geonames_id"], label='geonames identifier')
production.took_place_at = pl
# production carried out by
for person in data_prod["person"]:
if person["id"] != "":
production.carried_out_by = Person(
ident=person["id"], label=person["_label"])
return production
def creation_pattern(data, globalvars ):
# production
production = Production(ident="", label="")
if "produced_by_event" not in data["used"]:
return {}
data_prod = data["used"]["produced_by_event"]
# production timespan
timespan = TimeSpan(ident="", label="")
timespan.begin_of_the_begin = data_prod["begin"]
timespan.end_of_the_end = data_prod["end"]
if data_prod["display_title"] != "":
name = Name(ident="", label="")
name.content = data_prod["display_title"]
name.classified_as = type_pattern(
300404669, globalvars)
timespan.identified_by = name
production.timespan = timespan
# production location
if "location" in data_prod:
for place in data_prod["location"]:
if "id" in place and place["id"] != "":
pl = Place(ident=place["id"], label=place["_label"])
pl.identified_by = Identifier(
ident=place["id"], label='local identifier')
if place["geonames_id"] != "":
pl.identified_by = Identifier(
ident=place["geonames_id"], label='geonames identifier')
production.took_place_at = pl
# production carried out by
if "person" in data_prod:
for person in data_prod["person"]:
if person["id"] != "":
production.carried_out_by = Person(
ident=person["id"], label=person["_label"])
# negative
negative = negative_pattern(data["used"], globalvars)
negative.produced_by = production
negative.shows = VisualItem(ident="", label=data["used"]["_label"])
# creation
creation = Creation(ident="", label=data["_label"])
creation.used_specific_object = negative
return creation
def shows_pattern(data, globalvars):
label = data["_label"]
visual_item = VisualItem(ident="", label=label)
if "type_id" in data:
visual_item.represents = type_pattern(data["type_id"], globalvars)
return visual_item
def digitally_shows_pattern(data, globalvars):
label = data["_label"]
visual_item = VisualItem(ident="", label=label)
if "type_id" in data:
visual_item.represents_instance_of_type = type_pattern(
data["type_id"], globalvars)
return visual_item
def name_pattern(data, globalvars):
uris = globalvars["uris"]
types = globalvars["types"]
label = data["_label"]
name = Name(ident="", label="")
name.classified_as = type_pattern(
300404670, globalvars)
if "language" in data:
lang = data["language"]
lang_id = lang.get("type_id")
selected_type = types.get(lang_id)
label = selected_type.get('label')
name.language = Language(
ident=uris["aat"] + str(lang_id), label=label)
return name
def identifier_pattern(data, globalvars):
value = data["value"]
type_id = data["type_id"]
identifier = Identifier(content=value, ident="")
identifier.classified_as = type_pattern(type_id, globalvars)
return identifier