nothing@1: import rdflib, os, fnmatch, urllib2 nothing@1: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL nothing@1: from xml.dom.minidom import parseString nothing@1: nothing@1: names = [line.strip() for line in open('pdfextract/names.txt')] nothing@1: cat = [line.strip() for line in open('pdfextract/categories.txt')] nothing@1: sig = [line.strip() for line in open('pdfextract/sig.txt')] nothing@1: nothing@1: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@1: nothing@1: afgr = Graph() nothing@1: afgr.bind('local', URIRef(local)) nothing@1: afgr.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@1: afgr.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) nothing@1: nothing@1: # def split_uppercase(string): nothing@1: # x='' nothing@1: # for i in string: nothing@1: # if i.isupper(): nothing@1: # x+=' %s' %i nothing@1: # else: nothing@1: # x+=i nothing@1: # return x.strip() nothing@1: nothing@1: i = 0 nothing@1: nothing@1: order = [ nothing@1: "Zero Crossing Rate", nothing@1: "Linear Predictive Coding", nothing@1: "Mel-scale Frequency Cepstral Coefficients", nothing@1: "Auditory Filter Bank Temporal Envelopes", nothing@1: "Rate-scale-frequency Features", nothing@1: "Phase Space Features" nothing@1: ] nothing@1: nothing@1: domains = { nothing@1: "Zero Crossing Rate": 'temporal', nothing@1: "Linear Predictive Coding": 'frequency', nothing@1: "Mel-scale Frequency Cepstral Coefficients": 'cepstral', nothing@1: "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', nothing@1: "Rate-scale-frequency Features": 'eigendomain', nothing@1: "Phase Space Features": 'phase space' nothing@1: } nothing@1: nothing@1: abbr = { nothing@1: "Zero Crossing Rate": "ZCR", nothing@1: "Mel-scale Frequency Cepstral Coefficients": "MFCC", nothing@1: "Linear Predictive Coding": "LPC", nothing@1: "Linear Prediction Cepstral Coefficients": "LPCC", nothing@1: "Zero crossing peak amplitudes": "ZCPA", nothing@1: "Line spectral frequencies": "LSF", nothing@1: "Short-time energy": "STE", nothing@1: "Amplitude descriptor": "AD", nothing@1: "Adaptive time frequency transform": "ATFT", nothing@1: "Daubechies Wavelet coefficient histogram": "DWCH", nothing@1: "Spectral Flux": "SF", nothing@1: "Group delay function": "GDF", nothing@1: "Modified group delay function": "MGDF", nothing@1: "Spectral centroid": "SC", nothing@1: "Subband spectral flux": "SSF", nothing@1: "Perceptual linear prediction": "PLP" nothing@1: } nothing@1: nothing@1: nothing@1: domain = "" nothing@1: domainIndex = 0 nothing@1: compdict = {} nothing@1: nothing@1: for filename in ['filters', 'trans', 'aggr']: nothing@1: for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]: nothing@1: compdict[line[0]] = line[2:] nothing@1: nothing@1: nothing@1: nothing@1: for name in names: nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: nothing@1: if name == order[domainIndex]: nothing@1: domain = domains[order[domainIndex]] nothing@1: domainIndex += 1 nothing@1: nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(name.replace(' ','').replace('-','')) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'domain'), nothing@1: Literal(domain) nothing@1: )) nothing@1: nothing@1: word = cat[i].split(' ') nothing@1: nothing@1: temp = { nothing@1: 'I': 'intraframe', nothing@1: 'X': 'interframe', nothing@1: 'G': 'global' nothing@1: }[word[0]] nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'temporalscale'), nothing@1: Literal(temp) nothing@1: )) nothing@1: nothing@1: nothing@1: if word[1] == 'Y': nothing@1: temp = 'perceptual' nothing@1: else: nothing@1: temp = 'physical' nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'level'), nothing@1: Literal(temp) nothing@1: )) nothing@1: nothing@1: if word[2] == 'Y': nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'model'), nothing@1: Literal('psychoacoustic') nothing@1: )) nothing@1: nothing@1: temp = { nothing@1: 'L': 'low', nothing@1: 'M': 'medium', nothing@1: 'H': 'high' nothing@1: }[word[3]] nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'complexity'), nothing@1: Literal(temp) nothing@1: )) nothing@1: nothing@1: if word[4] == 'V': nothing@1: temp = 'parameterized' nothing@1: else: nothing@1: temp = word[4] nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'dimensions'), nothing@1: Literal(temp) nothing@1: )) nothing@1: nothing@1: temp = { nothing@1: 'ASR': "speech recognition", nothing@1: 'ESR': "environmental sound recognition", nothing@1: 'MIR': "music information retrieval", nothing@1: 'AS': "audio segmentation", nothing@1: 'FP': "fingerprinting", nothing@1: 'VAR': "several", nothing@1: 'EXC': '' nothing@1: }[word[5]] nothing@1: nothing@1: if temp != '': nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'appdomain'), nothing@1: Literal(temp) nothing@1: )) nothing@1: nothing@1: steps = sig[i].split(' ') nothing@1: nothing@1: for key in steps: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computation'), nothing@1: Literal(compdict[key]) nothing@1: )) nothing@1: nothing@1: if name.find('MPEG-7') >= 0: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('MPEG-7') nothing@1: )) nothing@1: nothing@1: if name in abbr.keys(): nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'abbreviation'), nothing@1: Literal(abbr[name]) nothing@1: )) nothing@1: nothing@1: nothing@1: i += 1 nothing@1: nothing@1: nothing@1: execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') nothing@1: nothing@1: ############# Vamp ############### nothing@1: nothing@1: nothing@1: vamp = Graph() nothing@1: vamp.parse('/Users/alo/Development/qm/qm-vamp-plugins/qm-vamp-plugins.n3', format='n3') nothing@1: nothing@1: vampdict = {} nothing@1: nothing@1: current = afgr nothing@1: nothing@1: for s, p, o in vamp.triples((None, None, URIRef('http://purl.org/ontology/vamp/Plugin'))): nothing@1: for vs, vp, vo in vamp.triples((s, URIRef('http://purl.org/ontology/vamp/name'), None )): nothing@1: score = 100 nothing@1: vampdict[vo] = {'score': 0, 'name': ""} nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(vo, name) nothing@1: sc = float(m.distance()) / ((len(vo) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: vampdict[vo]['score'] = 1.0 - sc nothing@1: vampdict[vo]['name'] = name nothing@1: score = sc nothing@1: nothing@1: for k in vampdict.keys(): nothing@1: if vampdict[k]['score'] > 0.75: nothing@1: name = vampdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Vamp Plugins') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k.replace(" ", "")) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Vamp Plugins') nothing@1: )) nothing@1: nothing@1: nothing@1: ############# Marsyas ############### nothing@1: nothing@1: nothing@1: mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' nothing@1: nothing@1: madict = {} nothing@1: nothing@1: for name in os.listdir(mdir): nothing@1: if fnmatch.fnmatch(name, '*.h'): nothing@1: code = [line.strip() for line in open(mdir + name)] nothing@1: found = False nothing@1: for line in code: nothing@1: if line.find('\ingroup Analysis') >= 0: nothing@1: found = True nothing@1: break nothing@1: nothing@1: if found: nothing@1: i = 0 nothing@1: cl = '' nothing@1: for line in code: nothing@1: if line.find('\class') >= 0: nothing@1: cl = line.split(' ')[-1] nothing@1: madict[cl] = {'brief': code[i+2][7:]} nothing@1: if code[i+3] != '': nothing@1: madict[cl]['brief'] += code[i+3] nothing@1: nothing@1: break nothing@1: nothing@1: i += 1 nothing@1: nothing@1: nothing@1: score = 100 nothing@1: madict[cl]['score'] = 0 nothing@1: madict[cl]['name'] = "" nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(cl), name) nothing@1: sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: madict[cl]['score'] = 1.0 - sc nothing@1: madict[cl]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if madict[cl]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == cl: nothing@1: madict[cl]['score'] = 1.0 nothing@1: madict[cl]['name'] = k nothing@1: nothing@1: nothing@1: for k in madict.keys(): nothing@1: if madict[k]['score'] > 0.75: nothing@1: name = madict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Marsyas') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'description'), nothing@1: Literal(madict[k]['brief']) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Marsyas') nothing@1: )) nothing@1: nothing@1: nothing@1: nothing@1: ############# jMIR ############### nothing@1: nothing@1: jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' nothing@1: nothing@1: jdict = {} nothing@1: nothing@1: file = urllib2.urlopen('file://' + jdir + 'features.xml') nothing@1: data = file.read() nothing@1: file.close() nothing@1: nothing@1: dom = parseString(data) nothing@1: jmir = dom.getElementsByTagName('feature') nothing@1: nothing@1: for nodes in jmir: nothing@1: jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] nothing@1: jdict[jname] = {'score': 0, 'name': ""} nothing@1: # if len(nodes.childNodes) == 5: nothing@1: # print nodes.childNodes[3] nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(jname), name) nothing@1: sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: jdict[jname]['score'] = 1.0 - sc nothing@1: jdict[jname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if jdict[jname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == jname: nothing@1: jdict[jname]['score'] = 1.0 nothing@1: jdict[jname]['name'] = k nothing@1: nothing@1: for k in jdict.keys(): nothing@1: if jdict[k]['score'] > 0.75: nothing@1: name = jdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('jMIR') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('jMIR') nothing@1: )) nothing@1: nothing@1: nothing@1: nothing@1: ############# libXtract ############### nothing@1: nothing@1: nothing@1: path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' nothing@1: nothing@1: lines = [line.strip() for line in open(path)] nothing@1: nothing@1: xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] nothing@1: nothing@1: xdict = {} nothing@1: nothing@1: for ln in xtract: nothing@1: xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower().capitalize() nothing@1: xdict[xname] = {'score': 0, 'name': ""} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(xname), name) nothing@1: sc = float(m.distance()) / ((len(xname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: xdict[xname]['score'] = 1.0 - sc nothing@1: xdict[xname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if xdict[xname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == xname.upper(): nothing@1: xdict[xname]['score'] = 1.0 nothing@1: xdict[xname]['name'] = k nothing@1: nothing@1: for k in xdict.keys(): nothing@1: if xdict[k]['score'] > 0.75: nothing@1: name = xdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('libXtract') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k.replace(" ", "").replace("-", "")) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('libXtract') nothing@1: )) nothing@1: nothing@1: nothing@1: nothing@1: ############# yaafe ############### nothing@1: nothing@1: path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" nothing@1: nothing@1: lines = [line.strip() for line in open(path)] nothing@1: nothing@1: ydict = {} nothing@1: nothing@1: for ln in lines: nothing@1: if ln.find('class ') >= 0: nothing@1: yname = ln[6:ln.find('(AudioFeature)')] nothing@1: nothing@1: ydict[yname] = {'score': 0, 'name': ""} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(yname), name) nothing@1: sc = float(m.distance()) / ((len(yname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: ydict[yname]['score'] = 1.0 - sc nothing@1: ydict[yname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if ydict[yname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == yname: nothing@1: ydict[yname]['score'] = 1.0 nothing@1: ydict[yname]['name'] = k nothing@1: nothing@1: for k in ydict.keys(): nothing@1: if ydict[k]['score'] > 0.75: nothing@1: name = ydict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('yaafe') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('yaafe') nothing@1: )) nothing@1: nothing@1: ############# MIRToolbox ############### nothing@1: nothing@1: path = "/Users/alo/MusicOntology/features/rdf/af-MIRToolbox.rdf" nothing@1: mirt = Graph() nothing@1: mirt.parse(path) nothing@1: nothing@1: mdict = {} nothing@1: nothing@1: for s, p, o in mirt.triples((None, None, RDFS.Resource)): nothing@1: mname = s.split('/')[-1] nothing@1: mdict[mname] = {'score': 0, 'name':"", 'sub': s} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(mname), name) nothing@1: sc = float(m.distance()) / ((len(mname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: mdict[mname]['score'] = 1.0 - sc nothing@1: mdict[mname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if mdict[mname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == mname: nothing@1: mdict[mname]['score'] = 1.0 nothing@1: mdict[mname]['name'] = k nothing@1: nothing@1: nothing@1: for k in mdict.keys(): nothing@1: if mdict[k]['score'] > 0.77: nothing@1: name = mdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('MIRToolbox') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('MIRToolbox') nothing@1: )) nothing@1: nothing@1: for s, p, o in mirt.triples((mdict[k]['sub'], None, None)): nothing@1: if o != RDFS.Resource: nothing@1: afgr.add((URIRef(id), p, o)) nothing@1: nothing@1: nothing@1: ############# CLAM ############### nothing@1: nothing@1: path = "/Users/alo/MusicOntology/features/rdf/af-CLAM.rdf" nothing@1: clam = Graph() nothing@1: clam.parse(path) nothing@1: nothing@1: cdict = {} nothing@1: nothing@1: for s, p, o in clam.triples((None, None, RDFS.Resource)): nothing@1: cname = s.split('/')[-1] nothing@1: cdict[cname] = {'score': 0, 'name':"", 'sub': s} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(cname), name) nothing@1: sc = float(m.distance()) / ((len(cname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: cdict[cname]['score'] = 1.0 - sc nothing@1: cdict[cname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if cdict[cname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == cname: nothing@1: cdict[cname]['score'] = 1.0 nothing@1: cdict[cname]['name'] = k nothing@1: nothing@1: for k in cdict.keys(): nothing@1: if cdict[k]['score'] > 0.77: nothing@1: name = cdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('CLAM') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('CLAM') nothing@1: )) nothing@1: nothing@1: for s, p, o in clam.triples((cdict[k]['sub'], None, None)): nothing@1: if o != RDFS.Resource: nothing@1: afgr.add((URIRef(id), p, o)) nothing@1: nothing@1: nothing@1: ############# SCMIR ############### nothing@1: nothing@1: path = "/Users/alo/MusicOntology/features/rdf/af-SuperCollider.rdf" nothing@1: scg = Graph() nothing@1: scg.parse(path) nothing@1: nothing@1: scdict = {} nothing@1: nothing@1: for s, p, o in scg.triples((None, None, RDFS.Resource)): nothing@1: scname = s.split('/')[-1] nothing@1: scdict[scname] = {'score': 0, 'name':"", 'sub': s} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(scname), name) nothing@1: sc = float(m.distance()) / ((len(scname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: scdict[scname]['score'] = 1.0 - sc nothing@1: scdict[scname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if scdict[scname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == scname: nothing@1: scdict[scname]['score'] = 1.0 nothing@1: scdict[scname]['name'] = k nothing@1: nothing@1: for k in scdict.keys(): nothing@1: if scdict[k]['score'] > 0.77: nothing@1: name = scdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('SuperCollider') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('SuperCollider') nothing@1: )) nothing@1: nothing@1: for s, p, o in scg.triples((scdict[k]['sub'], None, None)): nothing@1: if o != RDFS.Resource: nothing@1: afgr.add((URIRef(id), p, o)) nothing@1: nothing@1: nothing@1: ############# aubio ############### nothing@1: path = "/Users/alo/MusicOntology/features/rdf/af-aubio.rdf" nothing@1: aug = Graph() nothing@1: aug.parse(path) nothing@1: nothing@1: audict = {} nothing@1: nothing@1: for s, p, o in aug.triples((None, None, RDFS.Resource)): nothing@1: auname = s.split('/')[-1] nothing@1: audict[auname] = {'score': 0, 'name':"", 'sub': s} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(auname), name) nothing@1: au = float(m.distance()) / ((len(auname) + len(name)) / 2.0) nothing@1: if au < score: nothing@1: audict[auname]['score'] = 1.0 - au nothing@1: audict[auname]['name'] = name nothing@1: score = au nothing@1: nothing@1: if audict[auname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == auname: nothing@1: audict[auname]['score'] = 1.0 nothing@1: audict[auname]['name'] = k nothing@1: nothing@1: for k in audict.keys(): nothing@1: if audict[k]['score'] > 0.77: nothing@1: name = audict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Aubio') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('Aubio') nothing@1: )) nothing@1: nothing@1: for s, p, o in aug.triples((audict[k]['sub'], None, None)): nothing@1: if o != RDFS.Resource: nothing@1: afgr.add((URIRef(id), p, o)) nothing@1: nothing@1: nothing@1: ############# sMIRk ############### nothing@1: path = "/Users/alo/MusicOntology/features/rdf/af-smirk.rdf" nothing@1: smg = Graph() nothing@1: smg.parse(path) nothing@1: nothing@1: smdict = {} nothing@1: nothing@1: for s, p, o in smg.triples((None, None, RDFS.Resource)): nothing@1: smname = s.split('/')[-1] nothing@1: smdict[smname] = {'score': 0, 'name':"", 'sub': s} nothing@1: nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(smname), name) nothing@1: sm = float(m.distance()) / ((len(smname) + len(name)) / 2.0) nothing@1: if sm < score: nothing@1: smdict[smname]['score'] = 1.0 - sm nothing@1: smdict[smname]['name'] = name nothing@1: score = sm nothing@1: nothing@1: if smdict[smname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == smname: nothing@1: smdict[smname]['score'] = 1.0 nothing@1: smdict[smname]['name'] = k nothing@1: nothing@1: for k in smdict.keys(): nothing@1: if smdict[k]['score'] > 0.77: nothing@1: name = smdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('sMIRk') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(OWL.Class) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedIn'), nothing@1: Literal('sMIRk') nothing@1: )) nothing@1: nothing@1: for s, p, o in smg.triples((smdict[k]['sub'], None, None)): nothing@1: if o != RDFS.Resource: nothing@1: afgr.add((URIRef(id), p, o)) nothing@1: nothing@1: nothing@1: ############ check similarities ############### nothing@1: for s, p, o in afgr.triples((None, None, OWL.Class)): nothing@1: for ss, pp, oo in afgr.triples((None, None, OWL.Class)): nothing@1: it = s.split('/')[-1] nothing@1: other = ss.split('/')[-1] nothing@1: if s != ss: nothing@1: m = StringMatcher() nothing@1: m.set_seqs(it, other) nothing@1: score = float(m.distance()) / ((len(it) + len(other)) / 2.0) nothing@1: if score < 0.25: nothing@1: print score nothing@1: afgr.add((s, URIRef(local + 'similarTo'), ss)) nothing@1: nothing@1: nothing@1: afgr.serialize('/Users/alo/MusicOntology/features/featuresCatalogue.n3', format='n3') nothing@1: afgr.serialize('/Users/alo/MusicOntology/features/featuresCatalogue.rdf')