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