Mercurial > hg > audio-features-catalogue
changeset 1:365a37a2fb6c
added files from pdfextract directory
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:47:41 +0000 |
parents | 62d2c72e4223 |
children | c314ed54a13b |
files | pdfextract/aggr.txt pdfextract/categories.txt pdfextract/filters.txt pdfextract/graphDefs.py pdfextract/makeAFGraph.py pdfextract/makeAFOwlGraph.py pdfextract/makeOwlGraph.py pdfextract/names.txt pdfextract/parseLibXtract.py pdfextract/parseMarsyas.py pdfextract/parsejAudio.py pdfextract/sig.txt pdfextract/writeBase.py pdfextract/writeCatalogue.py pdfextract/writeRDFs.py |
diffstat | 15 files changed, 3588 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/aggr.txt Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,17 @@ +# Maximum +$ Minimum +^ Mean +% Median +# Sum, Weighted Sum +& Deviation, Sum of Differences +" Root Mean Square +' Power +H Entropy +( Percentile +) Regression +$ Histogram +! Spectral binning +* Peak Detection ++ Harmonic Peak Detection +, Polynomial Root Finding +- Level Crossing Detector \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/categories.txt Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,76 @@ +I N N L 1 VAR +I N N L 1 ASR +I N Y M V ASR +I N Y M V ASR +I N N L 2 EXC +I N N L 9 ESR +I N N L 1 VAR +I N N L 1 VAR +X N N L 1 MIR +G N N L 1 MIR +I N N L V ASR +I N N M V VAR +I N N M 28 MIR +G N N M 42 MIR +I N N L V VAR +I N N L 1 VAR +I N N L 4 VAR +X N N L V MIR +I N N M V ASR +G Y N L 1 MIR +I Y Y M 1 VAR +I Y N L 1 VAR +I Y Y M 1 VAR +I Y N L 1 MIR +I Y N L 1 VAR +I Y Y M 1 VAR +I Y N L 1 MIR +I Y N L 1 VAR +I Y N L V FP +I Y N M V FP +I Y N M 8 ESR +I Y N M V ASR +I Y Y H V MIR +I Y Y H 1 MIR +I Y N L 1 VAR +I Y N L 2 VAR +X Y N M V MIR +I Y Y H V VAR +I Y N M 12 MIR +I Y N M 12 MIR +I Y N H 12 MIR +I Y N M 2 VAR +I Y N L 1 AS +I Y N M 1 ESR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M 1 MIR +I Y N M V MIR +I N Y H V VAR +I N Y H V VAR +I N Y H V ASR +I N Y H 256 ESR +I N Y H V ASR +I N Y H V ASR +I N N M V ASR +I N Y M 62 MIR +X N Y H V VAR +X N N M 1 AS +X N Y M 1 AS +X Y N M 4 AS +I Y N M 1 AS +X Y N H V MIR +X Y N H V MIR +X Y N H 1 MIR +X Y N M 6 MIR +X Y N M V MIR +X N Y H 80 MIR +X N Y H 256 ESR +X N N H V ESR +X N N H 64 FP +I N N H V ASR \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/filters.txt Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,13 @@ +b Band-pass Filter (Bank) +c Comb Filter (Bank) +o Low-pass Filter +f Windowing +w (Non-) Linear Weighting Function +d Derivation, Difference +e Energy Spectral Density +g Group Delay Function +l Logarithm +x Exponential Function +n Normalization +a Autoregression (Linear Prediction Analysis) +r Cepstral Recursion Formula \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/graphDefs.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,139 @@ +import rdflib +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-scale Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Linear Prediction Cepstral Coefficients": "LPCC", + "Zero Crossing Peak Amplitudes": "ZCPA", + "Line Spectral Frequencies": "LSF", + "Short-Time Energy": "STE", + "Amplitude Descriptor": "AD", + "Adaptive Time Frequency Transform": "ATFT", + "Daubechies Wavelet Coefficient Histogram": "DWCH", + "Spectral Flux": "SF", + "Group Delay Function": "GDF", + "Modified Group Delay Function": "MGDF", + "Spectral Centroid": "SC", + "Subband Spectral Flux": "SSF", + "Perceptual Linear Prediction": "PLP", + "Linear Spectral Pairs": "LSP", + "Average Magnitude Difference Function": "AMDF", + "Octave Band Signal Intensity": "OBSI", + "Root Mean Square": "RMS", + "Harmonic Pitch Class Profile": "HPCP" +} + +synonyms = { + "Mel-scale Frequency Cepstral Coefficients": ["Mel Frequency Cepstral Coefficients", "Mel-Frequency Cepstral Coefficients", "Coefficients", "Mfcc"], + "Spectral Kurtosis": ["Kurtosis", "Spectral kurtosis"], + "Spectral Rolloff": ["Rolloff", "Spectral Rolloff Point"], + "Zero Crossing Rate": ["Zero Crossing", "Zcr", "Zero Crossings"], + "Spectral Skewness": ["Skewness", "Spectral skewness"], + "Spectral Flux": ["Flux"], + "Spectral Centroid": ["Centroid", "Spectral centroid"], + "Spectral Slope": ["Spectral slope"], + "Spectral Flatness": ["Spectral Flatness Measure", "Flatness"], + "Harmonic Spectrum": ["Harmonic spectrum"], + "Average Magnitude Difference Function": ["Amdf"], + "AutoCorrelation": ["Autocorrelation"], + "PeakSpectrum": ["Peak spectrum"], + "Spectral Spread": ["Spread"], + "Spectral Crest": ["Spectral Crest Measure"], + "Onset Detection Function": ["Onset", "Onsets"], + "Root Mean Square": ["Rms"] +} + +execfile('/Users/alo/Development/python-Levenshtein-0.10.2/StringMatcher.py') + +def checkSynonyms( name ): + rtn = "" + for key, syns in synonyms.items(): + for item in syns: + if name.replace(' ', '').replace('-', '') == item.replace(' ', '').replace('-', ''): + rtn = key.replace(' ', '').replace('-', '') + break + return rtn + +def checkAbbreviations( name ): + rtn = "" + for key, ab in abbr.items(): + if name.replace(' ', '').replace('-', '').lower() == ab.replace(' ', '').replace('-', '').lower(): + rtn = key.replace(' ', '').replace('-', '') + break + return rtn + + +def loadBase( graph, path ): + graph.parse(path) + for su, pr in graph.subject_predicates(OWL.Class): + graph.add((su, RDFS.subClassOf, URIRef(ns+'AudioFeature'))) + +def addBaseTriples( graph, ns ): + graph.add(( + URIRef(ns+'Signal'), + RDF.type, + OWL.Class + )) + + graph.add(( + URIRef(ns+'Feature'), + RDF.type, + OWL.Class + )) + + graph.add(( + URIRef(ns+'AudioFeature'), + RDFS.subClassOf, + URIRef(ns+'Signal') + )) + + +def addTriplesFromFile( graph, path, ns ): + loc = Graph() + loc.parse(path) + + for su in loc.subjects(RDF.type, RDFS.Resource): + name = su.split('/')[-1] + + ids = "" + + ids = checkSynonyms(name) + + if ids == "": + ids = checkAbbreviations(name) + + if ids == "": + ids = name.replace(' ','').replace('-','') + + graph.add(( + URIRef(ns + ids), + RDF.type, + OWL.Class + )) + graph.add(( + URIRef(ns + ids), + RDFS.subClassOf, + URIRef(ns+'AudioFeature') + )) + for pr, ob in loc.predicate_objects(su): + if ob != RDFS.Resource: + graph.add(( URIRef(ns + ids), pr, ob )) + + graph.add(( URIRef(ns + ids), URIRef(ns+'computedIn'), Literal(path.split('/')[-1][3:-4]) )) + + +def compareForSimilarities( graph, ns, threshold=0.75 ): + for s, p in graph.subject_predicates(OWL.Class): + for ss, pp in graph.subject_predicates(OWL.Class): + it = s.split('/')[-1] + other = ss.split('/')[-1] + if s != ss: + m = StringMatcher() + m.set_seqs(it, other) + score = float(m.distance()) / ((len(it) + len(other)) / 2.0) + if score < (1 - threshold): + graph.add((s, URIRef(ns + 'similarTo'), ss)) + #graph.add((s, URIRef(ns + 'similarity'), Literal(1.0-score))) + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/makeAFGraph.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,845 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal +from xml.dom.minidom import parseString + +names = [line.strip() for line in open('pdfextract/names.txt')] +cat = [line.strip() for line in open('pdfextract/categories.txt')] +sig = [line.strip() for line in open('pdfextract/sig.txt')] + +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' + +afgr = Graph() +afgr.bind('local', URIRef(local)) +afgr.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +def split_uppercase(string): + x='' + for i in string: + if i.isupper(): + x+=' %s' %i + else: + x+=i + return x.strip() + +i = 0 + +order = [ + "Zero Crossing Rate", + "Linear Predictive Coding", + "Mel-scale Frequency Cepstral Coefficients", + "Auditory Filter Bank Temporal Envelopes", + "Rate-scale-frequency Features", + "Phase Space Features" +] + +domains = { + "Zero Crossing Rate": 'temporal', + "Linear Predictive Coding": 'frequency', + "Mel-scale Frequency Cepstral Coefficients": 'cepstral', + "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', + "Rate-scale-frequency Features": 'eigendomain', + "Phase Space Features": 'phase space' +} + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-scale Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Linear Prediction Cepstral Coefficients": "LPCC", + "Zero crossing peak amplitudes": "ZCPA", + "Line spectral frequencies": "LSF", + "Short-time energy": "STE", + "Amplitude descriptor": "AD", + "Adaptive time frequency transform": "ATFT", + "Daubechies Wavelet coefficient histogram": "DWCH", + "Spectral Flux": "SF", + "Group delay function": "GDF", + "Modified group delay function": "MGDF", + "Spectral centroid": "SC", + "Subband spectral flux": "SSF", + "Perceptual linear prediction": "PLP" +} + + +domain = "" +domainIndex = 0 +compdict = {} + +for filename in ['filters', 'trans', 'aggr']: + for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]: + compdict[line[0]] = line[2:] + + + +for name in names: + id = local + (name.replace(' ','').replace('-','')) + + if name == order[domainIndex]: + domain = domains[order[domainIndex]] + domainIndex += 1 + + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(name) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'domain'), + Literal(domain) + )) + + word = cat[i].split(' ') + + temp = { + 'I': 'intraframe', + 'X': 'interframe', + 'G': 'global' + }[word[0]] + + afgr.add(( + URIRef(id), + URIRef(local + 'temporalscale'), + Literal(temp) + )) + + + if word[1] == 'Y': + temp = 'perceptual' + else: + temp = 'physical' + + afgr.add(( + URIRef(id), + URIRef(local + 'level'), + Literal(temp) + )) + + if word[2] == 'Y': + afgr.add(( + URIRef(id), + URIRef(local + 'model'), + Literal('psychoacoustic') + )) + + temp = { + 'L': 'low', + 'M': 'medium', + 'H': 'high' + }[word[3]] + + afgr.add(( + URIRef(id), + URIRef(local + 'complexity'), + Literal(temp) + )) + + if word[4] == 'V': + temp = 'parameterized' + else: + temp = word[4] + + afgr.add(( + URIRef(id), + URIRef(local + 'dimensions'), + Literal(temp) + )) + + temp = { + 'ASR': "speech recognition", + 'ESR': "environmental sound recognition", + 'MIR': "music information retrieval", + 'AS': "audio segmentation", + 'FP': "fingerprinting", + 'VAR': "several", + 'EXC': '' + }[word[5]] + + if temp != '': + afgr.add(( + URIRef(id), + URIRef(local + 'appdomain'), + Literal(temp) + )) + + steps = sig[i].split(' ') + + for key in steps: + afgr.add(( + URIRef(id), + URIRef(local + 'computation'), + Literal(compdict[key]) + )) + + if name.find('MPEG-7') >= 0: + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MPEG-7') + )) + + if name in abbr.keys(): + afgr.add(( + URIRef(id), + URIRef(local + 'abbreviation'), + Literal(abbr[name]) + )) + + + i += 1 + + +execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') + +############# Vamp ############### + + +vamp = Graph() +vamp.parse('/Users/alo/Development/qm/qm-vamp-plugins/qm-vamp-plugins.n3', format='n3') + +vampdict = {} + +current = afgr + +for s, p, o in vamp.triples((None, None, URIRef('http://purl.org/ontology/vamp/Plugin'))): + for vs, vp, vo in vamp.triples((s, URIRef('http://purl.org/ontology/vamp/name'), None )): + score = 100 + vampdict[vo] = {'score': 0, 'name': ""} + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(vo, name) + sc = float(m.distance()) / ((len(vo) + len(name)) / 2.0) + if sc < score: + vampdict[vo]['score'] = 1.0 - sc + vampdict[vo]['name'] = name + score = sc + +for k in vampdict.keys(): + if vampdict[k]['score'] > 0.75: + name = vampdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + + +############# Marsyas ############### + + +mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' + +madict = {} + +for name in os.listdir(mdir): + if fnmatch.fnmatch(name, '*.h'): + code = [line.strip() for line in open(mdir + name)] + found = False + for line in code: + if line.find('\ingroup Analysis') >= 0: + found = True + break + + if found: + i = 0 + cl = '' + for line in code: + if line.find('\class') >= 0: + cl = line.split(' ')[-1] + madict[cl] = {'brief': code[i+2][7:]} + if code[i+3] != '': + madict[cl]['brief'] += code[i+3] + + break + + i += 1 + + + score = 100 + madict[cl]['score'] = 0 + madict[cl]['name'] = "" + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cl), name) + sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0) + if sc < score: + madict[cl]['score'] = 1.0 - sc + madict[cl]['name'] = name + score = sc + + if madict[cl]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cl: + madict[cl]['score'] = 1.0 + madict[cl]['name'] = k + + +for k in madict.keys(): + if madict[k]['score'] > 0.75: + name = madict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'description'), + Literal(madict[k]['brief']) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + + + +############# jMIR ############### + +jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' + +jdict = {} + +file = urllib2.urlopen('file://' + jdir + 'features.xml') +data = file.read() +file.close() + +dom = parseString(data) +jmir = dom.getElementsByTagName('feature') + +for nodes in jmir: + jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] + jdict[jname] = {'score': 0, 'name': ""} +# if len(nodes.childNodes) == 5: +# print nodes.childNodes[3] + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(jname), name) + sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) + if sc < score: + jdict[jname]['score'] = 1.0 - sc + jdict[jname]['name'] = name + score = sc + + if jdict[jname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == jname: + jdict[jname]['score'] = 1.0 + jdict[jname]['name'] = k + +for k in jdict.keys(): + if jdict[k]['score'] > 0.75: + name = jdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + + + +############# libXtract ############### + + +path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' + +lines = [line.strip() for line in open(path)] + +xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] + +xdict = {} + +for ln in xtract: + xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower() + xdict[xname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(xname), name) + sc = float(m.distance()) / ((len(xname) + len(name)) / 2.0) + if sc < score: + xdict[xname]['score'] = 1.0 - sc + xdict[xname]['name'] = name + score = sc + + if xdict[xname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == xname.upper(): + xdict[xname]['score'] = 1.0 + xdict[xname]['name'] = k + +for k in xdict.keys(): + if xdict[k]['score'] > 0.75: + name = xdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + + + +############# yaafe ############### + +path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" + +lines = [line.strip() for line in open(path)] + +ydict = {} + +for ln in lines: + if ln.find('class ') >= 0: + yname = ln[6:ln.find('(AudioFeature)')] + + ydict[yname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(yname), name) + sc = float(m.distance()) / ((len(yname) + len(name)) / 2.0) + if sc < score: + ydict[yname]['score'] = 1.0 - sc + ydict[yname]['name'] = name + score = sc + + if ydict[yname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == yname: + ydict[yname]['score'] = 1.0 + ydict[yname]['name'] = k + +for k in ydict.keys(): + if ydict[k]['score'] > 0.75: + name = ydict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + +############# MIRToolbox ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-MIRToolbox.rdf" +mirt = Graph() +mirt.parse(path) + +mdict = {} + +for s, p, o in mirt.triples((None, None, RDFS.Resource)): + mname = s.split('/')[-1] + mdict[mname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(mname), name) + sc = float(m.distance()) / ((len(mname) + len(name)) / 2.0) + if sc < score: + mdict[mname]['score'] = 1.0 - sc + mdict[mname]['name'] = name + score = sc + + if mdict[mname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == mname: + mdict[mname]['score'] = 1.0 + mdict[mname]['name'] = k + + +for k in mdict.keys(): + if mdict[k]['score'] > 0.77: + name = mdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + + for s, p, o in mirt.triples((mdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# CLAM ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-CLAM.rdf" +clam = Graph() +clam.parse(path) + +cdict = {} + +for s, p, o in clam.triples((None, None, RDFS.Resource)): + cname = s.split('/')[-1] + cdict[cname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cname), name) + sc = float(m.distance()) / ((len(cname) + len(name)) / 2.0) + if sc < score: + cdict[cname]['score'] = 1.0 - sc + cdict[cname]['name'] = name + score = sc + + if cdict[cname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cname: + cdict[cname]['score'] = 1.0 + cdict[cname]['name'] = k + +for k in cdict.keys(): + if cdict[k]['score'] > 0.77: + name = cdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + + for s, p, o in clam.triples((cdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# SCMIR ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-SuperCollider.rdf" +scg = Graph() +scg.parse(path) + +scdict = {} + +for s, p, o in scg.triples((None, None, RDFS.Resource)): + scname = s.split('/')[-1] + scdict[scname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(scname), name) + sc = float(m.distance()) / ((len(scname) + len(name)) / 2.0) + if sc < score: + scdict[scname]['score'] = 1.0 - sc + scdict[scname]['name'] = name + score = sc + + if scdict[scname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == scname: + scdict[scname]['score'] = 1.0 + scdict[scname]['name'] = k + +for k in scdict.keys(): + if scdict[k]['score'] > 0.77: + name = scdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + + for s, p, o in scg.triples((scdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# aubio ############### +path = "/Users/alo/MusicOntology/features/rdf/af-aubio.rdf" +aug = Graph() +aug.parse(path) + +audict = {} + +for s, p, o in aug.triples((None, None, RDFS.Resource)): + auname = s.split('/')[-1] + audict[auname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(auname), name) + au = float(m.distance()) / ((len(auname) + len(name)) / 2.0) + if au < score: + audict[auname]['score'] = 1.0 - au + audict[auname]['name'] = name + score = au + + if audict[auname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == auname: + audict[auname]['score'] = 1.0 + audict[auname]['name'] = k + +for k in audict.keys(): + if audict[k]['score'] > 0.77: + name = audict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + + for s, p, o in aug.triples((audict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# sMIRk ############### +path = "/Users/alo/MusicOntology/features/rdf/af-smirk.rdf" +smg = Graph() +smg.parse(path) + +smdict = {} + +for s, p, o in smg.triples((None, None, RDFS.Resource)): + smname = s.split('/')[-1] + smdict[smname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(smname), name) + sm = float(m.distance()) / ((len(smname) + len(name)) / 2.0) + if sm < score: + smdict[smname]['score'] = 1.0 - sm + smdict[smname]['name'] = name + score = sm + + if smdict[smname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == smname: + smdict[smname]['score'] = 1.0 + smdict[smname]['name'] = k + +for k in smdict.keys(): + if smdict[k]['score'] > 0.77: + name = smdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + + for s, p, o in smg.triples((smdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + + +afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.n3', format='n3') +afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.rdf') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/makeAFOwlGraph.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,854 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL +from xml.dom.minidom import parseString + +names = [line.strip() for line in open('pdfextract/names.txt')] +cat = [line.strip() for line in open('pdfextract/categories.txt')] +sig = [line.strip() for line in open('pdfextract/sig.txt')] + +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' + +afgr = Graph() +afgr.bind('af', URIRef(local)) +afgr.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) +afgr.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) + +def split_uppercase(string): + x='' + for i in string: + if i.isupper(): + x+=' %s' %i + else: + x+=i + return x.strip() + + +i = 0 + +order = [ + "Zero Crossing Rate", + "Linear Predictive Coding", + "Mel-scale Frequency Cepstral Coefficients", + "Auditory Filter Bank Temporal Envelopes", + "Rate-scale-frequency Features", + "Phase Space Features" +] + +domains = { + "Zero Crossing Rate": 'temporal', + "Linear Predictive Coding": 'frequency', + "Mel-scale Frequency Cepstral Coefficients": 'cepstral', + "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', + "Rate-scale-frequency Features": 'eigendomain', + "Phase Space Features": 'phase space' +} + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-scale Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Linear Prediction Cepstral Coefficients": "LPCC", + "Zero crossing peak amplitudes": "ZCPA", + "Line spectral frequencies": "LSF", + "Short-time energy": "STE", + "Amplitude descriptor": "AD", + "Adaptive time frequency transform": "ATFT", + "Daubechies Wavelet coefficient histogram": "DWCH", + "Spectral Flux": "SF", + "Group delay function": "GDF", + "Modified group delay function": "MGDF", + "Spectral centroid": "SC", + "Subband spectral flux": "SSF", + "Perceptual linear prediction": "PLP" +} + + +domain = "" +domainIndex = 0 +compdict = {} + +for filename in ['filters', 'trans', 'aggr']: + for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]: + compdict[line[0]] = line[2:] + + + +for name in names: + id = local + (name.replace(' ','').replace('-','')) + + if name == order[domainIndex]: + domain = domains[order[domainIndex]] + domainIndex += 1 + +''' + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) +''' + afgr.add(( + URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + OWL.Class + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(name) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'domain'), + Literal(domain) + )) + + word = cat[i].split(' ') + + temp = { + 'I': 'intraframe', + 'X': 'interframe', + 'G': 'global' + }[word[0]] + + afgr.add(( + URIRef(id), + URIRef(local + 'temporalscale'), + Literal(temp) + )) + + + if word[1] == 'Y': + temp = 'perceptual' + else: + temp = 'physical' + + afgr.add(( + URIRef(id), + URIRef(local + 'level'), + Literal(temp) + )) + + if word[2] == 'Y': + afgr.add(( + URIRef(id), + URIRef(local + 'model'), + Literal('psychoacoustic') + )) + + temp = { + 'L': 'low', + 'M': 'medium', + 'H': 'high' + }[word[3]] + + afgr.add(( + URIRef(id), + URIRef(local + 'complexity'), + Literal(temp) + )) + + if word[4] == 'V': + temp = 'parameterized' + else: + temp = word[4] + + afgr.add(( + URIRef(id), + URIRef(local + 'dimensions'), + Literal(temp) + )) + + temp = { + 'ASR': "speech recognition", + 'ESR': "environmental sound recognition", + 'MIR': "music information retrieval", + 'AS': "audio segmentation", + 'FP': "fingerprinting", + 'VAR': "several", + 'EXC': '' + }[word[5]] + + if temp != '': + afgr.add(( + URIRef(id), + URIRef(local + 'appdomain'), + Literal(temp) + )) + + steps = sig[i].split(' ') + + for key in steps: + afgr.add(( + URIRef(id), + URIRef(local + 'computation'), + Literal(compdict[key]) + )) + + if name.find('MPEG-7') >= 0: + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MPEG-7') + )) + + if name in abbr.keys(): + afgr.add(( + URIRef(id), + URIRef(local + 'abbreviation'), + Literal(abbr[name]) + )) + + + i += 1 + + +execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') + +############# Vamp ############### + + +vamp = Graph() +vamp.parse('/Users/alo/Development/qm/qm-vamp-plugins/qm-vamp-plugins.n3', format='n3') + +vampdict = {} + +current = afgr + +for s, p, o in vamp.triples((None, None, URIRef('http://purl.org/ontology/vamp/Plugin'))): + for vs, vp, vo in vamp.triples((s, URIRef('http://purl.org/ontology/vamp/name'), None )): + score = 100 + vampdict[vo] = {'score': 0, 'name': ""} + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(vo, name) + sc = float(m.distance()) / ((len(vo) + len(name)) / 2.0) + if sc < score: + vampdict[vo]['score'] = 1.0 - sc + vampdict[vo]['name'] = name + score = sc + +for k in vampdict.keys(): + if vampdict[k]['score'] > 0.75: + name = vampdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + + +############# Marsyas ############### + + +mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' + +madict = {} + +for name in os.listdir(mdir): + if fnmatch.fnmatch(name, '*.h'): + code = [line.strip() for line in open(mdir + name)] + found = False + for line in code: + if line.find('\ingroup Analysis') >= 0: + found = True + break + + if found: + i = 0 + cl = '' + for line in code: + if line.find('\class') >= 0: + cl = line.split(' ')[-1] + madict[cl] = {'brief': code[i+2][7:]} + if code[i+3] != '': + madict[cl]['brief'] += code[i+3] + + break + + i += 1 + + + score = 100 + madict[cl]['score'] = 0 + madict[cl]['name'] = "" + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cl), name) + sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0) + if sc < score: + madict[cl]['score'] = 1.0 - sc + madict[cl]['name'] = name + score = sc + + if madict[cl]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cl: + madict[cl]['score'] = 1.0 + madict[cl]['name'] = k + + +for k in madict.keys(): + if madict[k]['score'] > 0.75: + name = madict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'description'), + Literal(madict[k]['brief']) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + + + +############# jMIR ############### + +jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' + +jdict = {} + +file = urllib2.urlopen('file://' + jdir + 'features.xml') +data = file.read() +file.close() + +dom = parseString(data) +jmir = dom.getElementsByTagName('feature') + +for nodes in jmir: + jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] + jdict[jname] = {'score': 0, 'name': ""} +# if len(nodes.childNodes) == 5: +# print nodes.childNodes[3] + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(jname), name) + sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) + if sc < score: + jdict[jname]['score'] = 1.0 - sc + jdict[jname]['name'] = name + score = sc + + if jdict[jname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == jname: + jdict[jname]['score'] = 1.0 + jdict[jname]['name'] = k + +for k in jdict.keys(): + if jdict[k]['score'] > 0.75: + name = jdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + + + +############# libXtract ############### + + +path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' + +lines = [line.strip() for line in open(path)] + +xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] + +xdict = {} + +for ln in xtract: + xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower() + xdict[xname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(xname), name) + sc = float(m.distance()) / ((len(xname) + len(name)) / 2.0) + if sc < score: + xdict[xname]['score'] = 1.0 - sc + xdict[xname]['name'] = name + score = sc + + if xdict[xname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == xname.upper(): + xdict[xname]['score'] = 1.0 + xdict[xname]['name'] = k + +for k in xdict.keys(): + if xdict[k]['score'] > 0.75: + name = xdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + + + +############# yaafe ############### + +path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" + +lines = [line.strip() for line in open(path)] + +ydict = {} + +for ln in lines: + if ln.find('class ') >= 0: + yname = ln[6:ln.find('(AudioFeature)')] + + ydict[yname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(yname), name) + sc = float(m.distance()) / ((len(yname) + len(name)) / 2.0) + if sc < score: + ydict[yname]['score'] = 1.0 - sc + ydict[yname]['name'] = name + score = sc + + if ydict[yname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == yname: + ydict[yname]['score'] = 1.0 + ydict[yname]['name'] = k + +for k in ydict.keys(): + if ydict[k]['score'] > 0.75: + name = ydict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + +############# MIRToolbox ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-MIRToolbox.rdf" +mirt = Graph() +mirt.parse(path) + +mdict = {} + +for s, p, o in mirt.triples((None, None, RDFS.Resource)): + mname = s.split('/')[-1] + mdict[mname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(mname), name) + sc = float(m.distance()) / ((len(mname) + len(name)) / 2.0) + if sc < score: + mdict[mname]['score'] = 1.0 - sc + mdict[mname]['name'] = name + score = sc + + if mdict[mname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == mname: + mdict[mname]['score'] = 1.0 + mdict[mname]['name'] = k + + +for k in mdict.keys(): + if mdict[k]['score'] > 0.77: + name = mdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + + for s, p, o in mirt.triples((mdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# CLAM ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-CLAM.rdf" +clam = Graph() +clam.parse(path) + +cdict = {} + +for s, p, o in clam.triples((None, None, RDFS.Resource)): + cname = s.split('/')[-1] + cdict[cname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cname), name) + sc = float(m.distance()) / ((len(cname) + len(name)) / 2.0) + if sc < score: + cdict[cname]['score'] = 1.0 - sc + cdict[cname]['name'] = name + score = sc + + if cdict[cname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cname: + cdict[cname]['score'] = 1.0 + cdict[cname]['name'] = k + +for k in cdict.keys(): + if cdict[k]['score'] > 0.77: + name = cdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + + for s, p, o in clam.triples((cdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# SCMIR ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-SuperCollider.rdf" +scg = Graph() +scg.parse(path) + +scdict = {} + +for s, p, o in scg.triples((None, None, RDFS.Resource)): + scname = s.split('/')[-1] + scdict[scname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(scname), name) + sc = float(m.distance()) / ((len(scname) + len(name)) / 2.0) + if sc < score: + scdict[scname]['score'] = 1.0 - sc + scdict[scname]['name'] = name + score = sc + + if scdict[scname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == scname: + scdict[scname]['score'] = 1.0 + scdict[scname]['name'] = k + +for k in scdict.keys(): + if scdict[k]['score'] > 0.77: + name = scdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + + for s, p, o in scg.triples((scdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# aubio ############### +path = "/Users/alo/MusicOntology/features/rdf/af-aubio.rdf" +aug = Graph() +aug.parse(path) + +audict = {} + +for s, p, o in aug.triples((None, None, RDFS.Resource)): + auname = s.split('/')[-1] + audict[auname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(auname), name) + au = float(m.distance()) / ((len(auname) + len(name)) / 2.0) + if au < score: + audict[auname]['score'] = 1.0 - au + audict[auname]['name'] = name + score = au + + if audict[auname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == auname: + audict[auname]['score'] = 1.0 + audict[auname]['name'] = k + +for k in audict.keys(): + if audict[k]['score'] > 0.77: + name = audict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + + for s, p, o in aug.triples((audict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# sMIRk ############### +path = "/Users/alo/MusicOntology/features/rdf/af-smirk.rdf" +smg = Graph() +smg.parse(path) + +smdict = {} + +for s, p, o in smg.triples((None, None, RDFS.Resource)): + smname = s.split('/')[-1] + smdict[smname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(smname), name) + sm = float(m.distance()) / ((len(smname) + len(name)) / 2.0) + if sm < score: + smdict[smname]['score'] = 1.0 - sm + smdict[smname]['name'] = name + score = sm + + if smdict[smname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == smname: + smdict[smname]['score'] = 1.0 + smdict[smname]['name'] = k + +for k in smdict.keys(): + if smdict[k]['score'] > 0.77: + name = smdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(split_uppercase(k)) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + + for s, p, o in smg.triples((smdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + + +afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.n3', format='n3') +afgr.serialize('/Users/alo/MusicOntology/features/docfeatures.rdf') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/makeOwlGraph.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,859 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL +from xml.dom.minidom import parseString + +names = [line.strip() for line in open('pdfextract/names.txt')] +cat = [line.strip() for line in open('pdfextract/categories.txt')] +sig = [line.strip() for line in open('pdfextract/sig.txt')] + +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' + +afgr = Graph() +afgr.bind('local', URIRef(local)) +afgr.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) +afgr.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) + +# def split_uppercase(string): +# x='' +# for i in string: +# if i.isupper(): +# x+=' %s' %i +# else: +# x+=i +# return x.strip() + +i = 0 + +order = [ + "Zero Crossing Rate", + "Linear Predictive Coding", + "Mel-scale Frequency Cepstral Coefficients", + "Auditory Filter Bank Temporal Envelopes", + "Rate-scale-frequency Features", + "Phase Space Features" +] + +domains = { + "Zero Crossing Rate": 'temporal', + "Linear Predictive Coding": 'frequency', + "Mel-scale Frequency Cepstral Coefficients": 'cepstral', + "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', + "Rate-scale-frequency Features": 'eigendomain', + "Phase Space Features": 'phase space' +} + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-scale Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Linear Prediction Cepstral Coefficients": "LPCC", + "Zero crossing peak amplitudes": "ZCPA", + "Line spectral frequencies": "LSF", + "Short-time energy": "STE", + "Amplitude descriptor": "AD", + "Adaptive time frequency transform": "ATFT", + "Daubechies Wavelet coefficient histogram": "DWCH", + "Spectral Flux": "SF", + "Group delay function": "GDF", + "Modified group delay function": "MGDF", + "Spectral centroid": "SC", + "Subband spectral flux": "SSF", + "Perceptual linear prediction": "PLP" +} + + +domain = "" +domainIndex = 0 +compdict = {} + +for filename in ['filters', 'trans', 'aggr']: + for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]: + compdict[line[0]] = line[2:] + + + +for name in names: + id = local + (name.replace(' ','').replace('-','')) + + if name == order[domainIndex]: + domain = domains[order[domainIndex]] + domainIndex += 1 + + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(name.replace(' ','').replace('-','')) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'domain'), + Literal(domain) + )) + + word = cat[i].split(' ') + + temp = { + 'I': 'intraframe', + 'X': 'interframe', + 'G': 'global' + }[word[0]] + + afgr.add(( + URIRef(id), + URIRef(local + 'temporalscale'), + Literal(temp) + )) + + + if word[1] == 'Y': + temp = 'perceptual' + else: + temp = 'physical' + + afgr.add(( + URIRef(id), + URIRef(local + 'level'), + Literal(temp) + )) + + if word[2] == 'Y': + afgr.add(( + URIRef(id), + URIRef(local + 'model'), + Literal('psychoacoustic') + )) + + temp = { + 'L': 'low', + 'M': 'medium', + 'H': 'high' + }[word[3]] + + afgr.add(( + URIRef(id), + URIRef(local + 'complexity'), + Literal(temp) + )) + + if word[4] == 'V': + temp = 'parameterized' + else: + temp = word[4] + + afgr.add(( + URIRef(id), + URIRef(local + 'dimensions'), + Literal(temp) + )) + + temp = { + 'ASR': "speech recognition", + 'ESR': "environmental sound recognition", + 'MIR': "music information retrieval", + 'AS': "audio segmentation", + 'FP': "fingerprinting", + 'VAR': "several", + 'EXC': '' + }[word[5]] + + if temp != '': + afgr.add(( + URIRef(id), + URIRef(local + 'appdomain'), + Literal(temp) + )) + + steps = sig[i].split(' ') + + for key in steps: + afgr.add(( + URIRef(id), + URIRef(local + 'computation'), + Literal(compdict[key]) + )) + + if name.find('MPEG-7') >= 0: + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MPEG-7') + )) + + if name in abbr.keys(): + afgr.add(( + URIRef(id), + URIRef(local + 'abbreviation'), + Literal(abbr[name]) + )) + + + i += 1 + + +execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') + +############# Vamp ############### + + +vamp = Graph() +vamp.parse('/Users/alo/Development/qm/qm-vamp-plugins/qm-vamp-plugins.n3', format='n3') + +vampdict = {} + +current = afgr + +for s, p, o in vamp.triples((None, None, URIRef('http://purl.org/ontology/vamp/Plugin'))): + for vs, vp, vo in vamp.triples((s, URIRef('http://purl.org/ontology/vamp/name'), None )): + score = 100 + vampdict[vo] = {'score': 0, 'name': ""} + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(vo, name) + sc = float(m.distance()) / ((len(vo) + len(name)) / 2.0) + if sc < score: + vampdict[vo]['score'] = 1.0 - sc + vampdict[vo]['name'] = name + score = sc + +for k in vampdict.keys(): + if vampdict[k]['score'] > 0.75: + name = vampdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k.replace(" ", "")) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Vamp Plugins') + )) + + +############# Marsyas ############### + + +mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' + +madict = {} + +for name in os.listdir(mdir): + if fnmatch.fnmatch(name, '*.h'): + code = [line.strip() for line in open(mdir + name)] + found = False + for line in code: + if line.find('\ingroup Analysis') >= 0: + found = True + break + + if found: + i = 0 + cl = '' + for line in code: + if line.find('\class') >= 0: + cl = line.split(' ')[-1] + madict[cl] = {'brief': code[i+2][7:]} + if code[i+3] != '': + madict[cl]['brief'] += code[i+3] + + break + + i += 1 + + + score = 100 + madict[cl]['score'] = 0 + madict[cl]['name'] = "" + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cl), name) + sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0) + if sc < score: + madict[cl]['score'] = 1.0 - sc + madict[cl]['name'] = name + score = sc + + if madict[cl]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cl: + madict[cl]['score'] = 1.0 + madict[cl]['name'] = k + + +for k in madict.keys(): + if madict[k]['score'] > 0.75: + name = madict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'description'), + Literal(madict[k]['brief']) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Marsyas') + )) + + + +############# jMIR ############### + +jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' + +jdict = {} + +file = urllib2.urlopen('file://' + jdir + 'features.xml') +data = file.read() +file.close() + +dom = parseString(data) +jmir = dom.getElementsByTagName('feature') + +for nodes in jmir: + jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] + jdict[jname] = {'score': 0, 'name': ""} +# if len(nodes.childNodes) == 5: +# print nodes.childNodes[3] + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(jname), name) + sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) + if sc < score: + jdict[jname]['score'] = 1.0 - sc + jdict[jname]['name'] = name + score = sc + + if jdict[jname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == jname: + jdict[jname]['score'] = 1.0 + jdict[jname]['name'] = k + +for k in jdict.keys(): + if jdict[k]['score'] > 0.75: + name = jdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('jMIR') + )) + + + +############# libXtract ############### + + +path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' + +lines = [line.strip() for line in open(path)] + +xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] + +xdict = {} + +for ln in xtract: + xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower().capitalize() + xdict[xname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(xname), name) + sc = float(m.distance()) / ((len(xname) + len(name)) / 2.0) + if sc < score: + xdict[xname]['score'] = 1.0 - sc + xdict[xname]['name'] = name + score = sc + + if xdict[xname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == xname.upper(): + xdict[xname]['score'] = 1.0 + xdict[xname]['name'] = k + +for k in xdict.keys(): + if xdict[k]['score'] > 0.75: + name = xdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k.replace(" ", "").replace("-", "")) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('libXtract') + )) + + + +############# yaafe ############### + +path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" + +lines = [line.strip() for line in open(path)] + +ydict = {} + +for ln in lines: + if ln.find('class ') >= 0: + yname = ln[6:ln.find('(AudioFeature)')] + + ydict[yname] = {'score': 0, 'name': ""} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(yname), name) + sc = float(m.distance()) / ((len(yname) + len(name)) / 2.0) + if sc < score: + ydict[yname]['score'] = 1.0 - sc + ydict[yname]['name'] = name + score = sc + + if ydict[yname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == yname: + ydict[yname]['score'] = 1.0 + ydict[yname]['name'] = k + +for k in ydict.keys(): + if ydict[k]['score'] > 0.75: + name = ydict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('yaafe') + )) + +############# MIRToolbox ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-MIRToolbox.rdf" +mirt = Graph() +mirt.parse(path) + +mdict = {} + +for s, p, o in mirt.triples((None, None, RDFS.Resource)): + mname = s.split('/')[-1] + mdict[mname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(mname), name) + sc = float(m.distance()) / ((len(mname) + len(name)) / 2.0) + if sc < score: + mdict[mname]['score'] = 1.0 - sc + mdict[mname]['name'] = name + score = sc + + if mdict[mname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == mname: + mdict[mname]['score'] = 1.0 + mdict[mname]['name'] = k + + +for k in mdict.keys(): + if mdict[k]['score'] > 0.77: + name = mdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MIRToolbox') + )) + + for s, p, o in mirt.triples((mdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# CLAM ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-CLAM.rdf" +clam = Graph() +clam.parse(path) + +cdict = {} + +for s, p, o in clam.triples((None, None, RDFS.Resource)): + cname = s.split('/')[-1] + cdict[cname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cname), name) + sc = float(m.distance()) / ((len(cname) + len(name)) / 2.0) + if sc < score: + cdict[cname]['score'] = 1.0 - sc + cdict[cname]['name'] = name + score = sc + + if cdict[cname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cname: + cdict[cname]['score'] = 1.0 + cdict[cname]['name'] = k + +for k in cdict.keys(): + if cdict[k]['score'] > 0.77: + name = cdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('CLAM') + )) + + for s, p, o in clam.triples((cdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# SCMIR ############### + +path = "/Users/alo/MusicOntology/features/rdf/af-SuperCollider.rdf" +scg = Graph() +scg.parse(path) + +scdict = {} + +for s, p, o in scg.triples((None, None, RDFS.Resource)): + scname = s.split('/')[-1] + scdict[scname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(scname), name) + sc = float(m.distance()) / ((len(scname) + len(name)) / 2.0) + if sc < score: + scdict[scname]['score'] = 1.0 - sc + scdict[scname]['name'] = name + score = sc + + if scdict[scname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == scname: + scdict[scname]['score'] = 1.0 + scdict[scname]['name'] = k + +for k in scdict.keys(): + if scdict[k]['score'] > 0.77: + name = scdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('SuperCollider') + )) + + for s, p, o in scg.triples((scdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# aubio ############### +path = "/Users/alo/MusicOntology/features/rdf/af-aubio.rdf" +aug = Graph() +aug.parse(path) + +audict = {} + +for s, p, o in aug.triples((None, None, RDFS.Resource)): + auname = s.split('/')[-1] + audict[auname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(auname), name) + au = float(m.distance()) / ((len(auname) + len(name)) / 2.0) + if au < score: + audict[auname]['score'] = 1.0 - au + audict[auname]['name'] = name + score = au + + if audict[auname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == auname: + audict[auname]['score'] = 1.0 + audict[auname]['name'] = k + +for k in audict.keys(): + if audict[k]['score'] > 0.77: + name = audict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('Aubio') + )) + + for s, p, o in aug.triples((audict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############# sMIRk ############### +path = "/Users/alo/MusicOntology/features/rdf/af-smirk.rdf" +smg = Graph() +smg.parse(path) + +smdict = {} + +for s, p, o in smg.triples((None, None, RDFS.Resource)): + smname = s.split('/')[-1] + smdict[smname] = {'score': 0, 'name':"", 'sub': s} + + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(smname), name) + sm = float(m.distance()) / ((len(smname) + len(name)) / 2.0) + if sm < score: + smdict[smname]['score'] = 1.0 - sm + smdict[smname]['name'] = name + score = sm + + if smdict[smname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == smname: + smdict[smname]['score'] = 1.0 + smdict[smname]['name'] = k + +for k in smdict.keys(): + if smdict[k]['score'] > 0.77: + name = smdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('sMIRk') + )) + + for s, p, o in smg.triples((smdict[k]['sub'], None, None)): + if o != RDFS.Resource: + afgr.add((URIRef(id), p, o)) + + +############ check similarities ############### +for s, p, o in afgr.triples((None, None, OWL.Class)): + for ss, pp, oo in afgr.triples((None, None, OWL.Class)): + it = s.split('/')[-1] + other = ss.split('/')[-1] + if s != ss: + m = StringMatcher() + m.set_seqs(it, other) + score = float(m.distance()) / ((len(it) + len(other)) / 2.0) + if score < 0.25: + print score + afgr.add((s, URIRef(local + 'similarTo'), ss)) + + +afgr.serialize('/Users/alo/MusicOntology/features/featuresCatalogue.n3', format='n3') +afgr.serialize('/Users/alo/MusicOntology/features/featuresCatalogue.rdf') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/names.txt Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,76 @@ +Zero Crossing Rate +Linear Prediction ZCR +Zero Crossing Peak Amplitudes +Pitch Synchronous ZCPA +MPEG-7 Audio Waveform +Amplitude Descriptor +Short-Time Energy +Volume +MPEG-7 Temporal Centroid +MPEG-7 Log Attack Time +Linear Predictive Coding +Line Spectral Frequencies +Daubechies Wavelet Coefficient Histogram +Adaptive Time-Frequency Transform +Subband Energy Ratio +Spectral Flux +Spectral Slope +Spectral Peaks +Modified Group Delay +MPEG-7 Spectral Centroid +MPEG-7 Audio Spectrum Centroid +Spectral Centroid +Sharpness +Spectral Center +Bandwidth +MPEG-7 Audio Spectrum Spread +Spectral Dispersion +Spectral Rolloff +Spectral Crest +Spectral Flatness +Subband Spectral Flux +Multi-resolution Entropy +Sone +Integral Loudness +Pitch +MPEG-7 Audio Fundamental Frequency +Pitch Histogram +Psychoacoustical Pitch +Chromagram +Chroma CENS Features +Pitch Profile +MPEG-7 Audio Harmonicity +Harmonic Coefficient +Harmonic Prominence +Inharmonicity +MPEG-7 Harmonic Spectral Centroid +MPEG-7 Harmonic Spectral Deviation +MPEG-7 Harmonic Spectral Spread +MPEG-7 Harmonic Spectral Variation +Harmonic Energy Entropy +Harmonic Concentration +Spectral Peak Structure +Harmonic Derivate +Mel-scale Frequency Cepstral Coefficients +Bark-scale Frequency Cepstral Coefficients +Autocorrelation MFCCs +Noise-Robust Auditory Feature +Perceptual Linear Prediction +Relative Spectral PLP +Linear Prediction Cepstral Coefficients +Auditory Filter Bank Temporal Envelopes +Joint Acoustic and Moduluation Frequency +4 Hz Modulation Harmonic Coefficients +4 Hz Modulation Energy +Band Periodicity +Pulse Metric +Beat Spectrum +Cyclic Beat Spectrum +Beat Tracker +Beat Histogram +DWPT-based Rhythm Feature +Rhythm Patterns +Rate-scale-frequency Features +MPEG-7 Audio Spectrum Basis +Distortion Discriminant Analysis +Phase Space Features \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/parseLibXtract.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,6 @@ +path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' + +lines = [line.strip() for line in open(path)] + +xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/parseMarsyas.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,71 @@ +import rdflib, os, fnmatch +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal + +execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') + +mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' +#magraph = Graph() +madict = {} +#current = Graph() +#current.parse('docfeatures.rdf') + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Zero crossing peak amplitudes": "ZCPA", + "Line spectral frequencies": "LSF", + "Short-time energy": "STE", + "Amplitude descriptor": "AD", + "Adaptive time frequency transform": "ATFT", + "Daubechies Wavelet coefficient histogram": "DWCH", + "Spectral Flux": "SF", + "Group delay function": "GDF", + "Modified group delay function": "MGDF", + "Spectral centroid": "SC", + "Subband spectral flux": "SSF", + "Perceptual linear prediction": "PLP" +} + +for name in os.listdir(mdir): + if fnmatch.fnmatch(name, '*.h'): + code = [line.strip() for line in open(mdir + name)] + found = False + for line in code: + if line.find('\ingroup Analysis') >= 0: + found = True + break + + if found: + i = 0 + cl = '' + for line in code: + if line.find('\class') >= 0: + cl = line.split(' ')[-1] + madict[cl] = {'brief': code[i+2][7:]} + if code[i+3] != '': + madict[cl]['brief'] += code[i+3] + + break + + i += 1 + + score = 100 + madict[cl]['score'] = 100 + madict[cl]['name'] = "" + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(cl), name) + sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0) + if sc < score: + madict[cl]['score'] = 1.0 - sc + madict[cl]['name'] = name + score = sc + + if madict[cl]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == cl: + madict[cl]['score'] = 1.0 + madict[cl]['name'] = k + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/parsejAudio.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,67 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal +from xml.dom.minidom import parseString + +execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') + +jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' + +jdict = {} + +file = urllib2.urlopen('file://' + jdir + 'features.xml') +data = xml.read() +file.close() + +dom = parseString(data) +jmir = dom.getElementsByTagName('feature') + +for nodes in jmir: + jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] + jdict[jname] = {'score': 0, 'name': ""} +# if len(nodes.childNodes) == 5: +# print nodes.childNodes[3] + score = 100 + + for s, p, o in current.triples((None, None, RDFS.Resource)): + for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): + m = StringMatcher() + m.set_seqs(Literal(jname), name) + sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) + if sc < score: + jdict[jname]['score'] = 1.0 - sc + jdict[jname]['name'] = name + score = sc + + if jdict[jname]['score'] < 0.75: + for k in abbr.keys(): + if abbr[k] == jname: + madict[cl]['score'] = 1.0 + madict[cl]['name'] = k + +for k in jdict.keys(): + if jdict[k]['score'] > 0.75: + name = jdict[k]['name'] + id = local + (name.replace(' ','').replace('-','')) + afgr.add(( + URIRef(id), + URIRef(local + 'computedBy'), + Literal('jMIR') + )) + else: + id = local + (k.replace(' ','').replace('-','')) + afgr.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(k) + )) + + afgr.add(( + URIRef(id), + URIRef(local + 'computedBy'), + Literal('jMIR') + ))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/sig.txt Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,76 @@ +f ! +f ! a ! +f b ! " l ! " +f b A # ! " l ! " +f # $ +f ^ % ! ^ % +f & +f ' +f ' ^ +f ' " l +f b a F +f a ( +f W ! +V ! +f F ) e n +f F d " +f F * +f F # d +f F o g C +F ^ +f F ) l ^ +f F ) l ^ +f F ) w w ^ +f F e + +f F ) l % +f F ) l % +f F e + % +f F , +f F ) # ^ l +f F ) ^ l +f F l n ) d ^ +f F n ) H +f F ) o l w +f F l " w x " +f A # +f A # +f A " ! " +b b w A " +f F l " +f B " n o +f Q " " # ! # # " +f A # +f A # +f A - +f A - % +f F - ^ +f F - ^ l % +f F - % +f F - R +f F - H +f F - e " +f F - d ! H +f F l d +f F ) l C +f F ) l C +f A o F ) l C +f B w d o l C +f F ) w w C a r +f F ) l b w w x C a r +f b a r +f b b e " +f F ) o W " +f A # C b +f F ) b e n " +f b A # " +f b " A " +f F l o R A +o f F d " c o " " +f b o d c " " +f W o " A " ! +f W A " ! +f F ) o l w F w o + +f B w d o W " P +f F ) l n S I +f M l P P +f E \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/writeBase.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,190 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL +from xml.dom.minidom import parseString + +names = [line.strip() for line in open('pdfextract/names.txt')] +cat = [line.strip() for line in open('pdfextract/categories.txt')] +sig = [line.strip() for line in open('pdfextract/sig.txt')] + +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' + +graph = Graph() +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) +graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) + +i = 0 + +order = [ + "Zero Crossing Rate", + "Linear Predictive Coding", + "Mel-scale Frequency Cepstral Coefficients", + "Auditory Filter Bank Temporal Envelopes", + "Rate-scale-frequency Features", + "Phase Space Features" +] + +domains = { + "Zero Crossing Rate": 'temporal', + "Linear Predictive Coding": 'frequency', + "Mel-scale Frequency Cepstral Coefficients": 'cepstral', + "Auditory Filter Bank Temporal Envelopes": 'modulation frequency', + "Rate-scale-frequency Features": 'eigendomain', + "Phase Space Features": 'phase space' +} + +abbr = { + "Zero Crossing Rate": "ZCR", + "Mel-scale Frequency Cepstral Coefficients": "MFCC", + "Linear Predictive Coding": "LPC", + "Linear Prediction Cepstral Coefficients": "LPCC", + "Zero crossing peak amplitudes": "ZCPA", + "Line spectral frequencies": "LSF", + "Short-time energy": "STE", + "Amplitude descriptor": "AD", + "Adaptive time frequency transform": "ATFT", + "Daubechies Wavelet coefficient histogram": "DWCH", + "Spectral Flux": "SF", + "Group delay function": "GDF", + "Modified group delay function": "MGDF", + "Spectral centroid": "SC", + "Subband spectral flux": "SSF", + "Perceptual linear prediction": "PLP" +} + + +domain = "" +domainIndex = 0 +compdict = {} + +for filename in ['filters', 'trans', 'aggr']: + for line in [line.strip() for line in open('pdfextract/' + filename + '.txt')]: + compdict[line[0]] = line[2:] + + + +for name in names: + id = local + (name.replace(' ','').replace('-','')) + + if name == order[domainIndex]: + domain = domains[order[domainIndex]] + domainIndex += 1 + + graph.add(( URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef(OWL.Class) + )) + + graph.add(( + URIRef(id), + URIRef(local + 'feature'), + Literal(name.replace(' ','').replace('-','')) + )) + + graph.add(( + URIRef(id), + URIRef(local + 'domain'), + Literal(domain) + )) + + word = cat[i].split(' ') + + temp = { + 'I': 'intraframe', + 'X': 'interframe', + 'G': 'global' + }[word[0]] + + graph.add(( + URIRef(id), + URIRef(local + 'temporalscale'), + Literal(temp) + )) + + + if word[1] == 'Y': + temp = 'perceptual' + else: + temp = 'physical' + + graph.add(( + URIRef(id), + URIRef(local + 'level'), + Literal(temp) + )) + + if word[2] == 'Y': + graph.add(( + URIRef(id), + URIRef(local + 'model'), + Literal('psychoacoustic') + )) + + temp = { + 'L': 'low', + 'M': 'medium', + 'H': 'high' + }[word[3]] + + graph.add(( + URIRef(id), + URIRef(local + 'complexity'), + Literal(temp) + )) + + if word[4] == 'V': + temp = 'parameterized' + else: + temp = word[4] + + graph.add(( + URIRef(id), + URIRef(local + 'dimensions'), + Literal(temp) + )) + + temp = { + 'ASR': "speech recognition", + 'ESR': "environmental sound recognition", + 'MIR': "music information retrieval", + 'AS': "audio segmentation", + 'FP': "fingerprinting", + 'VAR': "several", + 'EXC': '' + }[word[5]] + + if temp != '': + graph.add(( + URIRef(id), + URIRef(local + 'appdomain'), + Literal(temp) + )) + + steps = sig[i].split(' ') + + for key in steps: + graph.add(( + URIRef(id), + URIRef(local + 'computation'), + Literal(compdict[key]) + )) + + if name.find('MPEG-7') >= 0: + graph.add(( + URIRef(id), + URIRef(local + 'computedIn'), + Literal('MPEG-7') + )) + + if name in abbr.keys(): + graph.add(( + URIRef(id), + URIRef(local + 'abbreviation'), + Literal(abbr[name]) + )) + + + i += 1 + + +graph.serialize('/Users/alo/MusicOntology/features/rdf/base.rdf') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/writeCatalogue.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,27 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL +from xml.dom.minidom import parseString + +ns = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' + +basedir = '/Users/alo/MusicOntology/features/' + +execfile(basedir + 'pdfextract/graphDefs.py') + +graph = Graph() +graph.bind('af', URIRef(ns)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) +graph.bind('owl', OWL) + +addBaseTriples(graph, ns) + +loadBase( graph, basedir + 'rdf/base.rdf' ) + +for name in os.listdir(basedir+'rdf/'): + if fnmatch.fnmatch(name, 'af-*.rdf'): + addTriplesFromFile(graph, basedir+'rdf/'+name, ns) + +compareForSimilarities(graph, ns) + +graph.serialize(basedir + 'af-catalogue.rdf') +graph.serialize(basedir + 'af-catalogue.n3', format='n3') \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pdfextract/writeRDFs.py Mon Feb 25 14:47:41 2013 +0000 @@ -0,0 +1,272 @@ +import rdflib, os, fnmatch, urllib2 +from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL +from xml.dom.minidom import parseString + +############# Vamp ############### + +vampdir = '/Users/alo/Library/Audio/Plug-Ins/Vamp/' + +source = Graph() + +graph = Graph() +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +for name in os.listdir(vampdir): + if fnmatch.fnmatch(name, '*.n3'): + + print (vampdir + name) + + source.parse(vampdir + name, format='n3') + + for su, pr in source.subject_predicates(URIRef('http://purl.org/ontology/vamp/Plugin')): + + for name in source.objects(su, URIRef('http://purl.org/ontology/vamp/name')): + id = name.replace(' ', '').replace('Marsyas-BatchFeatureExtract-', '') + feature = name + graph.add(( + URIRef(id), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + graph.add(( + URIRef(id), + URIRef(local+'feature'), + Literal(feature) + )) + for domain in source.objects(su, URIRef('http://purl.org/ontology/vamp/input_domain')): + dom = domain.split('/')[-1].replace('Domain', '') + dom = dom.lower().replace('Time', 'temporal') + graph.add(( + URIRef(id), + URIRef(local+'domain'), + Literal(dom) + )) + for desc in source.objects(su, URIRef('http://purl.org/dc/elements/1.1/description')): + description = " ".join(desc.split()) + graph.add(( + URIRef(id), + URIRef('http://purl.org/dc/elements/1.1/description'), + Literal(description) + )) + for maker in source.objects(su, URIRef('http://xmlns.com/foaf/0.1/maker')): + for mname in source.objects(maker, URIRef('http://xmlns.com/foaf/0.1/name')): + makername = mname + graph.add(( + URIRef(id), + URIRef(local+'source'), + Literal(makername) + )) + + count=sum(1 for _ in source.objects(su, URIRef('http://purl.org/ontology/vamp/output'))) + + if count == 1: + for it in source.objects(su, URIRef('http://purl.org/ontology/vamp/output')): + for output in source.objects(it, URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')): + out = output.split('/')[-1].replace('Output', '') + if out.find('Sparse') >= 0 or out.find('Dense') >= 0: + graph.add(( + URIRef(id), + URIRef(local+'output'), + Literal(out) + )) + + else: + for it in source.objects(su, URIRef('http://purl.org/ontology/vamp/output')): + for name in source.objects(it, URIRef('http://purl.org/dc/elements/1.1/title')): + if name != feature: + subid = name.replace(' ', '') + graph.add(( + URIRef(subid), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + graph.add(( + URIRef(subid), + URIRef(local+'feature'), + Literal(name + " (" + feature + ")") + )) + graph.add(( + URIRef(subid), + URIRef(local+'domain'), + Literal(dom) + )) + graph.add(( + URIRef(subid), + URIRef(local+'source'), + Literal(makername) + )) + for output in source.objects(it, URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')): + out = output.split('/')[-1].replace('Output', '') + if out.find('Sparse') >= 0 or out.find('Dense') >= 0: + graph.add(( + URIRef(subid), + URIRef(local+'output'), + Literal(out) + )) + +graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Vamp.rdf') + +############# Marsyas ############### +mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' + +madict = {} + +graph = Graph() +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +for name in os.listdir(mdir): + if fnmatch.fnmatch(name, '*.h'): + code = [line.strip() for line in open(mdir + name)] + found = False + for line in code: + if line.find('\ingroup Analysis') >= 0: + found = True + break + + if found: + i = 0 + cl = '' + for line in code: + if line.find('\class') >= 0: + cl = line.split(' ')[-1] + madict[cl] = {'brief': code[i+2][7:]} + if code[i+3] != '': + madict[cl]['brief'] += code[i+3] + + break + + i += 1 + + graph.add(( + URIRef(cl), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + graph.add(( + URIRef(cl), + URIRef('http://purl.org/dc/elements/1.1/description'), + Literal(madict[cl]['brief']) + )) + +graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Marsyas.rdf') + +############# jMIR ############### +jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' +jsrc = '/Users/alo/Development/MIR/jAudio/jAudio/src/jAudioFeatureExtractor/AudioFeatures/' + +file = urllib2.urlopen('file://' + jdir + 'features.xml') +data = file.read() +file.close() + +dom = parseString(data) +jmir = dom.getElementsByTagName('feature') + +graph = Graph() +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +for nodes in jmir: + jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] + graph.add(( + URIRef(jname), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + file = open(jsrc + jname + '.java') + code = file.read() + searchstr = 'String name =' + start = code.find(searchstr) + len(searchstr) + start = code.find('"', start) + 1 + end = code.find('"', start) + name = code[start:end] + + if name > "": + graph.add(( + URIRef(jname), + URIRef(local+'name'), + Literal(name) + )) + + searchstr = 'String description' + start = code.find(searchstr) + len(searchstr) + start = code.find('"', start) + 1 + end = code.find('";', start) + desc = code[start:end] + desc = desc.replace(" ", "").replace("\t", "").replace('\n', '').replace('+', '').replace('"', '').replace(';', '').replace('//\n', '') + desc = " ".join(desc.split()) + + if desc > "": + graph.add(( + URIRef(jname), + URIRef('http://purl.org/dc/elements/1.1/description'), + Literal(desc) + )) + + +graph.serialize('/Users/alo/MusicOntology/features/rdf/af-jMIR.rdf') + + +############# yaafe ############### + +graph = Graph() +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" + +lines = [line.strip() for line in open(path)] + +count = 0 + +for ln in lines: + if ln.find('class ') >= 0: + yname = ln[6:ln.find('(AudioFeature)')] + desc = lines[count+2] + desc = desc.replace("`", "").replace("<", "").replace(">", "") + desc = " ".join(desc.split()) + + graph.add(( + URIRef(yname), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + + graph.add(( + URIRef(yname), + URIRef('http://purl.org/dc/elements/1.1/description'), + Literal(desc) + )) + + count += 1 + +graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Yaafe.rdf') + +############# libXtract ############### +graph = Graph() +local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' +graph.bind('local', URIRef(local)) +graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) + +path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' + +lines = [line.strip() for line in open(path)] + +xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] + +for ln in xtract: + xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower().capitalize() + + graph.add(( + URIRef(xname), + URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') + )) + +graph.serialize('/Users/alo/MusicOntology/features/rdf/af-libXtract.rdf')