-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2rdf.py
190 lines (151 loc) · 6.92 KB
/
2rdf.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
import datetime
from itertools import count
import pandas as pd
from rdflib import Dataset, Graph, URIRef, Namespace, Literal, XSD, OWL
from roar import rdfSubject
from roar import Agent, Activity, Derivation
from roar import VoidDataset, DataDownload, Document, Annotation, PersonObservation, PersonName, LocationObservation, ResourceSelection, FragmentSelector, TextualBody, Aggregation, WebResource
from roar import edm, roar, dc, oa, prov, dcterms, pnv, schema, void, foaf
create = Namespace("https://data.create.humanities.uva.nl/")
personCounter = count(1)
nsPersonObservation = Namespace(
"https://data.create.humanities.uva.nl/id/kohier1674/observations/PersonObservation/"
)
nsLocationObservation = Namespace(
"https://data.create.humanities.uva.nl/id/kohier1674/observations/LocationObservation/"
)
nsOccupationObservation = Namespace(
"https://data.create.humanities.uva.nl/id/kohier1674/observations/OccupationObservation/"
)
AGENT = Agent(URIRef("https://orcid.org/0000-0001-8672-025X"), label=["Leon van Wissen"])
ACTIVITY = Activity(
None,
wasAssociatedWith=[AGENT],
label=[Literal("OCR en correctie", lang='nl')],
comment=[
Literal(
"De scans van inventarisnummer 5028:662A zijn geOCRd met Tesseract (5.0.0-alpha) en daarna semi-automatisch gecorrigeerd.",
lang='nl')
])
DERIVATION = Derivation(None, hadActivity=ACTIVITY)
def main(csvfile, g):
df = pd.read_csv(csvfile)
df = df.where((pd.notnull(df)), None)
images = set()
for r in df.to_dict(orient='records'):
scanName, _ = r['source'].split('_')
pageNumber = int(scanName[-5:])
document = Document(URIRef(f"#p{pageNumber}")) #ProvidedCHO
image = URIRef(r['source'].replace('txt', 'tif'))
images.add(image)
aggregation = Aggregation(URIRef(
f"https://archief.amsterdam/archief/5028/662#p{pageNumber}"),
aggregatedCHO=document)
webResource = WebResource(
URIRef(f"https://archief.amsterdam/archief/5028/662A#{scanName}"))
aggregation.isShownAt = webResource
annotation = Annotation(
None,
hasTarget=ResourceSelection(
None,
hasSource=document,
hasSelector=FragmentSelector(
None,
conformsTo=URIRef("http://tools.ietf.org/rfc/rfc5147"),
value=f"line={r['lineNumber']}")),
hasBody=TextualBody(None,
value=r['reference'],
language="nl",
format="text/html"),
wasDerivedFrom=[image],
qualifiedDerivation=DERIVATION)
personNames = [
PersonName(
None,
baseSurname=r['baseSurname'],
givenName=r['givenName'],
surnamePrefix=r['surnamePrefix'],
disambiguatingDescription=r['disambiguatingDescription'],
literalName=" ".join([
i for i in
[r['givenName'], r['surnamePrefix'], r['baseSurname']]
if i is not None
]))
]
if r['altName']:
personNames.append(PersonName(None, literalName=r['altName']))
for name in personNames:
name.label = name.literalName
personObservation = PersonObservation(
nsPersonObservation.term(str(next(personCounter))),
hasName=personNames,
documentedIn=document,
locationInDocument=Literal(r['folio']) if r['folio'] else None,
wasDerivedFrom=[annotation])
personObservation.label = [i.literalName for i in personNames]
if r['neighbourhood']:
locationObservation = LocationObservation(
nsLocationObservation.term(r['neighbourhood']),
label=[r['neighbourhood']])
personObservation.hasLocation = [locationObservation]
DERIVATION.entity = sorted(images)
return personObservation # exampleResource
if __name__ == "__main__":
ds = Dataset()
g = rdfSubject.db = ds.graph(
identifier="https://data.create.humanities.uva.nl/id/kohier1674/")
exampleResource = main('data/records.csv', g)
rdfSubject.db = ds
description = """Van dit handgeschreven kohier (SAA inventarisnummer 5028:662) bestaat een getypte index op achternaam (SAA inventarisnummber 5028:662A). Hierin is de naam van een persoon, de relatie tot een andere persoon of groep (e.g. wed. van, of kinderen van), beroep en de woonwijk opgenomen. Ook is genoteerd op welk foliant de persoon beschreven is.
In totaal zijn 60 wijken beschreven in het kohier, aangegeven met cijfers. Daarna volgt een sectie van de 'Magistraten' (M), 'Joodse Natie' (J), 'Paden buijten de Stadt' (P1-P6), 'Officianten' (O), 'Regerende heeren' (R), 'Personen van andere Steden' (AS) en 'Testamenten' (T).
De wijkindeling correspondeert waarschijnlijk met die van een kaart uit 1766, vervaardigd door C. Philips Jacobsz. (1732-1789) en F.W. Greebe en is beschikbaar in de Beeldbank van het Stadsarchief, afbeelding 010001000849.
"""
contributors = ""
download = DataDownload(
None,
contentUrl=URIRef(
"https://github.com/LvanWissen/kohier-1674/raw/master/data/kohier1674.trig"
),
# name=Literal(),
url=URIRef("https://github.com/LvanWissen/kohier-1674"),
encodingFormat="application/trig")
dataset = VoidDataset(
URIRef("https://data.create.humanities.uva.nl/id/kohier1674/"),
name=[
Literal("Kohier van de 200ste penning, Amsterdam 1674", lang='nl')
],
about=None,
url=URIRef("https://github.com/LvanWissen/kohier-1674"),
description=[Literal(description, lang='nl')],
creator=[URIRef("https://orcid.org/0000-0001-8672-025X")],
publisher=[],
contributor=[],
source=None,
date=Literal(datetime.datetime.now().isoformat(),
datatype=XSD.datetime),
created=None,
issued=None,
modified=None,
exampleResource=exampleResource,
vocabulary=[URIRef("https://schema.org/")],
triples=sum(1 for i in ds.graph(
identifier="https://data.create.humanities.uva.nl/id/kohier1674/").
subjects()),
temporalCoverage=Literal("1674", datatype=XSD.gYear, normalize=False),
licenseprop=URIRef(
"https://creativecommons.org/licenses/by/4.0/"),
distribution=download)
ds.bind('owl', OWL)
ds.bind('create', create)
ds.bind('schema', schema)
ds.bind('void', void)
ds.bind('foaf', foaf)
ds.bind('edm', edm)
ds.bind('pnv', pnv)
ds.bind('roar', roar)
ds.bind('dc', dc)
ds.bind('dcterms', dcterms)
ds.bind('oa', oa)
ds.bind('prov', prov)
print("Serializing!")
ds.serialize('data/kohier1674.trig', format='trig')