forked from CarnegieHall/linked-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_changeSerialization.py
More file actions
74 lines (62 loc) · 2.59 KB
/
Copy pathgraph_changeSerialization.py
File metadata and controls
74 lines (62 loc) · 2.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# !/usr/local/bin/python3.4.2
# ----Copyright (c) 2017 Carnegie Hall | The MIT License (MIT)----
# ----For the full license terms, please visit https://github.com/CarnegieHall/linked-data/blob/master/LICENSE----
## Argument[0] is script to run
## Argument[1] is path to graph
import os
import rdflib
from rdflib import Graph
from rdflib import Graph, Literal, Namespace, OWL, RDF, URIRef, XSD
from rdflib.namespace import DCTERMS, FOAF, OWL, RDF, RDFS, SKOS
from rdflib.plugins.serializers.nt import NTSerializer
from rdflib.plugins.serializers.turtle import TurtleSerializer
import sys
def fetch_name(filepath):
return os.path.splitext(os.path.basename(filepath))[0]
chnames = Namespace('http://data.carnegiehall.org/names/')
chvenues = Namespace('http://data.carnegiehall.org/venues/')
chinstruments = Namespace('http://data.carnegiehall.org/instruments/')
chworks = Namespace('http://data.carnegiehall.org/works/')
event = Namespace('http://purl.org/NET/c4dm/event.owl#')
gndo = Namespace('http://d-nb.info/standards/elementset/gnd#')
mo = Namespace ('http://purl.org/ontology/mo/')
schema = Namespace('http://schema.org/')
dbp = Namespace('http://dbpedia.org/ontology/')
dbpedia = Namespace('http://dbpedia.org/resource/')
gn = Namespace('http://www.geonames.org/ontology#')
mbz = Namespace('http://musicbrainz.org/artist/')
lcnaf = Namespace('http://id.loc.gov/authorities/names/')
lcMarcRel = Namespace('http://id.loc.gov/vocabulary/relators/')
wgs84_pos = Namespace('http://www.w3.org/2003/01/geo/wgs84_pos#')
filePath_1 = sys.argv[1]
fileName = fetch_name(filePath_1)
turtle = 'turtle'
ttl = 'ttl'
newSerialization = input('Enter new serialization: ')
newExtension = input('Enter new file extension: ')
print('The new serialization will be', newSerialization, 'with extension', newExtension)
g = Graph()
g.parse(filePath_1, format=str(newSerialization))
graph_path = os.path.join(
os.path.dirname(__file__), os.pardir, 'Graphs', (fileName + '.' + newExtension))
g.bind("chinstruments", chinstruments)
g.bind("chnames", chnames)
g.bind("chworks", chworks)
g.bind("dbpedia-owl", dbp)
g.bind("dbpedia", dbpedia)
g.bind("dcterms", DCTERMS)
g.bind("event", event)
g.bind("foaf", FOAF)
g.bind("gn", gn)
g.bind("gndo", gndo)
g.bind("lcnaf", lcnaf)
g.bind("lcMarRel", lcMarcRel)
g.bind("mbz", mbz)
g.bind("mo", mo)
g.bind("rdf", RDF)
g.bind("rdfs", RDFS)
g.bind("skos", SKOS)
g.bind("schema", schema)
g.bind("wgs84_pos", wgs84_pos)
g.serialize(destination=graph_path,format=str(newSerialization))
print('Finished converting', fileName, 'to', newSerialization)