-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssif_terms_to_skos_ttl.py
37 lines (34 loc) · 1.2 KB
/
ssif_terms_to_skos_ttl.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
import csv
import os
import sys
from datetime import datetime
if len(sys.argv) != 2:
print(f"Usage: {os.path.basename(__file__)} csv_file")
sys.exit(1)
print(f"# Generated by {os.path.basename(__file__)} from {sys.argv[1]} on {datetime.now().isoformat()}")
print("@prefix ssif: <https://begrepp.uka.se/SSIF/> .")
print("@prefix skos: <http://www.w3.org/2004/02/skos/core#> .")
with open(sys.argv[1], newline="") as csvfile:
reader = csv.DictReader(csvfile, delimiter=",", quotechar='"')
for row in reader:
data = {k: v.strip() for k, v in row.items()}
if data["level1"]:
print(f"""
ssif:{data['level1']} a skos:Concept ;
skos:inScheme ssif: ;
skos:prefLabel "{data["en"]}"@en,
"{data["sv"]}"@sv .""")
if data["level2"]:
print(f"""
ssif:{data['level2']} a skos:Concept ;
skos:inScheme ssif: ;
skos:broader ssif:{data["level2"][:1]} ;
skos:prefLabel "{data["en"]}"@en,
"{data["sv"]}"@sv .""")
if data["level3"]:
print(f"""
ssif:{data['level3']} a skos:Concept ;
skos:inScheme ssif: ;
skos:broader ssif:{data["level3"][:3]} ;
skos:prefLabel "{data["en"]}"@en,
"{data["sv"]}"@sv .""")