@@ -216,15 +216,16 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
216
216
LOGGER .debug ('Generating baseline record' )
217
217
record = {
218
218
'identifier' : mcf ['metadata' ]['identifier' ],
219
- '@type' : dict (zip (TYPES .values (), TYPES .keys ()))[mcf ['metadata' ]['hierarchylevel' ]], # noqa
219
+ "@context" : "http://schema.org/" ,
220
+ '@type' : 'schema:' + dict (zip (TYPES .values (), TYPES .keys ()))[mcf ['metadata' ]['hierarchylevel' ]], # noqa
220
221
'spatialCoverage' : [{
221
- '@type' : 'Place' ,
222
+ '@type' : 'schema: Place' ,
222
223
'geo' : {
223
- '@type' : 'GeoShape' ,
224
+ '@type' : 'schema: GeoShape' ,
224
225
'box' : f'{ miny } ,{ minx } { maxy } ,{ maxx } '
225
226
}
226
227
}],
227
- 'title ' : title [0 ],
228
+ 'name ' : title [0 ],
228
229
'description' : description [0 ],
229
230
'distribution' : []
230
231
}
@@ -234,7 +235,7 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
234
235
235
236
LOGGER .debug ('Checking for temporal' )
236
237
try :
237
- begin = mcf ['identification' ]['extents' ]['temporal' ][0 ][ 'begin' ]
238
+ begin = mcf ['identification' ]['extents' ]['temporal' ][0 ]. get ( 'begin' )
238
239
end = mcf ['identification' ]['extents' ]['temporal' ][0 ].get ('end' )
239
240
240
241
if begin in ['now' , 'None' , None ]:
@@ -267,8 +268,9 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
267
268
record ['datePublished' ] = generate_datetime (value )
268
269
269
270
LOGGER .debug ('Checking for contacts' )
270
- record ['contacts' ] = self .generate_contacts (
271
- mcf ['contact' ])
271
+ for ct in ['author' , 'publisher' , 'creator' , 'provider' , 'funder' ]:
272
+ record [ct ] = self .generate_contacts (
273
+ mcf ['contact' ], ct )
272
274
273
275
all_keywords = []
274
276
@@ -306,13 +308,7 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
306
308
307
309
if 'url' in license :
308
310
LOGGER .debug ('Encoding license as link' )
309
- license_link = {
310
- 'rel' : 'license' ,
311
- 'type' : 'text/html' ,
312
- 'title' : license .get ('name' , 'license for this resource' ),
313
- 'url' : license ['url' ]
314
- }
315
- record ['distribution' ].append (self .generate_link (license_link ))
311
+ record ['license' ] = license ['url' ]
316
312
else :
317
313
LOGGER .debug ('Encoding license as property' )
318
314
record ['license' ] = license ['name' ]
@@ -327,14 +323,14 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
327
323
return record
328
324
329
325
def generate_party (self , contact : dict ,
330
- lang1 : str , lang2 : str , roles : list ) -> dict :
326
+ lang1 : str , lang2 : str ) -> dict :
331
327
"""
332
328
generate party construct from MCF contact
333
329
334
330
:param contact: dict of MCF contact
335
331
:param self.lang1: primary language
336
332
:param self.lang2: alternate language
337
- :param roles: roles of contact
333
+
338
334
339
335
:returns: MCF contact as a party representation
340
336
"""
@@ -373,60 +369,58 @@ def generate_party(self, contact: dict,
373
369
'roles' : []
374
370
}
375
371
376
- if organization_name [0 ] is not None :
377
- rp ['organization' ] = organization_name [0 ]
378
372
if individual_name [0 ] is not None :
373
+ rp ['@type' ] = "schema:Person"
379
374
rp ['name' ] = individual_name [0 ]
380
- if position_name [0 ] is not None :
381
- rp ['position' ] = position_name [0 ]
382
- if hours_of_service [0 ] is not None :
383
- rp ['hoursOfService' ] = hours_of_service [0 ]
384
- if contact_instructions [0 ] is not None :
385
- rp ['contactInstructions' ] = contact_instructions [0 ]
375
+ if position_name [0 ] is not None :
376
+ rp ['jobTitle' ] = position_name [0 ]
377
+ rp ['affiliation' ] = {
378
+ '@type' : "schema:Organization" ,
379
+ 'name' : organization_name [0 ]
380
+ }
381
+ else :
382
+ rp ['@type' ] = "schema:Organization"
383
+ rp ['name' ] = organization_name [0 ]
384
+
385
+ #if hours_of_service[0] is not None:
386
+ # rp['hoursOfService'] = hours_of_service[0]
387
+ #if contact_instructions[0] is not None:
388
+ # rp['contactInstructions'] = contact_instructions[0]
386
389
387
390
if address [0 ] is not None :
388
- rp ['addresses' ][0 ]['deliveryPoint' ] = [address [0 ]]
389
- if city [0 ] is not None :
390
- rp ['addresses' ][0 ]['city' ] = city [0 ]
391
- if administrative_area [0 ] is not None :
392
- rp ['addresses' ][0 ]['administrativeArea' ] = administrative_area [0 ]
393
- if postalcode [0 ] is not None :
394
- rp ['addresses' ][0 ]['postalCode' ] = postalcode [0 ]
395
- if country [0 ] is not None :
396
- rp ['addresses' ][0 ]['country' ] = country [0 ]
391
+ rp ['address' ] = {"@type" : "schema:PostalAddress" }
392
+ rp ['address' ]['streetAddress' ] = address [0 ]
393
+ if city [0 ] is not None :
394
+ rp ['address' ]['addressLocality' ] = city [0 ]
395
+ if administrative_area [0 ] is not None :
396
+ rp ['address' ]['addressRegion' ] = administrative_area [0 ]
397
+ if postalcode [0 ] is not None :
398
+ rp ['address' ]['postalCode' ] = postalcode [0 ]
399
+ if country [0 ] is not None :
400
+ rp ['address' ]['addressCountry' ] = country [0 ]
397
401
398
402
if contact .get ('phone' ) is not None :
399
403
LOGGER .debug ('Formatting phone number' )
400
404
phone = contact ['phone' ]
401
405
phone = phone .replace ('-' , '' ).replace ('(' , '' ).replace (')' , '' )
402
406
phone = phone .replace ('+0' , '+' ).replace (' ' , '' )
403
-
404
- rp ['phones' ] = [{'value' : phone }]
407
+ rp ['telephone' ] = phone
405
408
406
409
if contact .get ('email' ) is not None :
407
- rp ['emails' ] = [{'value' : contact .get ('email' )}]
408
-
409
- if rp ['addresses' ][0 ] == {}:
410
- rp .pop ('addresses' )
411
-
412
- for r in set (roles ):
413
- rp ['roles' ].append (r )
410
+ rp ['email' ] = contact .get ('email' )
414
411
415
412
if 'url' in contact :
416
- rp ['distribution' ] = [{
417
- 'rel' : 'canonical' ,
418
- 'type' : 'text/html' ,
419
- 'href' : contact ['url' ]
420
- }]
413
+ rp ['url' ] = contact ['url' ]
421
414
422
415
return rp
423
416
424
- def generate_contacts (self , contact : dict ) -> list :
417
+ def generate_contacts (self , contact : dict , tp : str ) -> list :
425
418
"""
426
419
Generates 1..n contacts, streamlining identical
427
420
contacts with multiple roles
428
421
429
422
:param contact: `dict` of contacts
423
+ :param tp: `str` of role
430
424
431
425
:returns: `list` of contacts
432
426
"""
@@ -435,29 +429,16 @@ def generate_contacts(self, contact: dict) -> list:
435
429
contacts2 = []
436
430
437
431
for key , value in contact .items ():
438
- if contacts :
439
- for c in contacts :
440
- if value == c ['contact' ]:
441
- LOGGER .debug ('Found matching contact; adding role' )
442
- c ['roles' ].append (key )
443
- else :
444
- LOGGER .debug ('Adding contact' )
445
- contacts .append ({
446
- 'contact' : value ,
447
- 'roles' : [key ]
448
- })
449
- else :
450
- contacts .append ({
451
- 'contact' : value ,
452
- 'roles' : [key ]
453
- })
432
+ if key == tp or value .get ('role' ,'' ) == tp :
433
+ contacts .append (
434
+ self .generate_party (value , self .lang1 ,
435
+ self .lang2 ))
436
+
437
+
454
438
455
- LOGGER .debug (f'Contacts: { contacts } ' )
456
- for c in contacts :
457
- contacts2 .append (self .generate_party (c ['contact' ], self .lang1 ,
458
- self .lang2 , c ['roles' ]))
459
439
460
- return contacts2
440
+
441
+ return contacts
461
442
462
443
def generate_link (self , distribution : dict ) -> dict :
463
444
"""
@@ -471,20 +452,27 @@ def generate_link(self, distribution: dict) -> dict:
471
452
name = get_charstring (distribution .get ('name' ),
472
453
self .lang1 , self .lang2 )
473
454
455
+ desc = get_charstring (distribution .get ('description' ),
456
+ self .lang1 , self .lang2 )
457
+
474
458
link = {
459
+ '@type' : 'schema:DataDownload' ,
475
460
'contentUrl' : distribution ['url' ]
476
461
}
477
462
478
463
if distribution .get ('type' ) is not None :
479
- link ['type ' ] = distribution ['type' ]
464
+ link ['encodingFormat ' ] = distribution ['type' ]
480
465
481
- reltype = distribution .get ('rel' ) or distribution .get ('function' )
482
- if reltype is not None :
483
- link ['rel' ] = reltype
466
+ # reltype = distribution.get('rel') or distribution.get('function')
467
+ # if reltype is not None:
468
+ # link['rel'] = reltype
484
469
485
470
if name != [None , None ]:
486
471
link ['name' ] = name [0 ]
487
472
elif name != [None , None ]:
488
473
link ['name' ] = name [0 ]
474
+
475
+ if desc != [None , None ]:
476
+ link ['description' ] = desc [0 ]
489
477
490
478
return link
0 commit comments