comparison rdfpy/writeTimbreToolbox.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents
children
comparison
equal deleted inserted replaced
17:2b5c292ad12f 18:d5012016bf64
1 import rdflib, os, fnmatch, urllib2
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace
3
4 graph = Graph()
5
6 af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/features/')
7 graph.bind('local', af)
8
9 dc = Namespace('http://purl.org/dc/elements/1.1/')
10 graph.bind('dc', dc)
11
12 input = {
13 'au': "Audio Signal",
14 'tee': "Temporal Energy Envelope",
15 'stft': "Short-term Fourier Transform",
16 'erb': "Auditory model",
17 'harm': "Harmonic"
18 }
19
20 features = {
21 'Global Descriptors': [
22 {"Attack": "tee"},
23 {"Decay": "tee"},
24 {"Release": "tee"},
25 {"Log-Attack Time": "tee"},
26 {"Attack Slope": "tee"},
27 {"DecreaseSlope": "tee"},
28 {"Temporal Centroid": "tee"},
29 {"Effective Duration": "tee"},
30 {"Frequency of Energy Modulation": "tee"},
31 {"Amplitude of Energy Modulation": "tee"}
32 ],
33
34 'Time-Varying Descriptors': [
35 {"Autocorrelation": 'au'},
36 {"Zero Crossing Rate": 'au'},
37 {"RMS-Energy Envelope": 'tee'},
38 {"Spectral Centroid": 'stft,erb,harm'},
39 {"Spectral Spread": 'stft,erb,harm'},
40 {"Spectral Skewness": 'stft,erb,harm'},
41 {"Spectral Kurtosis": 'stft,erb,harm'},
42 {"Spectral Slope": 'stft,erb,harm'},
43 {"Spectral Decrease": 'stft,erb,harm'},
44 {"Spectral Rolloff": 'stft,erb,harm'},
45 {"Spectro-temporal Variation": 'stft,erb,harm'},
46 {"Spectral Flatness": 'stft,erb'},
47 {"Spectral Crest": 'stft,erb'},
48 {"Harmonic Energy": 'harm'},
49 {"Noise Energy": 'harm'},
50 {"Noisiness": 'harm'},
51 {"Fundamental Frequency": 'harm'},
52 {"Inharmonicity": 'harm'},
53 {"Tristimulus": 'harm'},
54 {"Harmonic Spectral Deviation": 'harm'},
55 {"Odd to even harmonic ratio": 'harm'}
56 ]
57 }
58
59 for temporal in features.keys():
60 for feature in features[temporal]:
61 name = feature.keys()[0]
62 id = af + name.replace(" ", "")
63 graph.add((
64 URIRef(id),
65 RDF.type,
66 RDFS.Resource
67 ))
68 graph.add((
69 URIRef(id),
70 af['feature'],
71 Literal(name)
72 ))
73 graph.add((
74 URIRef(id),
75 af['feature'],
76 Literal(name)
77 ))
78 for inp in feature[name].split(","):
79 graph.add((
80 URIRef(id),
81 af['signal'],
82 Literal(input[inp])
83 ))
84
85
86 graph.serialize('/Users/alo/MusicOntology/features/rdf/af-TimbreToolbox.rdf')
87 graph.serialize('/Users/alo/MusicOntology/features/rdfn3/af-TimbreToolbox.n3', format="n3")
88