-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1657 lines (1381 loc) · 62.4 KB
/
main.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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Pipeline to convert Amsterdam Corporate Group Portrait data into RDF.
Built upon an adapted version of RDFAlchemy for Python (3.7). Install with:
```bash
pip install git+https://github.com/LvanWissen/RDFAlchemy.git
```
Contact:
Leon van Wissen ([email protected])
"""
import os
import uuid
import datetime
import json
import re
from itertools import count, product
from collections import defaultdict
import pandas as pd
from dateutil import parser as dateParser
import rdflib
from rdflib import Graph, URIRef, Literal, XSD, Namespace, BNode, OWL
from rdfalchemy import rdfSubject, rdfMultiple, rdfSingle
from ga import *
ns = Namespace("https://data.goldenagents.org/datasets/corporatiestukken/")
gaPersonName = Namespace("https://data.goldenagents.org/datasets/personname/")
rdflib.graph.DATASET_DEFAULT_GRAPH_ID = ns
nsArtwork = Namespace(
"https://data.goldenagents.org/datasets/corporatiestukken/artwork/")
afkortingen = {
"Amh": "Aalmoezeniershuis",
"Awh": "Aalmoezeniershuis", #Check?
"Amwh": "Aalmoezeniersweeshuis",
"Bwh": "Burgerweeshuis",
"CM": "Collegium Medicum",
"Dh": "Dolhuis",
"Gh": "Gasthuizen",
"Lh": "Leprozenhuis",
"NZHh": "Nieuwezijds Huiszittenhuis",
"No.K.": "Noorderkerk",
"Nz.K.": "Nieuwezijds Kapel",
"Oz.K.": "Oudezijds Kapel",
"E.K.": "Eilandskerk",
"A.K.": "Amstelkerk",
"N.K.": "Nieuwe Kerk",
"O.K.": "Oude Kerk",
"Z.K.": "Zuiderkerk",
"W.K.": "Westerkerk",
"Oo.K.": "Oosterkerk",
"N.W.K.": "Nieuwe Walenkerk",
"OZHh": "Oudezijds Huiszittenhuis",
"OMVGh": "Oude Mannen- en Vrouwengasthuis",
"Rh": "Rasphuis",
"SJh": "Sint Jorishof",
"Sph": "Spinhuis",
"SphNWh": "Spin- en Nieuwe Werkhuis",
"Wwh": "Walenweeshuis",
"Wwh.A.": "Walenweeshuis", # TODO
"Wwh.D.": "Walenweeshuis", # TODO
"Zwh": "Zijdewindhuis",
"A.A.": "Admiraliteit te Amsterdam",
"CM": "Collegium Medicum",
"H.Stede": "Heilige Stede",
"RCAk": "Rooms-Catholijck Armenkantoor",
"Vd": "Voetboogdoelen",
"Hd": "Handboogdoelen",
"Kd": "Kloveniersdoelen",
"stadssoldaten": "Stadssoldaten"
}
functies = {
"doct.med.": "medisch doctor",
"havenm.": "havenmeester",
"insp.": "inspecteur",
"kap.": "kapitein",
"kapluit.": "kapitein luitenant",
"k.": "keurmeester",
"km.": "kerkmeester",
"kol.": "kolonel",
"kolgen.": "kolonel generaal",
"luit.": "luitenant",
"luitkol.": "luitenant kolonel",
"ov.": "overman",
"serg.": "sergeant",
"vaand.": "vaandrig",
"tamboer": "tamboer",
"overm.": "overman",
"schout": "schout",
"kastelein": "kastelein",
"maj.": "majoor",
"provoost": "provoost",
"hopman": "hopman",
}
bestuursfuncties = {
"Sch.": "Schepen",
"R.": "Raad",
"C.": "Commissaris",
"C100p.": "Commissaris 100ste penning",
"B.": "Burgemeester",
"Secr.": "Secretaris",
"C.H.": "Commissaris Huwelijkse Zaken",
"C.K.Z.": "Commissaris Kleine Zaken",
"S.": "Schout",
"Onderschout": "Onderschout",
"Pens.": "Pensionaris",
"C.E.": "Commissaris Grooten Excijs",
"C.Z.": "Commissaris Zeezaken",
"Wm.": "Weesmeester",
"C.D.B.": "Commissaris Desolate Boedelskamer",
"C.B.L.": "Commissaris Bank van Lening",
"Th.E.": "Thesaurier Extraordinaris",
"Th.": "Thesaurier Ordinaris",
"Am.": "Assurantiemeester",
"C.Wb.": "Commissaris Wisselbank",
"G.R.": "Gecommitteerde Raad",
"Gecomm.Raad": "Gecommitteerde Raad",
"G.R.K.": "Gedeputeerde ter Generaliteits Rekenkamer",
"HSchout": "Hoofdschout",
"Subst.scht.extr.": "Substituut-schout Extraordinaris",
"Ordinaris": "Raad Ordinaris",
"Gedep.TerStaten": "Gedeputeerde ter Staten",
"Gedep.TerStatenGeneraal": "Gedeputeerde ter Staten Generaal",
"Raad.ter.admir.": "Raad ter Admiraliteit",
"A.N.": "Raad ter Admiraliteit in ‘t Noorderkwartier",
"ov.": "Overman",
"Rm.": "Rekenmeester",
"R.H.":
"Gecommitteerde ter Rekenkamer ter Auditie van Holland in het Zuiderkwartier",
"ov.WKG": "Overman Wijnkopersgilde",
"Secr.Z.": "Secretaris Zeezaken",
"Secr.Th.E.": "Secretaris-thesaurier Extraordinaris",
"Boekh200p.": "Boekhouder 200ste penning",
"OCW": "Oppercommissaris der Walen"
}
# abbreviations = {
# Hd = "Handboogdoelen"
# Kd = "Kloveniersdoelen"
# Vd = "Voetboogdoelen"
# kap. = "kapitein"
# luit. = "luitenant"
# vaand. = "vaandrig"
# kol. = "kolonel"
# serg. = "sergeant"
# W. = "Wijk"
# reg. = "regent / regentes"
# ov. = "overman (-n. = onvervulde nominatie)"
# insp. = "inspecteur"
# doct. med. = "medisch doctor"
# m.p. = "jaar van meesterproef"
# d. = "deken"
# k. = "keurmeester"
# comm. = "oppercommissaris"
# havenm. = "havenmeester"
# OZ = "Oude Zijde / Oudezijds"
# NZ = "Nieuwe Zijde / Nieuwezijds",
# }
def unique(*args, sep="", ns=None):
"""Function to generate a unique BNode based on a series of arguments.
Uses the uuid5 function to generate a uuid from one or multiple ordered
arguments. This way, the BNode function of rdflib can be used, without the
need to filter strange characters or spaces that will break the serialization.
Returns:
BNode: Blank node with identifier that is based on the function's input.
"""
identifier = "".join(str(i) for i in args) # order matters
unique_id = uuid.uuid5(uuid.NAMESPACE_X500, identifier)
if ns:
return ns.term(str(unique_id))
else:
return BNode(unique_id)
def main():
#######
# RDF #
#######
# Poorters
df1 = pd.read_csv(
'data/Middelkoop diss. dl. 2 - bijlage 4a - mannelijke poorters.csv')
df1 = df1.where((pd.notnull(df1)), None)
toRDF(
df1.to_dict(orient='records'),
uri=ns.term('poorters/'),
name=Literal("Mannelijke poorters", lang='nl'),
description=Literal(
"Lijst van mannelijke poorters in functies als instellingsregent, kerkmeester, officier der schutterij en/of ten stadhuize, ca. 1500 – ca. 1795",
lang='nl'),
filename=
"Middelkoop diss. dl. 2 - bijlage 4a - mannelijke poorters.csv",
target='trig/poorters.trig')
# Regentessen
df2 = pd.read_csv(
'data/Middelkoop diss. dl. 2 - bijlage 4b - regentessen.csv')
df2 = df2.where((pd.notnull(df2)), None)
toRDF(
df2.to_dict(orient='records'),
uri=ns.term('regentessen/'),
name=Literal("Regentessen", lang='nl'),
description=Literal(
"Lijst van regentessen van zorg- en tuchtinstellingen, ca. 1578 – ca. 1795",
lang='nl'),
filename="Middelkoop diss. dl. 2 - bijlage 4b - regentessen.csv",
target='trig/regentessen.trig')
# Regenten
df3 = pd.read_csv(
'data/Middelkoop diss. dl. 2 - bijlage 4c - regenten Walenweeshuis.csv'
)
df3 = df3.where((pd.notnull(df3)), None)
toRDF(df3.to_dict(orient='records'),
uri=ns.term('regenten/'),
name=Literal("Regenten Walenweeshuis", lang='nl'),
description=Literal(
"Lijst van regenten van het Walenweeshuis, 1631 – 1800",
lang='nl'),
filename=
"Middelkoop diss. dl. 2 - bijlage 4c - regenten Walenweeshuis.csv",
target='trig/regenten.trig')
# Gildeleden
df4 = pd.read_csv(
'data/Middelkoop diss. dl. 2 - bijlage 4d - geportretteerde gildenleden.csv'
)
df4 = df4.where((pd.notnull(df4)), None)
toRDF(
df4.to_dict(orient='records'),
uri=ns.term('gildenleden/'),
name=Literal("Geportretteerde gildenleden", lang='nl'),
description=Literal(
"Lijst van geportretteerde leden van ambachtsgilden, inspecteurs van het Collegium Medicum en Oppercommissarissen der Walen, 1599 – 1795",
lang='nl'),
filename=
"Middelkoop diss. dl. 2 - bijlage 4d - geportretteerde gildenleden.csv",
target='trig/gildenleden.trig')
# Artwork dataset
df5 = pd.read_csv('data/corporatiestukken.csv')
df5 = df5.where((pd.notnull(df5)), None)
toRDF(df5.to_dict(orient='records'),
uri=ns.term('corporatiestukken/'),
name=Literal("Overzicht van Amsterdamse corporatiestukken",
lang='nl'),
description="Overgenomen uit appendix 3 (Middelkoop 2019).",
filename="corporatiestukken.csv",
target='trig/corporatiestukken.trig')
def getPersonName(d):
# surnamePrefixes = ['de', 'van', 'la', 'der', 'du']
surnamePrefixes = ['van', 'de', 'den', 'des', 'der', 'ten', "l'", "d'"]
pns = []
labels = []
prefixes = d['Titel'].split(
' / ') if d['Titel'] and d['Titel'] != "*" else [None]
givenNames = d['Voornaam'].split(' / ') if d['Voornaam'] else [None]
patronyms = d['Patroniem en tussenvoegsel'].split(
' / ') if d['Patroniem en tussenvoegsel'] else [None]
baseSurnames = d['Achternaam'].split(' / ') if d['Achternaam'] else [None]
for prefix, givenName, patronymSurnamePrefix, baseSurname in product(
prefixes, givenNames, patronyms, baseSurnames):
if prefix:
prefix = prefix.strip()
if givenName:
givenName = givenName.strip()
if patronymSurnamePrefix:
patronym = " ".join([
i for i in patronymSurnamePrefix.split(' ')
if i not in surnamePrefixes
]).strip()
surnamePrefix = " ".join([
i for i in patronymSurnamePrefix.split(' ')
if i in surnamePrefixes
]).strip()
if surnamePrefix == "":
surnamePrefix = None
if patronym == "":
patronym = None
else:
patronym = None
surnamePrefix = None
if ', ' in baseSurname:
baseSurname, disambiguatingDescription = baseSurname.split(', ', 1)
disambiguatingDescription = disambiguatingDescription.strip()
else:
disambiguatingDescription = None
literalName = " ".join([
i for i in [
prefix, givenName, patronym, surnamePrefix, baseSurname,
disambiguatingDescription
] if i is not None
])
labels.append(literalName)
identifier = unique(prefix,
givenName,
patronym,
surnamePrefix,
baseSurname,
disambiguatingDescription,
literalName,
sep='@ga@',
ns=gaPersonName)
pn = PersonName(identifier,
prefix=prefix,
givenName=givenName,
patronym=patronym,
surnamePrefix=surnamePrefix,
baseSurname=baseSurname,
disambiguatingDescription=disambiguatingDescription,
literalName=literalName,
label=[literalName])
pns.append(pn)
return pns, labels
def parsePersonName(nameString, identifier=None):
"""
Parse a capitalised Notary Name from the notorial acts to pnv format.
Args:
full_name (str): Capitalised string
Returns:
PersonName: according to pnv
"""
pns = []
labels = []
for full_name in nameString.split(' / '):
# Some static lists
dets = ['van', 'de', 'den', 'des', 'der', 'ten', "l'", "d'"]
prefixes = ['Mr.']
suffixes = ['Jr.', 'Sr.']
patronymfix = ('sz', 'sz.', 'szoon', 'dr.', 'dr')
# Correcting syntax errors
full_name = full_name.replace('.', '. ')
full_name = full_name.replace("'", "' ")
full_name = full_name.replace(' ', ' ')
# Tokenise
tokens = full_name.split(' ')
tokens = [i.lower() for i in tokens]
tokens = [i.title() if i not in dets else i for i in tokens]
full_name = " ".join(
tokens
) # ALL CAPS to normal name format (e.g. Mr. Jan van Tatenhove)
full_name = full_name.replace(
"' ", "'") # clunk back the apostrophe to the name
# -fixes
infix = " ".join(i for i in tokens if i in dets).strip()
prefix = " ".join(i for i in tokens if i in prefixes).strip()
suffix = " ".join(i for i in tokens if i in suffixes).strip()
name_removed_fix = " ".join(i for i in tokens
if i not in prefixes and i not in suffixes)
if infix and infix in name_removed_fix:
name = name_removed_fix.split(
" " + infix, 1) # would be nicer with regex word boundary
first_name = name[0].strip()
family_name = name[1].strip()
else:
name = name_removed_fix.split(' ', 1)
first_name = name[0]
family_name = name[1]
family_name_split = family_name.split(' ')
first_name_split = first_name.split(' ')
# build first name, family name, patronym and ignore -fixes
first_name = " ".join(i for i in first_name_split
if not i.endswith(patronymfix)).strip()
family_name = " ".join(i for i in family_name_split
if not i.endswith(patronymfix)).strip()
patronym = " ".join(i for i in first_name_split + family_name_split
if i.endswith(patronymfix)).strip()
full_name = " ".join(tokens).strip(
) # ALL CAPS to normal name format (e.g. Mr. Jan van Tatenhove)
literalName = full_name.strip() if full_name is not None else "Unknown"
disambiguatingDescription = suffix if suffix != "" else None
patronym = patronym if patronym != "" else None
prefix = prefix if prefix != "" else None
givenName = first_name if first_name != "" else None
surnamePrefix = infix if infix != "" else None
baseSurname = family_name if family_name != "" else None
if identifier is None:
identifier = unique(prefix,
givenName,
patronym,
surnamePrefix,
baseSurname,
disambiguatingDescription,
literalName,
sep='@ga@',
ns=gaPersonName)
pn = PersonName(identifier,
literalName=literalName,
prefix=prefix,
givenName=givenName,
surnamePrefix=surnamePrefix,
baseSurname=baseSurname,
patronym=patronym,
disambiguatingDescription=disambiguatingDescription)
pn.label = [pn.literalName]
pns.append(pn)
labels.append(pn.literalName)
return pns, labels
def parseDate(dateString):
"""
Parse a date notation from the CSV data to XSD literals.
Args:
dateString (str): Date string from CSV data
Returns:
tuple: (earliestDate, latestDate, timeStamp)
"""
if dateString is None:
return None, None, None
timeStamp = None
if '/' in dateString:
earliestDate, latestDate = dateString.split('/')
if earliestDate != "?":
earliestDate = dateParser.parse(earliestDate)
else:
earliestDate = None
if latestDate != "?":
latestDate = dateParser.parse(latestDate)
else:
latestDate = None
else:
date = dateParser.parse(dateString)
earliestDate = date
latestDate = date
timeStamp = Literal(date.date(), datatype=XSD.date)
if earliestDate:
earliestDate = Literal(earliestDate.date(), datatype=XSD.date)
if latestDate:
latestDate = Literal(latestDate.date(), datatype=XSD.date)
return earliestDate, latestDate, timeStamp
def yearToDate(yearString):
"""
Convert a year string to a XSD date literal.
Args:
yearString (str): Year string from CSV data
Returns:
Literal: XSD date literal
"""
if yearString is None or yearString == "?":
return None, None
return Literal(f"{yearString}-01-01",
datatype=XSD.date), Literal(f"{yearString}-12-31",
datatype=XSD.date)
def parseOccupationInfo(occupationInfo, roleTypePerson, person,
roleTypeOrganization, organizationSubEventDict,
nsEvent, pid, eventCounter, nsRole, roleCounter):
"""
Parse occupation information.
"""
organizationString, years = occupationInfo.split(' ', 1)
begin, end = years.split('/')
earliestBeginTimeStamp, latestBeginTimeStamp = begin.split('|')
earliestEndTimeStamp, latestEndTimeStamp = end.split('|')
beginYearLabel = datetime.datetime.fromisoformat(
earliestBeginTimeStamp).year if earliestBeginTimeStamp != "?" else "?"
endYearLabel = datetime.datetime.fromisoformat(
latestEndTimeStamp).year if latestEndTimeStamp != "?" else "?"
earliestBeginTimeStamp = Literal(
earliestBeginTimeStamp,
datatype=XSD.date) if earliestBeginTimeStamp != "?" else None
latestBeginTimeStamp = Literal(
latestBeginTimeStamp,
datatype=XSD.date) if latestBeginTimeStamp != "?" else None
earliestEndTimeStamp = Literal(
earliestEndTimeStamp,
datatype=XSD.date) if earliestEndTimeStamp != "?" else None
latestEndTimeStamp = Literal(
latestEndTimeStamp,
datatype=XSD.date) if latestEndTimeStamp != "?" else None
organization = Organization(
gaOrganization.term(organizationString.replace('.', '')),
label=[Literal(afkortingen[organizationString], lang='nl')])
occupationEvent = Event(
nsEvent.term(f"{pid}-event-{next(eventCounter)}"),
label=[
Literal(
f"{person.label[0]} als {roleTypePerson.label[0]} bij {afkortingen[organizationString]} ({beginYearLabel}-{endYearLabel})",
lang='nl'),
Literal(
f"{person.label[0]} as {roleTypePerson.label[0]} at {afkortingen[organizationString]} ({beginYearLabel}-{endYearLabel})",
lang='en')
],
participationOf=[person, organization],
hasEarliestBeginTimeStamp=earliestBeginTimeStamp,
hasLatestBeginTimeStamp=latestBeginTimeStamp,
hasEarliestEndTimeStamp=earliestEndTimeStamp,
hasLatestEndTimeStamp=latestEndTimeStamp)
roleCount = next(roleCounter)
rolePerson = SpecificRoleType(
nsRole.term(f"{pid}-role-{roleCount}"),
type=roleTypePerson,
carriedIn=occupationEvent,
carriedBy=person,
label=[
Literal(
f"{person.label[0]} in de rol van {roleTypePerson.label[0]}",
lang='nl'),
Literal(
f"{person.label[0]} in the role of {roleTypePerson.label[0]}",
lang='en')
])
roleTypeOrganization = SpecificRoleType(
nsRole.term(f"{pid}-org-{roleCount}"),
type=roleTypeOrganization,
carriedIn=occupationEvent,
carriedBy=organization,
label=[
Literal(
f"{afkortingen[organizationString]} in de rol van {roleTypeOrganization.label[0]}",
lang='nl'),
Literal(
f"{afkortingen[organizationString]} in the role of {roleTypeOrganization.label[0]}",
lang='en')
])
organizationSubEventDict[organization].append(occupationEvent)
return occupationEvent, organizationSubEventDict
def parseFunctionInfo(functionInfo, person, roleTypeOrganization,
organizationSubEventDict, nsEvent, pid, eventCounter,
nsRole, roleCounter):
if 'W.' in functionInfo:
# kap. W. XXIV 1793-01-01|1793-12-31/1795-01-01|1795-12-31
function, _, wijk, years = functionInfo.split(' ')
doelen, unknownOrganization, stadssoldaten = None, None, None
organizationLiteral = "Schutterij van wijk " + wijk
elif 'stadssoldaten' in functionInfo:
function, stadssoldaten, years = functionInfo.split(' ')
wijk, doelen, unknownOrganization = None, None, None
organizationLiteral = "Stadssoldaten"
elif ' ? ' in functionInfo:
function, _, years = functionInfo = functionInfo.split(' ')
wijk, doelen, stadssoldaten = None, None, None
unknownOrganization = "Unknown"
organizationLiteral = "Unknown organization"
else:
# overm. Hd 1659-01-01|1659-12-31/1659-01-01|1659-12-31
function, doelen, years = functionInfo.split(' ')
wijk, unknownOrganization = None, None
organizationLiteral = afkortingen[doelen]
if function == '?':
roleTypePerson = RoleType(gaRoleType.term('Unknown'),
subClassOf=ga.Role,
label=["?"])
else:
roleTypePerson = RoleType(gaRoleType.term(
functies[function].title().replace(' ', '')),
subClassOf=ga.Role,
label=[functies[function].title()])
begin, end = years.split('/')
earliestBeginTimeStamp, latestBeginTimeStamp = begin.split('|')
earliestEndTimeStamp, latestEndTimeStamp = end.split('|')
beginYearLabel = datetime.datetime.fromisoformat(
earliestBeginTimeStamp).year if earliestBeginTimeStamp != "?" else "?"
endYearLabel = datetime.datetime.fromisoformat(
latestEndTimeStamp).year if latestEndTimeStamp != "?" else "?"
earliestBeginTimeStamp = Literal(
earliestBeginTimeStamp,
datatype=XSD.date) if earliestBeginTimeStamp != "?" else None
latestBeginTimeStamp = Literal(
latestBeginTimeStamp,
datatype=XSD.date) if latestBeginTimeStamp != "?" else None
earliestEndTimeStamp = Literal(
earliestEndTimeStamp,
datatype=XSD.date) if earliestEndTimeStamp != "?" else None
latestEndTimeStamp = Literal(
latestEndTimeStamp,
datatype=XSD.date) if latestEndTimeStamp != "?" else None
organization = Organization(
gaOrganization.term(wijk or doelen or stadssoldaten
or unknownOrganization),
label=[Literal(organizationLiteral, lang='nl')])
functionEvent = Event(
nsEvent.term(f"{pid}-event-{next(eventCounter)}"),
label=[
Literal(
f"{person.label[0]} als {roleTypePerson.label[0]} bij {organizationLiteral} ({beginYearLabel}-{endYearLabel})",
lang='nl'),
Literal(
f"{person.label[0]} as {roleTypePerson.label[0]} at {organizationLiteral} ({beginYearLabel}-{endYearLabel})",
lang='en')
],
participationOf=[person, organization],
hasEarliestBeginTimeStamp=earliestBeginTimeStamp,
hasLatestBeginTimeStamp=latestBeginTimeStamp,
hasEarliestEndTimeStamp=earliestEndTimeStamp,
hasLatestEndTimeStamp=latestEndTimeStamp)
roleCount = next(roleCounter)
rolePerson = SpecificRoleType(
nsRole.term(f"{pid}-role-{roleCount}"),
type=roleTypePerson,
carriedIn=functionEvent,
carriedBy=person,
label=[
Literal(
f"{person.label[0]} in de rol van {roleTypePerson.label[0]}",
lang='nl'),
Literal(
f"{person.label[0]} in the role of {roleTypePerson.label[0]}",
lang='en')
])
roleTypeOrganization = SpecificRoleType(
nsRole.term(f"{pid}-org-{roleCount}"),
type=roleTypeOrganization,
carriedIn=functionEvent,
carriedBy=organization,
label=[
Literal(
f"{organizationLiteral} in de rol van {roleTypeOrganization.label[0]}",
lang='nl'),
Literal(
f"{organizationLiteral} in the role of {roleTypeOrganization.label[0]}",
lang='en')
])
organizationSubEventDict[organization].append(functionEvent)
return functionEvent, organizationSubEventDict
def parseRegeerInfo(regeerInfo, person, organization, roleTypeOrganization,
organizationSubEventDict, nsEvent, pid, eventCounter,
nsRole, roleCounter):
function, years = regeerInfo.split(' ')
roleTypePerson = RoleType(gaRoleType.term(
bestuursfuncties[function].title().replace(' ', '')),
subClassOf=ga.Role,
label=[bestuursfuncties[function].title()])
begin, end = years.split('/')
earliestBeginTimeStamp, latestBeginTimeStamp = begin.split('|')
earliestEndTimeStamp, latestEndTimeStamp = end.split('|')
beginYearLabel = datetime.datetime.fromisoformat(
earliestBeginTimeStamp).year if earliestBeginTimeStamp != "?" else "?"
endYearLabel = datetime.datetime.fromisoformat(
latestEndTimeStamp).year if latestEndTimeStamp != "?" else "?"
earliestBeginTimeStamp = Literal(
earliestBeginTimeStamp,
datatype=XSD.date) if earliestBeginTimeStamp != "?" else None
latestBeginTimeStamp = Literal(
latestBeginTimeStamp,
datatype=XSD.date) if latestBeginTimeStamp != "?" else None
earliestEndTimeStamp = Literal(
earliestEndTimeStamp,
datatype=XSD.date) if earliestEndTimeStamp != "?" else None
latestEndTimeStamp = Literal(
latestEndTimeStamp,
datatype=XSD.date) if latestEndTimeStamp != "?" else None
bestuursEvent = Event(
nsEvent.term(f"{pid}-event-{next(eventCounter)}"),
label=[
Literal(
f"{person.label[0]} als {roleTypePerson.label[0]} bij de Stadsregering ({beginYearLabel}-{endYearLabel})",
lang='nl'),
Literal(
f"{person.label[0]} as {roleTypePerson.label[0]} at the City Government ({beginYearLabel}-{endYearLabel})",
lang='en')
],
participationOf=[person, organization],
hasEarliestBeginTimeStamp=earliestBeginTimeStamp,
hasLatestBeginTimeStamp=latestBeginTimeStamp,
hasEarliestEndTimeStamp=earliestEndTimeStamp,
hasLatestEndTimeStamp=latestEndTimeStamp)
roleCount = next(roleCounter)
rolePerson = SpecificRoleType(
nsRole.term(f"{pid}-role-{roleCount}"),
type=roleTypePerson,
carriedIn=bestuursEvent,
carriedBy=person,
label=[
Literal(
f"{person.label[0]} in de rol van {roleTypePerson.label[0]}",
lang='nl'),
Literal(
f"{person.label[0]} in the role of {roleTypePerson.label[0]}",
lang='en')
])
roleTypeOrganization = SpecificRoleType(
nsRole.term(f"{pid}-org-{roleCount}"),
type=roleTypeOrganization,
carriedIn=bestuursEvent,
carriedBy=organization,
label=[
Literal(
f"Stadsregering in de rol van {roleTypeOrganization.label[0]}",
lang='nl'),
Literal(
f"City Government in the role of {roleTypeOrganization.label[0]}",
lang='en')
])
organizationSubEventDict[organization].append(bestuursEvent)
return bestuursEvent, organizationSubEventDict
def toRDF(data, uri, name, description, filename, target=None):
nametype = os.path.split(target)[1].replace('.trig', '')
nsAnnotation = Namespace(
f"https://data.goldenagents.org/datasets/corporatiestukken/annotation/{nametype}/"
)
nsPerson = Namespace(
f"https://data.goldenagents.org/datasets/corporatiestukken/person/{nametype}/"
)
nsGeneralEvent = Namespace(
f"https://data.goldenagents.org/datasets/corporatiestukken/event/")
nsEvent = Namespace(
f"https://data.goldenagents.org/datasets/corporatiestukken/event/{nametype}/"
)
nsRole = Namespace(
f"https://data.goldenagents.org/datasets/corporatiestukken/role/{nametype}/"
)
dataset = ns.term('')
g = rdfSubject.db = Graph(identifier=uri)
_ = RoleType(
ga.Groom,
subClassOf=ga.Role,
label=[Literal("Groom", lang='en'),
Literal("Bruidegom", lang='nl')])
_ = RoleType(
ga.Bride,
subClassOf=ga.Role,
label=[Literal("Bride", lang='en'),
Literal("Bruid", lang='nl')])
_ = RoleType(
ga.Born,
subClassOf=ga.Role,
label=[Literal("Born", lang='en'),
Literal("Geborene", lang='nl')])
_ = RoleType(ga.Deceased,
subClassOf=ga.Role,
label=[
Literal("Deceased", lang='en'),
Literal("Overledene", lang='nl')
])
artworkDepictedDict = defaultdict(list)
organizationSubEventDict = defaultdict(list)
# For the artworks
if 'corporatiestukken.trig' in target:
# Artists
with open('data/creativework2artist.json') as infile:
creativework2artist = json.load(infile)
# Depictions
with open('data/depictions_amsterdammuseum.json') as infile:
depictions_amsterdammuseum = json.load(infile)
with open('data/depictions_rijksmuseum.json') as infile:
depictions_rijksmuseum = json.load(infile)
with open('data/depictions_stadsarchief.json') as infile:
depictions_stadsarchief = json.load(infile)
for nrow, d in enumerate(data, 2):
# Prov
anno = Annotation(
nsAnnotation.term(str(nrow)),
hasTarget=ResourceSelection(
None,
hasSource=filename,
hasSelector=FragmentSelector(
None,
conformsTo=URIRef("http://tools.ietf.org/rfc/rfc7111"),
value=f"row={nrow}")))
# Artwork
art_id = d['identifier'].replace(' ', '').replace('.', '')
artwork = CreativeArtifact(
nsArtwork.term(art_id),
label=[d['title']],
creationDate=d['date'],
hasEarliestBeginTimeStamp=d['earliestBeginTimeStamp'],
hasLatestEndTimeStamp=d['latestEndTimeStamp'],
# artist=[d['artist']],
#disambiguatingDescription=d['dimensions'],
comment=[Literal(d['description'], lang='nl')],
wasDerivedFrom=[anno])
# Get data from mapping
artist_name = creativework2artist[art_id]["name"]
artist_uri = creativework2artist[art_id][
"ecartico"] or creativework2artist[art_id]["wikidata"]
if artist_uri:
artist = Person(URIRef(artist_uri), label=[artist_name])
if 'ecartico' in artist_uri and creativework2artist[art_id][
"wikidata"]:
artist.sameAs = [
URIRef(creativework2artist[art_id]["wikidata"])
]
else:
artist = Person(None, label=[d['artist']])
artwork.artist = [artist]
sameAs = [
URIRef(i) for i in [
d['wikidata_uri'], d['rkd_uri'], d['rijksmuseum_uri'],
d['amsterdammuseum_uri'], d['stadsarchief_uri']
] if i is not None
]
artwork.sameAs = sameAs
depictions = []
if d['amsterdammuseum_uri']:
depictionsList = [
URIRef(i) for i in depictions_amsterdammuseum[
d['amsterdammuseum_uri']]
]
depictions += depictionsList
if d['rijksmuseum_uri']:
portrait = depictions_rijksmuseum.get(d['rijksmuseum_uri'])
if portrait:
depictions.append(URIRef(portrait))
if d['stadsarchief_uri']:
portrait = depictions_stadsarchief.get(d['stadsarchief_uri'])
if portrait:
depictions.append(URIRef(portrait))
artwork.depiction = depictions
# for the exampleResource
p = artwork
# For the person data
else:
for nrow, d in enumerate(data, 2):
# Prov
anno = Annotation(
nsAnnotation.term(str(d['id'])),
hasTarget=ResourceSelection(
None,
hasSource=filename,
hasSelector=FragmentSelector(
None,
conformsTo=URIRef("http://tools.ietf.org/rfc/rfc7111"),
value=f"row={nrow}")))
# Person
lifeEvents = []
gender = d['geslacht']
if gender == 'M':
gender = ga.Male
elif gender == "F":
gender = ga.Female
pn, labels = getPersonName(d)
# pid = str(next(personCounter))
personCounter = count(1)
roleCounter = count(1)
eventCounter = count(1)
pid = d['id']
person_sameAs = []
if Qid := d['Wikidata']:
person_sameAs.append(
URIRef("http://www.wikidata.org/entity/" + Qid))
p = Person(nsPerson.term(str(pid)),
hasName=pn,
gender=gender,
label=labels,
wasDerivedFrom=[anno],
sameAs=person_sameAs)
birthPlace = d['Doop/geboren te']
deathPlace = d['Begraven/overleden te']
birthDateEarliest, birthDateLatest, birthTimeStamp = parseDate(