nothing@0: import rdflib, os, fnmatch, urllib2 nothing@0: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL nothing@0: from xml.dom.minidom import parseString nothing@0: nothing@0: ############# Vamp ############### nothing@0: nothing@0: vampdir = '/Users/alo/Library/Audio/Plug-Ins/Vamp/' nothing@0: nothing@0: source = Graph() nothing@0: nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: for name in os.listdir(vampdir): nothing@0: if fnmatch.fnmatch(name, '*.n3'): nothing@0: nothing@0: print (vampdir + name) nothing@0: nothing@0: source.parse(vampdir + name, format='n3') nothing@0: nothing@0: for su, pr in source.subject_predicates(URIRef('http://purl.org/ontology/vamp/Plugin')): nothing@0: nothing@0: for name in source.objects(su, URIRef('http://purl.org/ontology/vamp/name')): nothing@0: id = name.replace(' ', '').replace('Marsyas-BatchFeatureExtract-', '') nothing@0: feature = name nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local+'feature'), nothing@0: Literal(feature) nothing@0: )) nothing@0: for domain in source.objects(su, URIRef('http://purl.org/ontology/vamp/input_domain')): nothing@0: dom = domain.split('/')[-1].replace('Domain', '') nothing@0: dom = dom.lower().replace('Time', 'temporal') nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local+'domain'), nothing@0: Literal(dom) nothing@0: )) nothing@0: for desc in source.objects(su, URIRef('http://purl.org/dc/elements/1.1/description')): nothing@0: description = " ".join(desc.split()) nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: Literal(description) nothing@0: )) nothing@0: for maker in source.objects(su, URIRef('http://xmlns.com/foaf/0.1/maker')): nothing@0: for mname in source.objects(maker, URIRef('http://xmlns.com/foaf/0.1/name')): nothing@0: makername = mname nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local+'source'), nothing@0: Literal(makername) nothing@0: )) nothing@0: nothing@0: count=sum(1 for _ in source.objects(su, URIRef('http://purl.org/ontology/vamp/output'))) nothing@0: nothing@0: if count == 1: nothing@0: for it in source.objects(su, URIRef('http://purl.org/ontology/vamp/output')): nothing@0: for output in source.objects(it, URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')): nothing@0: out = output.split('/')[-1].replace('Output', '') nothing@0: if out.find('Sparse') >= 0 or out.find('Dense') >= 0: nothing@0: graph.add(( nothing@0: URIRef(id), nothing@0: URIRef(local+'output'), nothing@0: Literal(out) nothing@0: )) nothing@0: nothing@0: else: nothing@0: for it in source.objects(su, URIRef('http://purl.org/ontology/vamp/output')): nothing@0: for name in source.objects(it, URIRef('http://purl.org/dc/elements/1.1/title')): nothing@0: if name != feature: nothing@0: subid = name.replace(' ', '') nothing@0: graph.add(( nothing@0: URIRef(subid), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(subid), nothing@0: URIRef(local+'feature'), nothing@0: Literal(name + " (" + feature + ")") nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(subid), nothing@0: URIRef(local+'domain'), nothing@0: Literal(dom) nothing@0: )) nothing@0: graph.add(( nothing@0: URIRef(subid), nothing@0: URIRef(local+'source'), nothing@0: Literal(makername) nothing@0: )) nothing@0: for output in source.objects(it, URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')): nothing@0: out = output.split('/')[-1].replace('Output', '') nothing@0: if out.find('Sparse') >= 0 or out.find('Dense') >= 0: nothing@0: graph.add(( nothing@0: URIRef(subid), nothing@0: URIRef(local+'output'), nothing@0: Literal(out) nothing@0: )) nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Vamp.rdf') nothing@0: nothing@0: ############# Marsyas ############### nothing@0: mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/' nothing@0: nothing@0: madict = {} nothing@0: nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: for name in os.listdir(mdir): nothing@0: if fnmatch.fnmatch(name, '*.h'): nothing@0: code = [line.strip() for line in open(mdir + name)] nothing@0: found = False nothing@0: for line in code: nothing@0: if line.find('\ingroup Analysis') >= 0: nothing@0: found = True nothing@0: break nothing@0: nothing@0: if found: nothing@0: i = 0 nothing@0: cl = '' nothing@0: for line in code: nothing@0: if line.find('\class') >= 0: nothing@0: cl = line.split(' ')[-1] nothing@0: madict[cl] = {'brief': code[i+2][7:]} nothing@0: if code[i+3] != '': nothing@0: madict[cl]['brief'] += code[i+3] nothing@0: nothing@0: break nothing@0: nothing@0: i += 1 nothing@0: nothing@0: graph.add(( nothing@0: URIRef(cl), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(cl), nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: Literal(madict[cl]['brief']) nothing@0: )) nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Marsyas.rdf') nothing@0: nothing@0: ############# jMIR ############### nothing@0: jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' nothing@0: jsrc = '/Users/alo/Development/MIR/jAudio/jAudio/src/jAudioFeatureExtractor/AudioFeatures/' nothing@0: nothing@0: file = urllib2.urlopen('file://' + jdir + 'features.xml') nothing@0: data = file.read() nothing@0: file.close() nothing@0: nothing@0: dom = parseString(data) nothing@0: jmir = dom.getElementsByTagName('feature') nothing@0: nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: for nodes in jmir: nothing@0: jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] nothing@0: graph.add(( nothing@0: URIRef(jname), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: file = open(jsrc + jname + '.java') nothing@0: code = file.read() nothing@0: searchstr = 'String name =' nothing@0: start = code.find(searchstr) + len(searchstr) nothing@0: start = code.find('"', start) + 1 nothing@0: end = code.find('"', start) nothing@0: name = code[start:end] nothing@0: nothing@0: if name > "": nothing@0: graph.add(( nothing@0: URIRef(jname), nothing@0: URIRef(local+'name'), nothing@0: Literal(name) nothing@0: )) nothing@0: nothing@0: searchstr = 'String description' nothing@0: start = code.find(searchstr) + len(searchstr) nothing@0: start = code.find('"', start) + 1 nothing@0: end = code.find('";', start) nothing@0: desc = code[start:end] nothing@0: desc = desc.replace(" ", "").replace("\t", "").replace('\n', '').replace('+', '').replace('"', '').replace(';', '').replace('//\n', '') nothing@0: desc = " ".join(desc.split()) nothing@0: nothing@0: if desc > "": nothing@0: graph.add(( nothing@0: URIRef(jname), nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: Literal(desc) nothing@0: )) nothing@0: nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-jMIR.rdf') nothing@0: nothing@0: nothing@0: ############# yaafe ############### nothing@0: nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: path = "/Users/alo/Development/MIR/yaafe-v0.64/src_python/yaafefeatures.py" nothing@0: nothing@0: lines = [line.strip() for line in open(path)] nothing@0: nothing@0: count = 0 nothing@0: nothing@0: for ln in lines: nothing@0: if ln.find('class ') >= 0: nothing@0: yname = ln[6:ln.find('(AudioFeature)')] nothing@0: desc = lines[count+2] nothing@0: desc = desc.replace("`", "").replace("<", "").replace(">", "") nothing@0: desc = " ".join(desc.split()) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(yname), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: nothing@0: graph.add(( nothing@0: URIRef(yname), nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: Literal(desc) nothing@0: )) nothing@0: nothing@0: count += 1 nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-Yaafe.rdf') nothing@0: nothing@0: ############# libXtract ############### nothing@0: graph = Graph() nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: graph.bind('local', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: nothing@0: path = '/Users/alo/Development/MIR/LibXtract/xtract/libxtract.h' nothing@0: nothing@0: lines = [line.strip() for line in open(path)] nothing@0: nothing@0: xtract = lines[(lines.index('enum xtract_features_ {')+1):(lines.index('XTRACT_WINDOWED')-1)] nothing@0: nothing@0: for ln in xtract: nothing@0: xname = ln[(ln.index('_')+1):-1].replace("_", " ").lower().capitalize() nothing@0: nothing@0: graph.add(( nothing@0: URIRef(xname), nothing@0: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@0: URIRef('http://www.w3.org/2000/01/rdf-schema#Resource') nothing@0: )) nothing@0: nothing@0: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-libXtract.rdf')