nothing@1
|
1 import rdflib
|
nothing@1
|
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL
|
nothing@1
|
3
|
nothing@1
|
4 abbr = {
|
nothing@1
|
5 "Zero Crossing Rate": "ZCR",
|
nothing@1
|
6 "Mel-scale Frequency Cepstral Coefficients": "MFCC",
|
nothing@1
|
7 "Linear Predictive Coding": "LPC",
|
nothing@1
|
8 "Linear Prediction Cepstral Coefficients": "LPCC",
|
nothing@1
|
9 "Zero Crossing Peak Amplitudes": "ZCPA",
|
nothing@1
|
10 "Line Spectral Frequencies": "LSF",
|
nothing@1
|
11 "Short-Time Energy": "STE",
|
nothing@1
|
12 "Amplitude Descriptor": "AD",
|
nothing@1
|
13 "Adaptive Time Frequency Transform": "ATFT",
|
nothing@1
|
14 "Daubechies Wavelet Coefficient Histogram": "DWCH",
|
nothing@1
|
15 "Spectral Flux": "SF",
|
nothing@1
|
16 "Group Delay Function": "GDF",
|
nothing@1
|
17 "Modified Group Delay Function": "MGDF",
|
nothing@1
|
18 "Spectral Centroid": "SC",
|
nothing@1
|
19 "Subband Spectral Flux": "SSF",
|
nothing@1
|
20 "Perceptual Linear Prediction": "PLP",
|
nothing@1
|
21 "Linear Spectral Pairs": "LSP",
|
nothing@1
|
22 "Average Magnitude Difference Function": "AMDF",
|
nothing@1
|
23 "Octave Band Signal Intensity": "OBSI",
|
nothing@1
|
24 "Root Mean Square": "RMS",
|
nothing@18
|
25 "Harmonic Pitch Class Profile": "HPCP",
|
nothing@18
|
26 "SignalToNoiseRatio": "SNR"
|
nothing@1
|
27 }
|
nothing@1
|
28
|
nothing@1
|
29 synonyms = {
|
nothing@1
|
30 "Mel-scale Frequency Cepstral Coefficients": ["Mel Frequency Cepstral Coefficients", "Mel-Frequency Cepstral Coefficients", "Coefficients", "Mfcc"],
|
nothing@1
|
31 "Spectral Kurtosis": ["Kurtosis", "Spectral kurtosis"],
|
nothing@1
|
32 "Spectral Rolloff": ["Rolloff", "Spectral Rolloff Point"],
|
nothing@1
|
33 "Zero Crossing Rate": ["Zero Crossing", "Zcr", "Zero Crossings"],
|
nothing@1
|
34 "Spectral Skewness": ["Skewness", "Spectral skewness"],
|
nothing@1
|
35 "Spectral Flux": ["Flux"],
|
nothing@1
|
36 "Spectral Centroid": ["Centroid", "Spectral centroid"],
|
nothing@1
|
37 "Spectral Slope": ["Spectral slope"],
|
nothing@1
|
38 "Spectral Flatness": ["Spectral Flatness Measure", "Flatness"],
|
nothing@1
|
39 "Harmonic Spectrum": ["Harmonic spectrum"],
|
nothing@1
|
40 "Average Magnitude Difference Function": ["Amdf"],
|
nothing@18
|
41 "Average Squared Difference Function": ["Asdf"],
|
nothing@1
|
42 "AutoCorrelation": ["Autocorrelation"],
|
nothing@1
|
43 "PeakSpectrum": ["Peak spectrum"],
|
nothing@1
|
44 "Spectral Spread": ["Spread"],
|
nothing@1
|
45 "Spectral Crest": ["Spectral Crest Measure"],
|
nothing@18
|
46 "Onset Detection Function": ["Onset", "Onsets", "Onset Detector"],
|
nothing@18
|
47 "Root Mean Square": ["Rms"],
|
nothing@18
|
48 "Note Tracker": ["Aubio Note Tracker"],
|
nothing@18
|
49 "Pitch": ["Aubio Pitch Detector"],
|
nothing@18
|
50 "Silence Test": ["Aubio Silence Detector"],
|
nothing@18
|
51 "AutoCorrelationFFT": ["Autocorrelationfft"],
|
nothing@18
|
52 "Average Deviation": ["Average deviation"],
|
nothing@18
|
53 "Bark Coefficients": ["Bark coefficients"],
|
nothing@18
|
54 "Beat Spectrum": ["Beat Spectra"],
|
nothing@18
|
55 "Beat Tracker": ["Beat Tracking", "BeatTracking" "BeatTrack", "Beat Track", "BeatTrack2", "Beats", "Aubio Beat Tracker"],
|
nothing@18
|
56 "Complex Domain Onset Detection": ["Complex Domain Method Onset Detection Function"],
|
nothing@18
|
57 "Discrete Cosine Transform": ["Dct"],
|
nothing@18
|
58 "Funcdamental Frequency": ["F0", "Failsafef0"],
|
nothing@18
|
59 "HighestValue": ["Highest value"],
|
nothing@18
|
60 "Harmonic Product Spectrum": ["Hps"],
|
nothing@18
|
61 "Key Detector": ["KeyTrack"],
|
nothing@18
|
62 "KrumhanslKeyFinder": ["Krumhansl_key_finder"],
|
nothing@18
|
63 "L-Norm": ["Lnorm"],
|
nothing@18
|
64 "Lowest Value": ["Lowest value"],
|
nothing@18
|
65 "MELODIAMelodyExtraction": ["MELODIAMelodyExtractionintermediatesteps"],
|
nothing@18
|
66 "MIDI Note": ["MIDI"],
|
nothing@18
|
67 "Note Onset Detector": ["Note Onsets", "Note Onset"],
|
nothing@18
|
68 "Octave Band Signal Intensity Ratio": ["OBSIR"],
|
nothing@18
|
69 "OddToEvenHarmonicRatio": ["Oddtoevenharmonicratio"],
|
nothing@18
|
70 "OddEvenRatio": ["Oddevenratio"],
|
nothing@18
|
71 "Pitch Countours": ["PitchContours:All", "PitchContours:Melody"],
|
nothing@18
|
72 "PitchFFTYIN": ["PitchFftYin"],
|
nothing@18
|
73 "PitchYIN": ["PitchYin", "Yin", "AubioYin"],
|
nothing@18
|
74 "Rhythm Patterns": ["RhythmPattern"],
|
nothing@18
|
75 "RMSAmplitude": ["Rmsamplitude"],
|
nothing@18
|
76 "Spectral Shape": ["Spectral Shape Descriptors"],
|
nothing@18
|
77 "Spectral Variance": ["Spectral Variation", "Spectralvariance"],
|
nothing@18
|
78 "Spectral Average Deviation": ["Spectralaveragedeviation"],
|
nothing@18
|
79 "Spectral Inharmonicity": ["Spectralinharmonicity"],
|
nothing@18
|
80 "Spectral Mean": ["Spectralmean"],
|
nothing@18
|
81 "Spectral Standard Deviation": ["Spectralstandarddeviation"],
|
nothing@18
|
82 "Standard Deviation": ["Standarddeviation"],
|
nothing@18
|
83 "Tristimulus1": ["TristimulusI"],
|
nothing@18
|
84 "Tristimulus2": ["TristimulusII"],
|
nothing@18
|
85 "Tristimulus3": ["TristimulusIII"],
|
nothing@18
|
86 "Even Harmonic Ratio": ["evenHarmonicRatio"]
|
nothing@1
|
87 }
|
nothing@1
|
88
|
nothing@1
|
89 execfile('/Users/alo/Development/python-Levenshtein-0.10.2/StringMatcher.py')
|
nothing@1
|
90
|
nothing@1
|
91 def checkSynonyms( name ):
|
nothing@1
|
92 rtn = ""
|
nothing@1
|
93 for key, syns in synonyms.items():
|
nothing@1
|
94 for item in syns:
|
nothing@4
|
95 if name.replace(' ', '').replace('-', '').lower() == item.replace(' ', '').replace('-', '').lower():
|
nothing@1
|
96 rtn = key.replace(' ', '').replace('-', '')
|
nothing@1
|
97 break
|
nothing@1
|
98 return rtn
|
nothing@1
|
99
|
nothing@1
|
100 def checkAbbreviations( name ):
|
nothing@1
|
101 rtn = ""
|
nothing@1
|
102 for key, ab in abbr.items():
|
nothing@1
|
103 if name.replace(' ', '').replace('-', '').lower() == ab.replace(' ', '').replace('-', '').lower():
|
nothing@1
|
104 rtn = key.replace(' ', '').replace('-', '')
|
nothing@1
|
105 break
|
nothing@1
|
106 return rtn
|
nothing@1
|
107
|
nothing@1
|
108
|
nothing@1
|
109 def loadBase( graph, path ):
|
nothing@1
|
110 graph.parse(path)
|
nothing@1
|
111 for su, pr in graph.subject_predicates(OWL.Class):
|
nothing@1
|
112 graph.add((su, RDFS.subClassOf, URIRef(ns+'AudioFeature')))
|
nothing@1
|
113
|
nothing@1
|
114 def addBaseTriples( graph, ns ):
|
nothing@1
|
115 graph.add((
|
nothing@1
|
116 URIRef(ns+'Signal'),
|
nothing@1
|
117 RDF.type,
|
nothing@1
|
118 OWL.Class
|
nothing@1
|
119 ))
|
nothing@1
|
120
|
nothing@1
|
121 graph.add((
|
nothing@1
|
122 URIRef(ns+'Feature'),
|
nothing@1
|
123 RDF.type,
|
nothing@1
|
124 OWL.Class
|
nothing@1
|
125 ))
|
nothing@1
|
126
|
nothing@1
|
127 graph.add((
|
nothing@1
|
128 URIRef(ns+'AudioFeature'),
|
nothing@1
|
129 RDFS.subClassOf,
|
nothing@1
|
130 URIRef(ns+'Signal')
|
nothing@1
|
131 ))
|
nothing@1
|
132
|
nothing@1
|
133
|
nothing@1
|
134 def addTriplesFromFile( graph, path, ns ):
|
nothing@1
|
135 loc = Graph()
|
nothing@1
|
136 loc.parse(path)
|
nothing@1
|
137
|
nothing@1
|
138 for su in loc.subjects(RDF.type, RDFS.Resource):
|
nothing@1
|
139 name = su.split('/')[-1]
|
nothing@1
|
140
|
nothing@1
|
141 ids = ""
|
nothing@1
|
142
|
nothing@1
|
143 ids = checkSynonyms(name)
|
nothing@1
|
144
|
nothing@1
|
145 if ids == "":
|
nothing@1
|
146 ids = checkAbbreviations(name)
|
nothing@1
|
147
|
nothing@1
|
148 if ids == "":
|
nothing@1
|
149 ids = name.replace(' ','').replace('-','')
|
nothing@1
|
150
|
nothing@1
|
151 graph.add((
|
nothing@1
|
152 URIRef(ns + ids),
|
nothing@1
|
153 RDF.type,
|
nothing@1
|
154 OWL.Class
|
nothing@1
|
155 ))
|
nothing@1
|
156 graph.add((
|
nothing@1
|
157 URIRef(ns + ids),
|
nothing@1
|
158 RDFS.subClassOf,
|
nothing@1
|
159 URIRef(ns+'AudioFeature')
|
nothing@1
|
160 ))
|
nothing@1
|
161 for pr, ob in loc.predicate_objects(su):
|
nothing@1
|
162 if ob != RDFS.Resource:
|
nothing@1
|
163 graph.add(( URIRef(ns + ids), pr, ob ))
|
nothing@1
|
164
|
nothing@1
|
165 graph.add(( URIRef(ns + ids), URIRef(ns+'computedIn'), Literal(path.split('/')[-1][3:-4]) ))
|
nothing@1
|
166
|
nothing@1
|
167
|
nothing@1
|
168 def compareForSimilarities( graph, ns, threshold=0.75 ):
|
nothing@1
|
169 for s, p in graph.subject_predicates(OWL.Class):
|
nothing@1
|
170 for ss, pp in graph.subject_predicates(OWL.Class):
|
nothing@1
|
171 it = s.split('/')[-1]
|
nothing@1
|
172 other = ss.split('/')[-1]
|
nothing@1
|
173 if s != ss:
|
nothing@1
|
174 m = StringMatcher()
|
nothing@1
|
175 m.set_seqs(it, other)
|
nothing@1
|
176 score = float(m.distance()) / ((len(it) + len(other)) / 2.0)
|
nothing@1
|
177 if score < (1 - threshold):
|
nothing@1
|
178 graph.add((s, URIRef(ns + 'similarTo'), ss))
|
nothing@1
|
179 #graph.add((s, URIRef(ns + 'similarity'), Literal(1.0-score)))
|
nothing@1
|
180 |