comparison pdfextract/parseMarsyas.py @ 1:365a37a2fb6c

added files from pdfextract directory
author nothing@tehis.net
date Mon, 25 Feb 2013 14:47:41 +0000
parents
children
comparison
equal deleted inserted replaced
0:62d2c72e4223 1:365a37a2fb6c
1 import rdflib, os, fnmatch
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal
3
4 execfile('/Users/alo/Downloads/python-Levenshtein-0.10.2/StringMatcher.py')
5
6 mdir = '/Users/alo/Development/MIR/marsyas-0.4.7/src/marsyas/'
7 #magraph = Graph()
8 madict = {}
9 #current = Graph()
10 #current.parse('docfeatures.rdf')
11
12 abbr = {
13 "Zero Crossing Rate": "ZCR",
14 "Mel-Frequency Cepstral Coefficients": "MFCC",
15 "Linear Predictive Coding": "LPC",
16 "Zero crossing peak amplitudes": "ZCPA",
17 "Line spectral frequencies": "LSF",
18 "Short-time energy": "STE",
19 "Amplitude descriptor": "AD",
20 "Adaptive time frequency transform": "ATFT",
21 "Daubechies Wavelet coefficient histogram": "DWCH",
22 "Spectral Flux": "SF",
23 "Group delay function": "GDF",
24 "Modified group delay function": "MGDF",
25 "Spectral centroid": "SC",
26 "Subband spectral flux": "SSF",
27 "Perceptual linear prediction": "PLP"
28 }
29
30 for name in os.listdir(mdir):
31 if fnmatch.fnmatch(name, '*.h'):
32 code = [line.strip() for line in open(mdir + name)]
33 found = False
34 for line in code:
35 if line.find('\ingroup Analysis') >= 0:
36 found = True
37 break
38
39 if found:
40 i = 0
41 cl = ''
42 for line in code:
43 if line.find('\class') >= 0:
44 cl = line.split(' ')[-1]
45 madict[cl] = {'brief': code[i+2][7:]}
46 if code[i+3] != '':
47 madict[cl]['brief'] += code[i+3]
48
49 break
50
51 i += 1
52
53 score = 100
54 madict[cl]['score'] = 100
55 madict[cl]['name'] = ""
56 for s, p, o in current.triples((None, None, RDFS.Resource)):
57 for cs, cp, name in current.triples((s, URIRef('http://sovarr.c4dm.eecs.qmul.ac.uk/features/feature'), None)):
58 m = StringMatcher()
59 m.set_seqs(Literal(cl), name)
60 sc = float(m.distance()) / ((len(cl) + len(name)) / 2.0)
61 if sc < score:
62 madict[cl]['score'] = 1.0 - sc
63 madict[cl]['name'] = name
64 score = sc
65
66 if madict[cl]['score'] < 0.75:
67 for k in abbr.keys():
68 if abbr[k] == cl:
69 madict[cl]['score'] = 1.0
70 madict[cl]['name'] = k
71