forked from lawlesst/vivo-sample-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizations.py
More file actions
53 lines (38 loc) · 1 KB
/
organizations.py
File metadata and controls
53 lines (38 loc) · 1 KB
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
"""
Load the organization.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
org_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",
}
}
organizations = []
with open(sys.argv[1]) as infile:
for count, row in enumerate(csv.DictReader(infile)):
name = row['org_name']
oid = row['org_ID']
org_uri = 'org{}'.format(oid)
org_type = row['org_vivo_uri']
org = {}
org['uri'] = org_uri
org['a'] = org_type
org['label'] = name
org.update(org_ctx)
organizations.append(org)
g = Graph()
g.namespace_manager = ns_mgr
out = to_rdf(organizations, g)
print out.serialize(format='turtle')