annotate pdfextract/makeAFGraph.py @ 18:d5012016bf64 tip

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