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