comparison rdfpy/writeTimbreToolboxOnto.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents
children
comparison
equal deleted inserted replaced
17:2b5c292ad12f 18:d5012016bf64
1 import rdflib, os, fnmatch, urllib2
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace
3
4 graph = Graph()
5
6 af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/features/')
7 graph.bind('af', af)
8
9 dc = Namespace('http://purl.org/dc/elements/1.1/')
10 graph.bind('dc', dc)
11
12 owl = Namespace('http://www.w3.org/2002/07/owl#')
13 graph.bind('owl', owl)
14
15 xsd = Namespace('http://www.w3.org/2001/XMLSchema#')
16 graph.bind('xsd', xsd)
17
18
19 input = {
20 'au': "Audio Signal",
21 'tee': "Temporal Energy Envelope",
22 'stft': "Short-term Fourier Transform",
23 'erb': "Auditory model",
24 'harm': "Harmonic"
25 }
26
27 graph.add((
28 URIRef(af+"AudioDescriptor"),
29 RDF.type,
30 OWL.Class
31 ))
32 graph.add((
33 URIRef(af+"AudioDescriptor"),
34 RDFS.label,
35 Literal("Timbre Toolbox Audio Descriptor", lang="en")
36 ))
37
38
39 graph.add((
40 URIRef(af+"InputSignal"),
41 RDF.type,
42 OWL.Class
43 ))
44 graph.add((
45 URIRef(af+"InputSignal"),
46 RDFS.label,
47 Literal("Timbre Toolbox Input Representation", lang="en")
48 ))
49
50 graph.add((
51 URIRef(af+"inputRepresentation"),
52 RDF.type,
53 OWL.ObjectProperty
54 ))
55 graph.add((
56 URIRef(af+"inputRepresentation"),
57 RDFS.domain,
58 URIRef(af+"AudioDescriptor")
59 ))
60 graph.add((
61 URIRef(af+"inputRepresentation"),
62 RDFS.range,
63 URIRef(af+"InputSignal")
64 ))
65
66
67
68 for inkey in input.keys():
69 id = af+input[inkey].replace(" ", "")
70 graph.add((
71 URIRef(id),
72 RDF.type,
73 OWL.Class
74 ))
75 graph.add((
76 URIRef(id),
77 RDFS.label,
78 Literal(input[inkey], lang="en")
79 ))
80 graph.add((
81 URIRef(id),
82 RDFS.subClassOf,
83 URIRef(af+"InputSignal")
84 ))
85
86 features = {
87 'Global Descriptors': [
88 {"Attack": "tee"},
89 {"Decay": "tee"},
90 {"Release": "tee"},
91 {"Log-Attack Time": "tee"},
92 {"Attack Slope": "tee"},
93 {"DecreaseSlope": "tee"},
94 {"Temporal Centroid": "tee"},
95 {"Effective Duration": "tee"},
96 {"Frequency of Energy Modulation": "tee"},
97 {"Amplitude of Energy Modulation": "tee"}
98 ],
99
100 'Time-Varying Descriptors': [
101 {"Autocorrelation": 'au'},
102 {"Zero Crossing Rate": 'au'},
103 {"RMS-Energy Envelope": 'tee'},
104 {"Spectral Centroid": 'stft,erb,harm'},
105 {"Spectral Spread": 'stft,erb,harm'},
106 {"Spectral Skewness": 'stft,erb,harm'},
107 {"Spectral Kurtosis": 'stft,erb,harm'},
108 {"Spectral Slope": 'stft,erb,harm'},
109 {"Spectral Decrease": 'stft,erb,harm'},
110 {"Spectral Rolloff": 'stft,erb,harm'},
111 {"Spectro-temporal Variation": 'stft,erb,harm'},
112 {"Spectral Flatness": 'stft,erb'},
113 {"Spectral Crest": 'stft,erb'},
114 {"Harmonic Energy": 'harm'},
115 {"Noise Energy": 'harm'},
116 {"Noisiness": 'harm'},
117 {"Fundamental Frequency": 'harm'},
118 {"Inharmonicity": 'harm'},
119 {"Tristimulus": 'harm'},
120 {"Harmonic Spectral Deviation": 'harm'},
121 {"Odd to even harmonic ratio": 'harm'}
122 ]
123 }
124
125 for temporal in features.keys():
126 auid = af + temporal[:-1].replace("-", "").replace(" ", "")
127 graph.add((
128 URIRef(auid),
129 RDF.type,
130 OWL.Class
131 ))
132 graph.add((
133 URIRef(auid),
134 RDFS.subClassOf,
135 URIRef(af+"AudioDescriptor")
136 ))
137
138 for feature in features[temporal]:
139 name = feature.keys()[0]
140 id = af + name.replace(" ", "")
141 #graph.add((
142 # URIRef(id),
143 # RDF.type,
144 # OWL.Class
145 #))
146 graph.add((
147 URIRef(id),
148 RDF.type,
149 URIRef(af+"AudioFeature")
150 ))
151 graph.add((
152 URIRef(id),
153 RDFS.label,
154 Literal(name, lang="en")
155 ))
156 graph.add((
157 URIRef(id),
158 RDFS.subClassOf,
159 URIRef(auid)
160 ))
161 for inp in feature[name].split(","):
162 graph.add((
163 URIRef(id),
164 URIRef(af+"inputRepresentation"),
165 URIRef(af+input[inp].replace(" ", ""))
166 ))
167
168
169 graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.rdf')
170 graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.n3', format="n3")
171