nothing@1
|
1 import rdflib, os, fnmatch, urllib2
|
nothing@1
|
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal
|
nothing@1
|
3 from xml.dom.minidom import parseString
|
nothing@1
|
4
|
nothing@1
|
5 execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py')
|
nothing@1
|
6
|
nothing@1
|
7 jdir = '/Users/alo/Development/MIR/jAudio/jAudio/'
|
nothing@1
|
8
|
nothing@1
|
9 jdict = {}
|
nothing@1
|
10
|
nothing@1
|
11 file = urllib2.urlopen('file://' + jdir + 'features.xml')
|
nothing@1
|
12 data = xml.read()
|
nothing@1
|
13 file.close()
|
nothing@1
|
14
|
nothing@1
|
15 dom = parseString(data)
|
nothing@1
|
16 jmir = dom.getElementsByTagName('feature')
|
nothing@1
|
17
|
nothing@1
|
18 for nodes in jmir:
|
nothing@1
|
19 jname = nodes.childNodes[1].firstChild.nodeValue.split('.')[-1]
|
nothing@1
|
20 jdict[jname] = {'score': 0, 'name': ""}
|
nothing@1
|
21 # if len(nodes.childNodes) == 5:
|
nothing@1
|
22 # print nodes.childNodes[3]
|
nothing@1
|
23 score = 100
|
nothing@1
|
24
|
nothing@1
|
25 for s, p, o in current.triples((None, None, RDFS.Resource)):
|
nothing@1
|
26 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
|
nothing@1
|
27 m = StringMatcher()
|
nothing@1
|
28 m.set_seqs(Literal(jname), name)
|
nothing@1
|
29 sc = float(m.distance()) / ((len(jname) + len(name)) / 2.0)
|
nothing@1
|
30 if sc < score:
|
nothing@1
|
31 jdict[jname]['score'] = 1.0 - sc
|
nothing@1
|
32 jdict[jname]['name'] = name
|
nothing@1
|
33 score = sc
|
nothing@1
|
34
|
nothing@1
|
35 if jdict[jname]['score'] < 0.75:
|
nothing@1
|
36 for k in abbr.keys():
|
nothing@1
|
37 if abbr[k] == jname:
|
nothing@1
|
38 madict[cl]['score'] = 1.0
|
nothing@1
|
39 madict[cl]['name'] = k
|
nothing@1
|
40
|
nothing@1
|
41 for k in jdict.keys():
|
nothing@1
|
42 if jdict[k]['score'] > 0.75:
|
nothing@1
|
43 name = jdict[k]['name']
|
nothing@1
|
44 id = local + (name.replace(' ','').replace('-',''))
|
nothing@1
|
45 afgr.add((
|
nothing@1
|
46 URIRef(id),
|
nothing@1
|
47 URIRef(local + 'computedBy'),
|
nothing@1
|
48 Literal('jMIR')
|
nothing@1
|
49 ))
|
nothing@1
|
50 else:
|
nothing@1
|
51 id = local + (k.replace(' ','').replace('-',''))
|
nothing@1
|
52 afgr.add(( URIRef(id),
|
nothing@1
|
53 URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
nothing@1
|
54 URIRef(u'http://www.w3.org/2000/01/rdf-schema#Resource')
|
nothing@1
|
55 ))
|
nothing@1
|
56
|
nothing@1
|
57 afgr.add((
|
nothing@1
|
58 URIRef(id),
|
nothing@1
|
59 URIRef(local + 'feature'),
|
nothing@1
|
60 Literal(k)
|
nothing@1
|
61 ))
|
nothing@1
|
62
|
nothing@1
|
63 afgr.add((
|
nothing@1
|
64 URIRef(id),
|
nothing@1
|
65 URIRef(local + 'computedBy'),
|
nothing@1
|
66 Literal('jMIR')
|
nothing@1
|
67 ))
|