annotate pdfextract/parseMarsyas.py @ 18:d5012016bf64 tip

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