48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import json
|
|
import sys
|
|
from urllib.parse import quote
|
|
|
|
#{
|
|
# "pid":"trr379root:projects/q02",
|
|
# "attributed_to":[{"object":"trr379root:contributors/michael-hanke","roles":["marcrel:rth"],"display_label":"Hanke, Michael (team lead)"},...]}
|
|
#}
|
|
|
|
# this is the main PID mapping from the DFG survey context to the metadata
|
|
# pooling system for person records
|
|
with open('dfg-cp_pid-map.json') as fobj:
|
|
dfgcp_id_map = json.load(fobj)
|
|
|
|
projects = {}
|
|
|
|
with open('records/TRR379Project.jsonl') as fobj:
|
|
for line in fobj:
|
|
rec = json.loads(line)
|
|
projects[rec['pid']] = rec
|
|
|
|
for line in sys.stdin:
|
|
j = json.loads(line)
|
|
if j['pid'] not in dfgcp_id_map:
|
|
msg = f'Unknown person PID, please map: {j!r}'
|
|
raise ValueError(msg)
|
|
|
|
if j['person_identity_consent'] != 'yes':
|
|
continue
|
|
|
|
# this PID must be a valid URI in the end, so we must quote any invalid chars.
|
|
# however, the mapping declared above should already take care of (most) of this
|
|
mpid = dfgcp_id_map[j["pid"]]
|
|
mpid = quote(mpid, safe='/:')
|
|
outpid = f'trr379root:contributors/{mpid}'
|
|
|
|
for p in j['consortium_participation']:
|
|
for pp in p.get('participation_project', []):
|
|
curr_proj = projects[pp]
|
|
proj_attributions = curr_proj.get('attributed_to', [])
|
|
if not any(m['object'] == outpid for m in proj_attributions):
|
|
# we cannot really derive roles within a project from the
|
|
# DFG status groups
|
|
proj_attributions.append({'object': outpid})
|
|
curr_proj['attributed_to'] = proj_attributions
|
|
|
|
for p in projects:
|
|
print(json.dumps(projects[p], ensure_ascii=False))
|