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