-
Notifications
You must be signed in to change notification settings - Fork 47
/
positions.py
65 lines (50 loc) · 1.45 KB
/
positions.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
"""
Load the positions.csv file.
"""
import csv
import json
import sys
import logging
logging.basicConfig(level=logging.INFO)
from rdflib import Graph
from rdflib_jsonld.parser import to_rdf
from utils import ns_mgr, DATA_NAMESPACE
from utils import hash_uri
pos_ctx = {
"@context": {
"@base": DATA_NAMESPACE,
"a": "@type",
"uri": "@id",
"vivo": "http://vivoweb.org/ontology/core#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"label": "rdfs:label",
"relates": {
"@id": "vivo:relates",
"@type": "@id"
}
}
}
positions = []
with open(sys.argv[1]) as infile:
for count, row in enumerate(csv.DictReader(infile)):
fac_id = row['person_ID']
org_id = row['department_ID']
title = row['job_title']
#Create a hash local name for use in the URI.
uri_parts = "{}{}{}".format(fac_id, org_id, title)
position_uri = hash_uri(uri_parts, prefix='pos')
pos = {}
pos['uri'] = position_uri
pos['a'] = 'vivo:FacultyPosition'
pos['label'] = title
#Multiple relation statements as list.
pos['relates'] = [
'fac{}'.format(fac_id),
'org{}'.format(org_id)
]
pos.update(pos_ctx)
positions.append(pos)
raw_jld = json.dumps(positions)
g = Graph().parse(data=raw_jld, format='json-ld')
g.namespace_manager = ns_mgr
print g.serialize(format='turtle')