nothing@1
|
1 import rdflib, os, fnmatch, urllib2
|
nothing@1
|
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL
|
nothing@1
|
3 from xml.dom.minidom import parseString
|
nothing@1
|
4
|
nothing@1
|
5 names = [line.strip() for line in open('pdfextract/names.txt')]
|
nothing@1
|
6 cat = [line.strip() for line in open('pdfextract/categories.txt')]
|
nothing@1
|
7 sig = [line.strip() for line in open('pdfextract/sig.txt')]
|
nothing@1
|
8
|
nothing@1
|
9 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/'
|
nothing@1
|
10
|
nothing@1
|
11 afgr = Graph()
|
nothing@1
|
12 afgr.bind('af', URIRef(local))
|
nothing@1
|
13 afgr.bind('dc', URIRef('http://purl.org/dc/elements/1.1/'))
|
nothing@1
|
14 afgr.bind('owl', URIRef('http://www.w3.org/2002/07/owl#'))
|
nothing@1
|
15
|
nothing@1
|
16 def split_uppercase(string):
|
nothing@1
|
17 x=''
|
nothing@1
|
18 for i in string:
|
nothing@1
|
19 if i.isupper():
|
nothing@1
|
20 x+=' %s' %i
|
nothing@1
|
21 else:
|
nothing@1
|
22 x+=i
|
nothing@1
|
23 return x.strip()
|
nothing@1
|
24
|
nothing@1
|
25
|
nothing@1
|
26 i = 0
|
nothing@1
|
27
|
nothing@1
|
28 order = [
|
nothing@1
|
29 "Zero Crossing Rate",
|
nothing@1
|
30 "Linear Predictive Coding",
|
nothing@1
|
31 "Mel-scale Frequency Cepstral Coefficients",
|
nothing@1
|
32 "Auditory Filter Bank Temporal Envelopes",
|
nothing@1
|
33 "Rate-scale-frequency Features",
|
nothing@1
|
34 "Phase Space Features"
|
nothing@1
|
35 ]
|
nothing@1
|
36
|
nothing@1
|
37 domains = {
|
nothing@1
|
38 "Zero Crossing Rate": 'temporal',
|
nothing@1
|
39 "Linear Predictive Coding": 'frequency',
|
nothing@1
|
40 "Mel-scale Frequency Cepstral Coefficients": 'cepstral',
|
nothing@1
|
41 "Auditory Filter Bank Temporal Envelopes": 'modulation frequency',
|
nothing@1
|
42 "Rate-scale-frequency Features": 'eigendomain',
|
nothing@1
|
43 "Phase Space Features": 'phase space'
|
nothing@1
|
44 }
|
nothing@1
|
45
|
nothing@1
|
46 abbr = {
|
nothing@1
|
47 "Zero Crossing Rate": "ZCR",
|
nothing@1
|
48 "Mel-scale Frequency Cepstral Coefficients": "MFCC",
|
nothing@1
|
49 "Linear Predictive Coding": "LPC",
|
nothing@1
|
50 "Linear Prediction Cepstral Coefficients": "LPCC",
|
nothing@1
|
51 "Zero crossing peak amplitudes": "ZCPA",
|
nothing@1
|
52 "Line spectral frequencies": "LSF",
|
nothing@1
|
53 "Short-time energy": "STE",
|
nothing@1
|
54 "Amplitude descriptor": "AD",
|
nothing@1
|
55 "Adaptive time frequency transform": "ATFT",
|
nothing@1
|
56 "Daubechies Wavelet coefficient histogram": "DWCH",
|
nothing@1
|
57 "Spectral Flux": "SF",
|
nothing@1
|
58 "Group delay function": "GDF",
|
nothing@1
|
59 "Modified group delay function": "MGDF",
|
nothing@1
|
60 "Spectral centroid": "SC",
|
nothing@1
|
61 "Subband spectral flux": "SSF",
|
nothing@1
|
62 "Perceptual linear prediction": "PLP"
|
nothing@1
|
63 }
|
nothing@1
|
64
|
nothing@1
|
65
|
nothing@1
|
66 domain = ""
|
nothing@1
|
67 domainIndex = 0
|
nothing@1
|
68 compdict = {}
|
nothing@1
|
69
|
nothing@1
|
70 for filename in ['filters', 'trans', 'aggr']:
|
nothing@1
|
71 for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]:
|
nothing@1
|
72 compdict[line[0]] = line[2:]
|
nothing@1
|
73
|
nothing@1
|
74
|
nothing@1
|
75
|
nothing@1
|
76 for name in names:
|
nothing@1
|
77 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
78
|
nothing@1
|
79 if name == order[domainIndex]:
|
nothing@1
|
80 domain = domains[order[domainIndex]]
|
nothing@1
|
81 domainIndex += 1
|
nothing@1
|
82
|
nothing@1
|
83 '''
|
nothing@1
|
84 afgr.add(( URIRef(id),
|
nothing@1
|
85 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
86 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
87 ))
|
nothing@1
|
88 '''
|
nothing@1
|
89 afgr.add((
|
nothing@1
|
90 URIRef(id),
|
nothing@1
|
91 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
92 OWL.Class
|
nothing@1
|
93 ))
|
nothing@1
|
94
|
nothing@1
|
95 afgr.add((
|
nothing@1
|
96 URIRef(id),
|
nothing@1
|
97 URIRef(local + 'feature'),
|
nothing@1
|
98 Literal(name)
|
nothing@1
|
99 ))
|
nothing@1
|
100
|
nothing@1
|
101 afgr.add((
|
nothing@1
|
102 URIRef(id),
|
nothing@1
|
103 URIRef(local + 'domain'),
|
nothing@1
|
104 Literal(domain)
|
nothing@1
|
105 ))
|
nothing@1
|
106
|
nothing@1
|
107 word = cat[i].split(' ')
|
nothing@1
|
108
|
nothing@1
|
109 temp = {
|
nothing@1
|
110 'I': 'intraframe',
|
nothing@1
|
111 'X': 'interframe',
|
nothing@1
|
112 'G': 'global'
|
nothing@1
|
113 }[word[0]]
|
nothing@1
|
114
|
nothing@1
|
115 afgr.add((
|
nothing@1
|
116 URIRef(id),
|
nothing@1
|
117 URIRef(local + 'temporalscale'),
|
nothing@1
|
118 Literal(temp)
|
nothing@1
|
119 ))
|
nothing@1
|
120
|
nothing@1
|
121
|
nothing@1
|
122 if word[1] == 'Y':
|
nothing@1
|
123 temp = 'perceptual'
|
nothing@1
|
124 else:
|
nothing@1
|
125 temp = 'physical'
|
nothing@1
|
126
|
nothing@1
|
127 afgr.add((
|
nothing@1
|
128 URIRef(id),
|
nothing@1
|
129 URIRef(local + 'level'),
|
nothing@1
|
130 Literal(temp)
|
nothing@1
|
131 ))
|
nothing@1
|
132
|
nothing@1
|
133 if word[2] == 'Y':
|
nothing@1
|
134 afgr.add((
|
nothing@1
|
135 URIRef(id),
|
nothing@1
|
136 URIRef(local + 'model'),
|
nothing@1
|
137 Literal('psychoacoustic')
|
nothing@1
|
138 ))
|
nothing@1
|
139
|
nothing@1
|
140 temp = {
|
nothing@1
|
141 'L': 'low',
|
nothing@1
|
142 'M': 'medium',
|
nothing@1
|
143 'H': 'high'
|
nothing@1
|
144 }[word[3]]
|
nothing@1
|
145
|
nothing@1
|
146 afgr.add((
|
nothing@1
|
147 URIRef(id),
|
nothing@1
|
148 URIRef(local + 'complexity'),
|
nothing@1
|
149 Literal(temp)
|
nothing@1
|
150 ))
|
nothing@1
|
151
|
nothing@1
|
152 if word[4] == 'V':
|
nothing@1
|
153 temp = 'parameterized'
|
nothing@1
|
154 else:
|
nothing@1
|
155 temp = word[4]
|
nothing@1
|
156
|
nothing@1
|
157 afgr.add((
|
nothing@1
|
158 URIRef(id),
|
nothing@1
|
159 URIRef(local + 'dimensions'),
|
nothing@1
|
160 Literal(temp)
|
nothing@1
|
161 ))
|
nothing@1
|
162
|
nothing@1
|
163 temp = {
|
nothing@1
|
164 'ASR': "speech recognition",
|
nothing@1
|
165 'ESR': "environmental sound recognition",
|
nothing@1
|
166 'MIR': "music information retrieval",
|
nothing@1
|
167 'AS': "audio segmentation",
|
nothing@1
|
168 'FP': "fingerprinting",
|
nothing@1
|
169 'VAR': "several",
|
nothing@1
|
170 'EXC': ''
|
nothing@1
|
171 }[word[5]]
|
nothing@1
|
172
|
nothing@1
|
173 if temp != '':
|
nothing@1
|
174 afgr.add((
|
nothing@1
|
175 URIRef(id),
|
nothing@1
|
176 URIRef(local + 'appdomain'),
|
nothing@1
|
177 Literal(temp)
|
nothing@1
|
178 ))
|
nothing@1
|
179
|
nothing@1
|
180 steps = sig[i].split(' ')
|
nothing@1
|
181
|
nothing@1
|
182 for key in steps:
|
nothing@1
|
183 afgr.add((
|
nothing@1
|
184 URIRef(id),
|
nothing@1
|
185 URIRef(local + 'computation'),
|
nothing@1
|
186 Literal(compdict[key])
|
nothing@1
|
187 ))
|
nothing@1
|
188
|
nothing@1
|
189 if name.find('MPEG-7') >= 0:
|
nothing@1
|
190 afgr.add((
|
nothing@1
|
191 URIRef(id),
|
nothing@1
|
192 URIRef(local + 'computedIn'),
|
nothing@1
|
193 Literal('MPEG-7')
|
nothing@1
|
194 ))
|
nothing@1
|
195
|
nothing@1
|
196 if name in abbr.keys():
|
nothing@1
|
197 afgr.add((
|
nothing@1
|
198 URIRef(id),
|
nothing@1
|
199 URIRef(local + 'abbreviation'),
|
nothing@1
|
200 Literal(abbr[name])
|
nothing@1
|
201 ))
|
nothing@1
|
202
|
nothing@1
|
203
|
nothing@1
|
204 i += 1
|
nothing@1
|
205
|
nothing@1
|
206
|
nothing@1
|
207 execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py')
|
nothing@1
|
208
|
nothing@1
|
209 ############# Vamp ###############
|
nothing@1
|
210
|
nothing@1
|
211
|
nothing@1
|
212 vamp = Graph()
|
nothing@1
|
213 vamp.parse('/Users/alo/Development/qm/qm-vamp-plugins/qm-vamp-plugins.n3', format='n3')
|
nothing@1
|
214
|
nothing@1
|
215 vampdict = {}
|
nothing@1
|
216
|
nothing@1
|
217 current = afgr
|
nothing@1
|
218
|
nothing@1
|
219 for s, p, o in vamp.triples((None, None, URIRef('http://purl.org/ontology/vamp/Plugin'))):
|
nothing@1
|
220 for vs, vp, vo in vamp.triples((s, URIRef('http://purl.org/ontology/vamp/name'), None )):
|
nothing@1
|
221 score = 100
|
nothing@1
|
222 vampdict[vo] = {'score': 0, 'name': ""}
|
nothing@1
|
223 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
224 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
225 m = StringMatcher()
|
nothing@1
|
226 m.set_seqs(vo, name)
|
nothing@1
|
227 sc = float(m.distance()) / ((len(vo) + len(name)) / 2.0)
|
nothing@1
|
228 if sc < score:
|
nothing@1
|
229 vampdict[vo]['score'] = 1.0 - sc
|
nothing@1
|
230 vampdict[vo]['name'] = name
|
nothing@1
|
231 score = sc
|
nothing@1
|
232
|
nothing@1
|
233 for k in vampdict.keys():
|
nothing@1
|
234 if vampdict[k]['score'] > 0.75:
|
nothing@1
|
235 name = vampdict[k]['name']
|
nothing@1
|
236 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
237 afgr.add((
|
nothing@1
|
238 URIRef(id),
|
nothing@1
|
239 URIRef(local + 'computedIn'),
|
nothing@1
|
240 Literal('Vamp Plugins')
|
nothing@1
|
241 ))
|
nothing@1
|
242 else:
|
nothing@1
|
243 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
244 afgr.add(( URIRef(id),
|
nothing@1
|
245 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
246 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
247 ))
|
nothing@1
|
248
|
nothing@1
|
249 afgr.add((
|
nothing@1
|
250 URIRef(id),
|
nothing@1
|
251 URIRef(local + 'feature'),
|
nothing@1
|
252 Literal(k)
|
nothing@1
|
253 ))
|
nothing@1
|
254
|
nothing@1
|
255 afgr.add((
|
nothing@1
|
256 URIRef(id),
|
nothing@1
|
257 URIRef(local + 'computedIn'),
|
nothing@1
|
258 Literal('Vamp Plugins')
|
nothing@1
|
259 ))
|
nothing@1
|
260
|
nothing@1
|
261
|
nothing@1
|
262 ############# Marsyas ###############
|
nothing@1
|
263
|
nothing@1
|
264
|
nothing@1
|
265 mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/'
|
nothing@1
|
266
|
nothing@1
|
267 madict = {}
|
nothing@1
|
268
|
nothing@1
|
269 for name in os.listdir(mdir):
|
nothing@1
|
270 if fnmatch.fnmatch(name, '*.h'):
|
nothing@1
|
271 code = [line.strip() for line in open(mdir + name)]
|
nothing@1
|
272 found = False
|
nothing@1
|
273 for line in code:
|
nothing@1
|
274 if line.find('\ingroup Analysis') >= 0:
|
nothing@1
|
275 found = True
|
nothing@1
|
276 break
|
nothing@1
|
277
|
nothing@1
|
278 if found:
|
nothing@1
|
279 i = 0
|
nothing@1
|
280 cl = ''
|
nothing@1
|
281 for line in code:
|
nothing@1
|
282 if line.find('\class') >= 0:
|
nothing@1
|
283 cl = line.split(' ')[-1]
|
nothing@1
|
284 madict[cl] = {'brief': code[i+2][7:]}
|
nothing@1
|
285 if code[i+3] != '':
|
nothing@1
|
286 madict[cl]['brief'] += code[i+3]
|
nothing@1
|
287
|
nothing@1
|
288 break
|
nothing@1
|
289
|
nothing@1
|
290 i += 1
|
nothing@1
|
291
|
nothing@1
|
292
|
nothing@1
|
293 score = 100
|
nothing@1
|
294 madict[cl]['score'] = 0
|
nothing@1
|
295 madict[cl]['name'] = ""
|
nothing@1
|
296 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
297 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
298 m = StringMatcher()
|
nothing@1
|
299 m.set_seqs(Literal(cl), name)
|
nothing@1
|
300 sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0)
|
nothing@1
|
301 if sc < score:
|
nothing@1
|
302 madict[cl]['score'] = 1.0 - sc
|
nothing@1
|
303 madict[cl]['name'] = name
|
nothing@1
|
304 score = sc
|
nothing@1
|
305
|
nothing@1
|
306 if madict[cl]['score'] < 0.75:
|
nothing@1
|
307 for k in abbr.keys():
|
nothing@1
|
308 if abbr[k] == cl:
|
nothing@1
|
309 madict[cl]['score'] = 1.0
|
nothing@1
|
310 madict[cl]['name'] = k
|
nothing@1
|
311
|
nothing@1
|
312
|
nothing@1
|
313 for k in madict.keys():
|
nothing@1
|
314 if madict[k]['score'] > 0.75:
|
nothing@1
|
315 name = madict[k]['name']
|
nothing@1
|
316 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
317 afgr.add((
|
nothing@1
|
318 URIRef(id),
|
nothing@1
|
319 URIRef(local + 'computedIn'),
|
nothing@1
|
320 Literal('Marsyas')
|
nothing@1
|
321 ))
|
nothing@1
|
322 else:
|
nothing@1
|
323 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
324 afgr.add(( URIRef(id),
|
nothing@1
|
325 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
326 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
327 ))
|
nothing@1
|
328
|
nothing@1
|
329 afgr.add((
|
nothing@1
|
330 URIRef(id),
|
nothing@1
|
331 URIRef(local + 'feature'),
|
nothing@1
|
332 Literal(k)
|
nothing@1
|
333 ))
|
nothing@1
|
334
|
nothing@1
|
335 afgr.add((
|
nothing@1
|
336 URIRef(id),
|
nothing@1
|
337 URIRef(local + 'description'),
|
nothing@1
|
338 Literal(madict[k]['brief'])
|
nothing@1
|
339 ))
|
nothing@1
|
340
|
nothing@1
|
341 afgr.add((
|
nothing@1
|
342 URIRef(id),
|
nothing@1
|
343 URIRef(local + 'computedIn'),
|
nothing@1
|
344 Literal('Marsyas')
|
nothing@1
|
345 ))
|
nothing@1
|
346
|
nothing@1
|
347
|
nothing@1
|
348
|
nothing@1
|
349 ############# jMIR ###############
|
nothing@1
|
350
|
nothing@1
|
351 jdir = '/Users/alo/Development/MIR/jAudio/jAudio/'
|
nothing@1
|
352
|
nothing@1
|
353 jdict = {}
|
nothing@1
|
354
|
nothing@1
|
355 file = urllib2.urlopen('file://' + jdir + 'features.xml')
|
nothing@1
|
356 data = file.read()
|
nothing@1
|
357 file.close()
|
nothing@1
|
358
|
nothing@1
|
359 dom = parseString(data)
|
nothing@1
|
360 jmir = dom.getElementsByTagName('feature')
|
nothing@1
|
361
|
nothing@1
|
362 for nodes in jmir:
|
nothing@1
|
363 jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1]
|
nothing@1
|
364 jdict[jname] = {'score': 0, 'name': ""}
|
nothing@1
|
365 # if len(nodes.childNodes) == 5:
|
nothing@1
|
366 # print nodes.childNodes[3]
|
nothing@1
|
367 score = 100
|
nothing@1
|
368
|
nothing@1
|
369 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
370 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
371 m = StringMatcher()
|
nothing@1
|
372 m.set_seqs(Literal(jname), name)
|
nothing@1
|
373 sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0)
|
nothing@1
|
374 if sc < score:
|
nothing@1
|
375 jdict[jname]['score'] = 1.0 - sc
|
nothing@1
|
376 jdict[jname]['name'] = name
|
nothing@1
|
377 score = sc
|
nothing@1
|
378
|
nothing@1
|
379 if jdict[jname]['score'] < 0.75:
|
nothing@1
|
380 for k in abbr.keys():
|
nothing@1
|
381 if abbr[k] == jname:
|
nothing@1
|
382 jdict[jname]['score'] = 1.0
|
nothing@1
|
383 jdict[jname]['name'] = k
|
nothing@1
|
384
|
nothing@1
|
385 for k in jdict.keys():
|
nothing@1
|
386 if jdict[k]['score'] > 0.75:
|
nothing@1
|
387 name = jdict[k]['name']
|
nothing@1
|
388 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
389 afgr.add((
|
nothing@1
|
390 URIRef(id),
|
nothing@1
|
391 URIRef(local + 'computedIn'),
|
nothing@1
|
392 Literal('jMIR')
|
nothing@1
|
393 ))
|
nothing@1
|
394 else:
|
nothing@1
|
395 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
396 afgr.add(( URIRef(id),
|
nothing@1
|
397 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
398 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
399 ))
|
nothing@1
|
400
|
nothing@1
|
401 afgr.add((
|
nothing@1
|
402 URIRef(id),
|
nothing@1
|
403 URIRef(local + 'feature'),
|
nothing@1
|
404 Literal(k)
|
nothing@1
|
405 ))
|
nothing@1
|
406
|
nothing@1
|
407 afgr.add((
|
nothing@1
|
408 URIRef(id),
|
nothing@1
|
409 URIRef(local + 'computedIn'),
|
nothing@1
|
410 Literal('jMIR')
|
nothing@1
|
411 ))
|
nothing@1
|
412
|
nothing@1
|
413
|
nothing@1
|
414
|
nothing@1
|
415 ############# libXtract ###############
|
nothing@1
|
416
|
nothing@1
|
417
|
nothing@1
|
418 path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h'
|
nothing@1
|
419
|
nothing@1
|
420 lines = [line.strip() for line in open(path)]
|
nothing@1
|
421
|
nothing@1
|
422 xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)]
|
nothing@1
|
423
|
nothing@1
|
424 xdict = {}
|
nothing@1
|
425
|
nothing@1
|
426 for ln in xtract:
|
nothing@1
|
427 xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower()
|
nothing@1
|
428 xdict[xname] = {'score': 0, 'name': ""}
|
nothing@1
|
429
|
nothing@1
|
430 score = 100
|
nothing@1
|
431
|
nothing@1
|
432 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
433 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
434 m = StringMatcher()
|
nothing@1
|
435 m.set_seqs(Literal(xname), name)
|
nothing@1
|
436 sc = float(m.distance()) / ((len(xname) + len(name)) / 2.0)
|
nothing@1
|
437 if sc < score:
|
nothing@1
|
438 xdict[xname]['score'] = 1.0 - sc
|
nothing@1
|
439 xdict[xname]['name'] = name
|
nothing@1
|
440 score = sc
|
nothing@1
|
441
|
nothing@1
|
442 if xdict[xname]['score'] < 0.75:
|
nothing@1
|
443 for k in abbr.keys():
|
nothing@1
|
444 if abbr[k] == xname.upper():
|
nothing@1
|
445 xdict[xname]['score'] = 1.0
|
nothing@1
|
446 xdict[xname]['name'] = k
|
nothing@1
|
447
|
nothing@1
|
448 for k in xdict.keys():
|
nothing@1
|
449 if xdict[k]['score'] > 0.75:
|
nothing@1
|
450 name = xdict[k]['name']
|
nothing@1
|
451 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
452 afgr.add((
|
nothing@1
|
453 URIRef(id),
|
nothing@1
|
454 URIRef(local + 'computedIn'),
|
nothing@1
|
455 Literal('libXtract')
|
nothing@1
|
456 ))
|
nothing@1
|
457 else:
|
nothing@1
|
458 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
459 afgr.add(( URIRef(id),
|
nothing@1
|
460 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
461 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
462 ))
|
nothing@1
|
463
|
nothing@1
|
464 afgr.add((
|
nothing@1
|
465 URIRef(id),
|
nothing@1
|
466 URIRef(local + 'feature'),
|
nothing@1
|
467 Literal(k)
|
nothing@1
|
468 ))
|
nothing@1
|
469
|
nothing@1
|
470 afgr.add((
|
nothing@1
|
471 URIRef(id),
|
nothing@1
|
472 URIRef(local + 'computedIn'),
|
nothing@1
|
473 Literal('libXtract')
|
nothing@1
|
474 ))
|
nothing@1
|
475
|
nothing@1
|
476
|
nothing@1
|
477
|
nothing@1
|
478 ############# yaafe ###############
|
nothing@1
|
479
|
nothing@1
|
480 path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py"
|
nothing@1
|
481
|
nothing@1
|
482 lines = [line.strip() for line in open(path)]
|
nothing@1
|
483
|
nothing@1
|
484 ydict = {}
|
nothing@1
|
485
|
nothing@1
|
486 for ln in lines:
|
nothing@1
|
487 if ln.find('class ') >= 0:
|
nothing@1
|
488 yname = ln[6:ln.find('(AudioFeature)')]
|
nothing@1
|
489
|
nothing@1
|
490 ydict[yname] = {'score': 0, 'name': ""}
|
nothing@1
|
491
|
nothing@1
|
492 score = 100
|
nothing@1
|
493
|
nothing@1
|
494 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
495 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
496 m = StringMatcher()
|
nothing@1
|
497 m.set_seqs(Literal(yname), name)
|
nothing@1
|
498 sc = float(m.distance()) / ((len(yname) + len(name)) / 2.0)
|
nothing@1
|
499 if sc < score:
|
nothing@1
|
500 ydict[yname]['score'] = 1.0 - sc
|
nothing@1
|
501 ydict[yname]['name'] = name
|
nothing@1
|
502 score = sc
|
nothing@1
|
503
|
nothing@1
|
504 if ydict[yname]['score'] < 0.75:
|
nothing@1
|
505 for k in abbr.keys():
|
nothing@1
|
506 if abbr[k] == yname:
|
nothing@1
|
507 ydict[yname]['score'] = 1.0
|
nothing@1
|
508 ydict[yname]['name'] = k
|
nothing@1
|
509
|
nothing@1
|
510 for k in ydict.keys():
|
nothing@1
|
511 if ydict[k]['score'] > 0.75:
|
nothing@1
|
512 name = ydict[k]['name']
|
nothing@1
|
513 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
514 afgr.add((
|
nothing@1
|
515 URIRef(id),
|
nothing@1
|
516 URIRef(local + 'computedIn'),
|
nothing@1
|
517 Literal('yaafe')
|
nothing@1
|
518 ))
|
nothing@1
|
519 else:
|
nothing@1
|
520 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
521 afgr.add(( URIRef(id),
|
nothing@1
|
522 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
523 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
524 ))
|
nothing@1
|
525
|
nothing@1
|
526 afgr.add((
|
nothing@1
|
527 URIRef(id),
|
nothing@1
|
528 URIRef(local + 'feature'),
|
nothing@1
|
529 Literal(k)
|
nothing@1
|
530 ))
|
nothing@1
|
531
|
nothing@1
|
532 afgr.add((
|
nothing@1
|
533 URIRef(id),
|
nothing@1
|
534 URIRef(local + 'computedIn'),
|
nothing@1
|
535 Literal('yaafe')
|
nothing@1
|
536 ))
|
nothing@1
|
537
|
nothing@1
|
538 ############# MIRToolbox ###############
|
nothing@1
|
539
|
nothing@1
|
540 path = "/Users/alo/MusicOntology/features/rdf/af-MIRToolbox.rdf"
|
nothing@1
|
541 mirt = Graph()
|
nothing@1
|
542 mirt.parse(path)
|
nothing@1
|
543
|
nothing@1
|
544 mdict = {}
|
nothing@1
|
545
|
nothing@1
|
546 for s, p, o in mirt.triples((None, None, RDFS.Resource)):
|
nothing@1
|
547 mname = s.split('/')[-1]
|
nothing@1
|
548 mdict[mname] = {'score': 0, 'name':"", 'sub': s}
|
nothing@1
|
549
|
nothing@1
|
550 score = 100
|
nothing@1
|
551
|
nothing@1
|
552 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
553 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
554 m = StringMatcher()
|
nothing@1
|
555 m.set_seqs(Literal(mname), name)
|
nothing@1
|
556 sc = float(m.distance()) / ((len(mname) + len(name)) / 2.0)
|
nothing@1
|
557 if sc < score:
|
nothing@1
|
558 mdict[mname]['score'] = 1.0 - sc
|
nothing@1
|
559 mdict[mname]['name'] = name
|
nothing@1
|
560 score = sc
|
nothing@1
|
561
|
nothing@1
|
562 if mdict[mname]['score'] < 0.75:
|
nothing@1
|
563 for k in abbr.keys():
|
nothing@1
|
564 if abbr[k] == mname:
|
nothing@1
|
565 mdict[mname]['score'] = 1.0
|
nothing@1
|
566 mdict[mname]['name'] = k
|
nothing@1
|
567
|
nothing@1
|
568
|
nothing@1
|
569 for k in mdict.keys():
|
nothing@1
|
570 if mdict[k]['score'] > 0.77:
|
nothing@1
|
571 name = mdict[k]['name']
|
nothing@1
|
572 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
573 afgr.add((
|
nothing@1
|
574 URIRef(id),
|
nothing@1
|
575 URIRef(local + 'computedIn'),
|
nothing@1
|
576 Literal('MIRToolbox')
|
nothing@1
|
577 ))
|
nothing@1
|
578 else:
|
nothing@1
|
579 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
580 afgr.add(( URIRef(id),
|
nothing@1
|
581 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
582 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
583 ))
|
nothing@1
|
584
|
nothing@1
|
585 afgr.add((
|
nothing@1
|
586 URIRef(id),
|
nothing@1
|
587 URIRef(local + 'feature'),
|
nothing@1
|
588 Literal(split_uppercase(k))
|
nothing@1
|
589 ))
|
nothing@1
|
590
|
nothing@1
|
591 afgr.add((
|
nothing@1
|
592 URIRef(id),
|
nothing@1
|
593 URIRef(local + 'computedIn'),
|
nothing@1
|
594 Literal('MIRToolbox')
|
nothing@1
|
595 ))
|
nothing@1
|
596
|
nothing@1
|
597 for s, p, o in mirt.triples((mdict[k]['sub'], None, None)):
|
nothing@1
|
598 if o != RDFS.Resource:
|
nothing@1
|
599 afgr.add((URIRef(id), p, o))
|
nothing@1
|
600
|
nothing@1
|
601
|
nothing@1
|
602 ############# CLAM ###############
|
nothing@1
|
603
|
nothing@1
|
604 path = "/Users/alo/MusicOntology/features/rdf/af-CLAM.rdf"
|
nothing@1
|
605 clam = Graph()
|
nothing@1
|
606 clam.parse(path)
|
nothing@1
|
607
|
nothing@1
|
608 cdict = {}
|
nothing@1
|
609
|
nothing@1
|
610 for s, p, o in clam.triples((None, None, RDFS.Resource)):
|
nothing@1
|
611 cname = s.split('/')[-1]
|
nothing@1
|
612 cdict[cname] = {'score': 0, 'name':"", 'sub': s}
|
nothing@1
|
613
|
nothing@1
|
614 score = 100
|
nothing@1
|
615
|
nothing@1
|
616 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
617 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
618 m = StringMatcher()
|
nothing@1
|
619 m.set_seqs(Literal(cname), name)
|
nothing@1
|
620 sc = float(m.distance()) / ((len(cname) + len(name)) / 2.0)
|
nothing@1
|
621 if sc < score:
|
nothing@1
|
622 cdict[cname]['score'] = 1.0 - sc
|
nothing@1
|
623 cdict[cname]['name'] = name
|
nothing@1
|
624 score = sc
|
nothing@1
|
625
|
nothing@1
|
626 if cdict[cname]['score'] < 0.75:
|
nothing@1
|
627 for k in abbr.keys():
|
nothing@1
|
628 if abbr[k] == cname:
|
nothing@1
|
629 cdict[cname]['score'] = 1.0
|
nothing@1
|
630 cdict[cname]['name'] = k
|
nothing@1
|
631
|
nothing@1
|
632 for k in cdict.keys():
|
nothing@1
|
633 if cdict[k]['score'] > 0.77:
|
nothing@1
|
634 name = cdict[k]['name']
|
nothing@1
|
635 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
636 afgr.add((
|
nothing@1
|
637 URIRef(id),
|
nothing@1
|
638 URIRef(local + 'computedIn'),
|
nothing@1
|
639 Literal('CLAM')
|
nothing@1
|
640 ))
|
nothing@1
|
641 else:
|
nothing@1
|
642 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
643 afgr.add(( URIRef(id),
|
nothing@1
|
644 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
645 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
646 ))
|
nothing@1
|
647
|
nothing@1
|
648 afgr.add((
|
nothing@1
|
649 URIRef(id),
|
nothing@1
|
650 URIRef(local + 'feature'),
|
nothing@1
|
651 Literal(split_uppercase(k))
|
nothing@1
|
652 ))
|
nothing@1
|
653
|
nothing@1
|
654 afgr.add((
|
nothing@1
|
655 URIRef(id),
|
nothing@1
|
656 URIRef(local + 'computedIn'),
|
nothing@1
|
657 Literal('CLAM')
|
nothing@1
|
658 ))
|
nothing@1
|
659
|
nothing@1
|
660 for s, p, o in clam.triples((cdict[k]['sub'], None, None)):
|
nothing@1
|
661 if o != RDFS.Resource:
|
nothing@1
|
662 afgr.add((URIRef(id), p, o))
|
nothing@1
|
663
|
nothing@1
|
664
|
nothing@1
|
665 ############# SCMIR ###############
|
nothing@1
|
666
|
nothing@1
|
667 path = "/Users/alo/MusicOntology/features/rdf/af-SuperCollider.rdf"
|
nothing@1
|
668 scg = Graph()
|
nothing@1
|
669 scg.parse(path)
|
nothing@1
|
670
|
nothing@1
|
671 scdict = {}
|
nothing@1
|
672
|
nothing@1
|
673 for s, p, o in scg.triples((None, None, RDFS.Resource)):
|
nothing@1
|
674 scname = s.split('/')[-1]
|
nothing@1
|
675 scdict[scname] = {'score': 0, 'name':"", 'sub': s}
|
nothing@1
|
676
|
nothing@1
|
677 score = 100
|
nothing@1
|
678
|
nothing@1
|
679 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
680 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
681 m = StringMatcher()
|
nothing@1
|
682 m.set_seqs(Literal(scname), name)
|
nothing@1
|
683 sc = float(m.distance()) / ((len(scname) + len(name)) / 2.0)
|
nothing@1
|
684 if sc < score:
|
nothing@1
|
685 scdict[scname]['score'] = 1.0 - sc
|
nothing@1
|
686 scdict[scname]['name'] = name
|
nothing@1
|
687 score = sc
|
nothing@1
|
688
|
nothing@1
|
689 if scdict[scname]['score'] < 0.75:
|
nothing@1
|
690 for k in abbr.keys():
|
nothing@1
|
691 if abbr[k] == scname:
|
nothing@1
|
692 scdict[scname]['score'] = 1.0
|
nothing@1
|
693 scdict[scname]['name'] = k
|
nothing@1
|
694
|
nothing@1
|
695 for k in scdict.keys():
|
nothing@1
|
696 if scdict[k]['score'] > 0.77:
|
nothing@1
|
697 name = scdict[k]['name']
|
nothing@1
|
698 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
699 afgr.add((
|
nothing@1
|
700 URIRef(id),
|
nothing@1
|
701 URIRef(local + 'computedIn'),
|
nothing@1
|
702 Literal('SuperCollider')
|
nothing@1
|
703 ))
|
nothing@1
|
704 else:
|
nothing@1
|
705 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
706 afgr.add(( URIRef(id),
|
nothing@1
|
707 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
708 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
709 ))
|
nothing@1
|
710
|
nothing@1
|
711 afgr.add((
|
nothing@1
|
712 URIRef(id),
|
nothing@1
|
713 URIRef(local + 'feature'),
|
nothing@1
|
714 Literal(split_uppercase(k))
|
nothing@1
|
715 ))
|
nothing@1
|
716
|
nothing@1
|
717 afgr.add((
|
nothing@1
|
718 URIRef(id),
|
nothing@1
|
719 URIRef(local + 'computedIn'),
|
nothing@1
|
720 Literal('SuperCollider')
|
nothing@1
|
721 ))
|
nothing@1
|
722
|
nothing@1
|
723 for s, p, o in scg.triples((scdict[k]['sub'], None, None)):
|
nothing@1
|
724 if o != RDFS.Resource:
|
nothing@1
|
725 afgr.add((URIRef(id), p, o))
|
nothing@1
|
726
|
nothing@1
|
727
|
nothing@1
|
728 ############# aubio ###############
|
nothing@1
|
729 path = "/Users/alo/MusicOntology/features/rdf/af-aubio.rdf"
|
nothing@1
|
730 aug = Graph()
|
nothing@1
|
731 aug.parse(path)
|
nothing@1
|
732
|
nothing@1
|
733 audict = {}
|
nothing@1
|
734
|
nothing@1
|
735 for s, p, o in aug.triples((None, None, RDFS.Resource)):
|
nothing@1
|
736 auname = s.split('/')[-1]
|
nothing@1
|
737 audict[auname] = {'score': 0, 'name':"", 'sub': s}
|
nothing@1
|
738
|
nothing@1
|
739 score = 100
|
nothing@1
|
740
|
nothing@1
|
741 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
742 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
743 m = StringMatcher()
|
nothing@1
|
744 m.set_seqs(Literal(auname), name)
|
nothing@1
|
745 au = float(m.distance()) / ((len(auname) + len(name)) / 2.0)
|
nothing@1
|
746 if au < score:
|
nothing@1
|
747 audict[auname]['score'] = 1.0 - au
|
nothing@1
|
748 audict[auname]['name'] = name
|
nothing@1
|
749 score = au
|
nothing@1
|
750
|
nothing@1
|
751 if audict[auname]['score'] < 0.75:
|
nothing@1
|
752 for k in abbr.keys():
|
nothing@1
|
753 if abbr[k] == auname:
|
nothing@1
|
754 audict[auname]['score'] = 1.0
|
nothing@1
|
755 audict[auname]['name'] = k
|
nothing@1
|
756
|
nothing@1
|
757 for k in audict.keys():
|
nothing@1
|
758 if audict[k]['score'] > 0.77:
|
nothing@1
|
759 name = audict[k]['name']
|
nothing@1
|
760 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
761 afgr.add((
|
nothing@1
|
762 URIRef(id),
|
nothing@1
|
763 URIRef(local + 'computedIn'),
|
nothing@1
|
764 Literal('Aubio')
|
nothing@1
|
765 ))
|
nothing@1
|
766 else:
|
nothing@1
|
767 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
768 afgr.add(( URIRef(id),
|
nothing@1
|
769 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
770 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
771 ))
|
nothing@1
|
772
|
nothing@1
|
773 afgr.add((
|
nothing@1
|
774 URIRef(id),
|
nothing@1
|
775 URIRef(local + 'feature'),
|
nothing@1
|
776 Literal(split_uppercase(k))
|
nothing@1
|
777 ))
|
nothing@1
|
778
|
nothing@1
|
779 afgr.add((
|
nothing@1
|
780 URIRef(id),
|
nothing@1
|
781 URIRef(local + 'computedIn'),
|
nothing@1
|
782 Literal('Aubio')
|
nothing@1
|
783 ))
|
nothing@1
|
784
|
nothing@1
|
785 for s, p, o in aug.triples((audict[k]['sub'], None, None)):
|
nothing@1
|
786 if o != RDFS.Resource:
|
nothing@1
|
787 afgr.add((URIRef(id), p, o))
|
nothing@1
|
788
|
nothing@1
|
789
|
nothing@1
|
790 ############# sMIRk ###############
|
nothing@1
|
791 path = "/Users/alo/MusicOntology/features/rdf/af-smirk.rdf"
|
nothing@1
|
792 smg = Graph()
|
nothing@1
|
793 smg.parse(path)
|
nothing@1
|
794
|
nothing@1
|
795 smdict = {}
|
nothing@1
|
796
|
nothing@1
|
797 for s, p, o in smg.triples((None, None, RDFS.Resource)):
|
nothing@1
|
798 smname = s.split('/')[-1]
|
nothing@1
|
799 smdict[smname] = {'score': 0, 'name':"", 'sub': s}
|
nothing@1
|
800
|
nothing@1
|
801 score = 100
|
nothing@1
|
802
|
nothing@1
|
803 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
804 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
805 m = StringMatcher()
|
nothing@1
|
806 m.set_seqs(Literal(smname), name)
|
nothing@1
|
807 sm = float(m.distance()) / ((len(smname) + len(name)) / 2.0)
|
nothing@1
|
808 if sm < score:
|
nothing@1
|
809 smdict[smname]['score'] = 1.0 - sm
|
nothing@1
|
810 smdict[smname]['name'] = name
|
nothing@1
|
811 score = sm
|
nothing@1
|
812
|
nothing@1
|
813 if smdict[smname]['score'] < 0.75:
|
nothing@1
|
814 for k in abbr.keys():
|
nothing@1
|
815 if abbr[k] == smname:
|
nothing@1
|
816 smdict[smname]['score'] = 1.0
|
nothing@1
|
817 smdict[smname]['name'] = k
|
nothing@1
|
818
|
nothing@1
|
819 for k in smdict.keys():
|
nothing@1
|
820 if smdict[k]['score'] > 0.77:
|
nothing@1
|
821 name = smdict[k]['name']
|
nothing@1
|
822 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
823 afgr.add((
|
nothing@1
|
824 URIRef(id),
|
nothing@1
|
825 URIRef(local + 'computedIn'),
|
nothing@1
|
826 Literal('sMIRk')
|
nothing@1
|
827 ))
|
nothing@1
|
828 else:
|
nothing@1
|
829 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
830 afgr.add(( URIRef(id),
|
nothing@1
|
831 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
832 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
833 ))
|
nothing@1
|
834
|
nothing@1
|
835 afgr.add((
|
nothing@1
|
836 URIRef(id),
|
nothing@1
|
837 URIRef(local + 'feature'),
|
nothing@1
|
838 Literal(split_uppercase(k))
|
nothing@1
|
839 ))
|
nothing@1
|
840
|
nothing@1
|
841 afgr.add((
|
nothing@1
|
842 URIRef(id),
|
nothing@1
|
843 URIRef(local + 'computedIn'),
|
nothing@1
|
844 Literal('sMIRk')
|
nothing@1
|
845 ))
|
nothing@1
|
846
|
nothing@1
|
847 for s, p, o in smg.triples((smdict[k]['sub'], None, None)):
|
nothing@1
|
848 if o != RDFS.Resource:
|
nothing@1
|
849 afgr.add((URIRef(id), p, o))
|
nothing@1
|
850
|
nothing@1
|
851
|
nothing@1
|
852
|
nothing@1
|
853 afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.n3', format='n3')
|
nothing@1
|
854 afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.rdf') |