nothing@1: import rdflib, os, fnmatch, urllib2 nothing@1: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal nothing@1: from xml.dom.minidom import parseString nothing@1: nothing@1: execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py') nothing@1: nothing@1: jdir = '/Users/alo/Development/MIR/jAudio/jAudio/' nothing@1: nothing@1: jdict = {} nothing@1: nothing@1: file = urllib2.urlopen('file://' + jdir + 'features.xml') nothing@1: data = xml.read() nothing@1: file.close() nothing@1: nothing@1: dom = parseString(data) nothing@1: jmir = dom.getElementsByTagName('feature') nothing@1: nothing@1: for nodes in jmir: nothing@1: jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1] nothing@1: jdict[jname] = {'score': 0, 'name': ""} nothing@1: # if len(nodes.childNodes) == 5: nothing@1: # print nodes.childNodes[3] nothing@1: score = 100 nothing@1: nothing@1: for s, p, o in current.triples((None, None, RDFS.Resource)): nothing@1: for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)): nothing@1: m = StringMatcher() nothing@1: m.set_seqs(Literal(jname), name) nothing@1: sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0) nothing@1: if sc < score: nothing@1: jdict[jname]['score'] = 1.0 - sc nothing@1: jdict[jname]['name'] = name nothing@1: score = sc nothing@1: nothing@1: if jdict[jname]['score'] < 0.75: nothing@1: for k in abbr.keys(): nothing@1: if abbr[k] == jname: nothing@1: madict[cl]['score'] = 1.0 nothing@1: madict[cl]['name'] = k nothing@1: nothing@1: for k in jdict.keys(): nothing@1: if jdict[k]['score'] > 0.75: nothing@1: name = jdict[k]['name'] nothing@1: id = local + (name.replace(' ','').replace('-','')) nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedBy'), nothing@1: Literal('jMIR') nothing@1: )) nothing@1: else: nothing@1: id = local + (k.replace(' ','').replace('-','')) nothing@1: afgr.add(( URIRef(id), nothing@1: URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), nothing@1: URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource') nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'feature'), nothing@1: Literal(k) nothing@1: )) nothing@1: nothing@1: afgr.add(( nothing@1: URIRef(id), nothing@1: URIRef(local + 'computedBy'), nothing@1: Literal('jMIR') nothing@1: ))