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