-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroar.py
435 lines (283 loc) · 11.3 KB
/
roar.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
"""
ROAR ontology, plus several usefull classes from edm, schema, bio etc.
"""
from rdflib import Dataset, Graph, Namespace
from rdflib import XSD, RDF, RDFS, OWL
from rdflib import URIRef, BNode, Literal
from rdfalchemy.rdfSubject import rdfSubject
from rdfalchemy import rdfSingle, rdfMultiple, rdfContainer, rdfList
bio = Namespace("http://purl.org/vocab/bio/0.1/")
edm = Namespace("http://www.europeana.eu/schemas/edm/")
sem = Namespace("http://semanticweb.cs.vu.nl/2009/11/sem/")
rel = Namespace("http://purl.org/vocab/relationship/")
pnv = Namespace('https://w3id.org/pnv#')
skos = Namespace('http://www.w3.org/2004/02/skos/core#')
schema = Namespace('http://schema.org/')
dc = Namespace("http://purl.org/dc/elements/1.1/")
dcterms = Namespace("http://purl.org/dc/terms/")
AS = Namespace("http://www.w3.org/ns/activitystreams#")
oa = Namespace("http://www.w3.org/ns/oa#")
void = Namespace("http://rdfs.org/ns/void#")
foaf = Namespace("http://xmlns.com/foaf/0.1/")
prov = Namespace("http://www.w3.org/ns/prov#")
roar = Namespace("https://w3id.org/roar#")
PersonObservation = Namespace(
"https://data.create.humanities.uva.nl/datasets/kohier1674/observations/PersonObservation/"
)
OccupationObservation = Namespace(
"https://data.create.humanities.uva.nl/datasets/kohier1674/observations/OccupationObservation/"
)
class Entity(rdfSubject):
rdf_type = prov.Entity
locationInDocument = rdfSingle(roar.locationInDocument)
name = rdfMultiple(schema.name)
url = rdfSingle(schema.url)
# Void
class VoidDataset(rdfSubject):
rdf_type = void.Dataset, schema.Dataset
subset = rdfMultiple(void.subset)
label = rdfMultiple(RDFS.label)
name = rdfMultiple(schema.name)
# db = ConjunctiveGraph
about = rdfSingle(schema.about)
url = rdfSingle(schema.url)
title = rdfMultiple(dcterms.title)
description = rdfMultiple(dcterms.description)
creator = rdfMultiple(dcterms.creator)
publisher = rdfMultiple(dcterms.publisher)
contributor = rdfMultiple(dcterms.contributor)
source = rdfSingle(dcterms.source)
date = rdfSingle(dcterms.date)
created = rdfSingle(dcterms.created)
issued = rdfSingle(dcterms.issued)
modified = rdfSingle(dcterms.modified)
exampleResource = rdfSingle(void.exampleResource)
vocabulary = rdfMultiple(void.vocabulary)
triples = rdfSingle(void.triples)
descriptionSchema = rdfMultiple(schema.description)
isBasedOn = rdfSingle(schema.isBasedOn)
dateCreated = rdfSingle(schema.dateCreated)
distribution = rdfSingle(schema.distribution)
licenseprop = rdfSingle(schema.license)
alternateName = rdfMultiple(schema.alternateName)
citation = rdfMultiple(schema.citation)
keywords = rdfMultiple(schema.keywords)
spatialCoverage = rdfSingle(schema.spatialCoverage)
temporalCoverage = rdfSingle(schema.temporalCoverage)
class DataDownload(Entity):
rdf_type = schema.DataDownload
contentUrl = rdfSingle(schema.contentUrl)
encodingFormat = rdfSingle(schema.encodingFormat)
# Prov
class Derivation(rdfSubject):
rdf_type = prov.Derivation
hadActivity = rdfSingle(prov.hadActivity, range_type=prov.Activity)
entity = rdfMultiple(prov.entity, range_type=prov.Entity)
class Activity(rdfSubject):
rdf_type = prov.Activity
wasAssociatedWith = rdfSingle(prov.wasAssociatedWith,
range_type=prov.Agent)
qualifiedAssociation = rdfSingle(prov.qualifiedAssociation,
range_type=prov.Association)
comment = rdfSingle(RDFS.comment)
class Association(rdfSubject):
rdf_type = prov.Association
hadPlan = rdfSingle(prov.hadPlan, range_type=prov.Plan)
agent = rdfSingle(prov.agent, range_type=prov.Agent)
comment = rdfSingle(RDFS.comment)
class Plan(rdfSubject):
rdf_type = prov.Plan
comment = rdfSingle(RDFS.comment)
class Agent(rdfSubject):
rdf_type = prov.Agent
#############
# SAA Index #
#############
class Entity(rdfSubject):
rdf_type = prov.Entity
label = rdfMultiple(RDFS.label)
comment = rdfMultiple(RDFS.comment)
wasDerivedFrom = rdfMultiple(prov.wasDerivedFrom)
qualifiedDerivation = rdfSingle(prov.qualifiedDerivation,
range_type=prov.Derivation)
inDataset = rdfSingle(void.inDataset)
hasLocation = rdfMultiple(roar.hasLocation)
documentedIn = rdfSingle(roar.documentedIn)
identifier = rdfSingle(schema.identifier)
class Observation(Entity):
rdf_type = roar.Observation
locationInDocument = rdfSingle(roar.locationInDocument)
class Reconstruction(Entity):
rdf_type = roar.Reconstruction
sameAs = rdfSingle(schema.sameAs)
class ProvidedCHO(Entity):
rdf_type = edm.ProvidedCHO
class WebResource(Entity):
rdf_type = edm.WebResource
class Aggregation(Entity):
rdf_type = edm.Aggregation
aggregatedCHO = rdfSingle(edm.aggregatedCHO)
hasView = rdfSingle(edm.hasView)
isShownAt = rdfSingle(edm.isShownAt)
isShownBy = rdfSingle(edm.isShownBy)
class Document(Entity):
rdf_type = roar.Document, edm.ProvidedCHO
identifier = rdfSingle(schema.identifier)
language = rdfSingle(schema.isInLanguage)
label = rdfMultiple(RDFS.label)
onScan = rdfMultiple(roar.onScan)
items = rdfList(AS.items) # rdf:Collection
prev = rdfSingle(AS.prev)
next = rdfSingle(AS.next)
class Derivation(rdfSubject):
rdf_type = prov.Derivation
label = rdfMultiple(RDFS.label)
comment = rdfMultiple(RDFS.comment)
hadActivity = rdfSingle(prov.hadActivity)
entity = rdfMultiple(prov.entity)
class Activity(rdfSubject):
rdf_type = prov.Activity
label = rdfMultiple(RDFS.label)
comment = rdfMultiple(RDFS.comment)
wasAssociatedWith = rdfMultiple(prov.wasAssociatedWith,
range_type=prov.Agent)
qualifiedAssociation = rdfSingle(prov.qualifiedAssociation,
range_type=prov.Association)
class Agent(rdfSubject):
rdf_type = prov.Agent
label = rdfMultiple(RDFS.label)
comment = rdfMultiple(RDFS.comment)
class StructuredValue(rdfSubject):
value = rdfSingle(RDF.value)
role = rdfSingle(roar.role)
hasTimeStamp = rdfSingle(sem.hasTimeStamp)
hasBeginTimeStamp = rdfSingle(sem.hasBeginTimeStamp)
hasEndTimeStamp = rdfSingle(sem.hasEndTimeStamp)
hasEarliestBeginTimeStamp = rdfSingle(sem.hasEarliestBeginTimeStamp)
hasLatestBeginTimeStamp = rdfSingle(sem.hasLatestBeginTimeStamp)
hasEarliestEndTimeStamp = rdfSingle(sem.hasEarliestEndTimeStamp)
hasLatestEndTimeStamp = rdfSingle(sem.hasLatestEndTimeStamp)
label = rdfMultiple(RDFS.label)
##########
# Person #
##########
class Person(Entity):
rdf_type = schema.Person
hasName = rdfMultiple(pnv.hasName, range_type=pnv.PersonName) # resource
label = rdfMultiple(RDFS.label)
birth = rdfSingle(bio.birth)
death = rdfSingle(bio.death)
event = rdfMultiple(bio.event)
birthDate = rdfSingle(schema.birthDate)
birthPlace = rdfSingle(schema.birthPlace)
deathDate = rdfSingle(schema.deathDate)
deathPlace = rdfSingle(schema.deathPlace)
gender = rdfSingle(schema.gender)
mother = rdfSingle(bio.mother)
father = rdfSingle(bio.father)
child = rdfSingle(bio.child)
spouse = rdfMultiple(schema.spouse)
parent = rdfMultiple(schema.parent)
children = rdfMultiple(schema.children)
hasOccupation = rdfMultiple(schema.hasOccupation)
address = rdfSingle(schema.address)
homeLocation = rdfSingle(schema.homeLocation)
depiction = rdfSingle(foaf.depiction)
class PersonObservation(Person, Observation):
rdf_type = roar.PersonObservation
class PersonReconstruction(Person, Reconstruction):
rdf_type = roar.PersonReconstruction
class LocationObservation(Observation):
rdf_type = roar.LocationObservation
hasPerson = rdfMultiple(roar.hasPerson)
address = rdfSingle(schema.address)
geoWithin = rdfSingle(schema.geoWithin)
class LocationReconstruction(Reconstruction):
rdf_type = roar.LocationReconstruction
class PostalAddress(Entity):
rdf_type = schema.PostalAddress
streetAddress = rdfSingle(schema.streetAddress)
addressRegion = rdfSingle(schema.addressRegion)
postalCode = rdfSingle(schema.postalCode)
disambiguatingDescription = rdfSingle(schema.disambiguatingDescription)
class PersonName(rdfSubject):
rdf_type = pnv.PersonName
label = rdfSingle(RDFS.label)
literalName = rdfSingle(pnv.literalName)
givenName = rdfSingle(pnv.givenName)
surnamePrefix = rdfSingle(pnv.surnamePrefix)
baseSurname = rdfSingle(pnv.baseSurname)
prefix = rdfSingle(pnv.prefix)
disambiguatingDescription = rdfSingle(pnv.disambiguatingDescription)
patronym = rdfSingle(pnv.patronym)
surname = rdfSingle(pnv.surname)
nameSpecification = rdfSingle(pnv.nameSpecification)
class Occupation(rdfSubject):
rdf_type = schema.Occupation
label = rdfMultiple(RDFS.label)
name = rdfMultiple(schema.name)
occupationalCategory = rdfMultiple(schema.occupationalCategory,
range_type=schema.CategoryCode)
class OccupationObservation(Entity):
rdf_type = roar.OccupationObservation
label = rdfMultiple(RDFS.label)
name = rdfMultiple(schema.name)
occupationalCategory = rdfMultiple(schema.occupationalCategory,
range_type=schema.CategoryCode)
class CategoryCode(rdfSubject):
rdf_type = schema.CategoryCode
inCodeSet = rdfSingle(schema.inCodeSet, range_type=schema.CategoryCodeSet)
codeValue = rdfSingle(schema.codeValue)
label = rdfMultiple(RDFS.label)
name = rdfMultiple(schema.name)
class CategoryCodeSet(rdfSubject):
rdf_type = schema.CategoryCodeSet
label = rdfMultiple(RDFS.label)
name = rdfMultiple(schema.name)
# {
# "@context": "http://schema.org/",
# "@type": "Occupation",
# "name": "Film actor",
# "occupationalCategory": {
# "@type": "CategoryCode",
# "inCodeSet": {
# "@type": "CategoryCodeSet",
# "name": "HISCO"
# },
# "codeValue": "17320",
# "name": "Actor"
# }
# }
class Annotation(Entity):
rdf_type = oa.Annotation
hasTarget = rdfSingle(oa.hasTarget)
bodyValue = rdfSingle(oa.bodyValue)
hasBody = rdfSingle(oa.hasBody) # or multiple?
motivatedBy = rdfSingle(oa.motivatedBy)
depiction = rdfSingle(foaf.depiction)
class SpecificResource(Entity):
rdf_type = oa.SpecificResource
hasSource = rdfSingle(oa.hasSource)
hasSelector = rdfSingle(oa.hasSelector)
hasState = rdfSingle(oa.hasState)
hasPurpose = rdfSingle(oa.hasPurpose)
class Selector(Entity):
rdf_type = oa.Selector
class FragmentSelector(Entity):
rdf_type = oa.FragmentSelector
conformsTo = rdfSingle(dcterms.conformsTo)
value = rdfSingle(RDF.value)
class TextQuoteSelector(Entity):
rdf_type = oa.TextQuoteSelector
class TextPositionSelector(Entity):
rdf_type = oa.TextPositionSelector
class ResourceSelection(Entity):
rdf_type = None
hasSource = rdfSingle(oa.hasSource)
hasSelector = rdfSingle(oa.hasSelector)
hasState = rdfSingle(oa.hasState)
class TextualBody(Entity):
rdf_type = oa.TextualBody
value = rdfSingle(RDF.value)
language = rdfSingle(dc.language)
format = rdfSingle(dc.term('format'))