nothing@18: import rdflib, os, fnmatch, urllib2 nothing@18: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace nothing@18: nothing@18: graph = Graph() nothing@18: nothing@18: af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/features/') nothing@18: graph.bind('local', af) nothing@18: nothing@18: dc = Namespace('http://purl.org/dc/elements/1.1/') nothing@18: graph.bind('dc', dc) nothing@18: nothing@18: input = { nothing@18: 'au': "Audio Signal", nothing@18: 'tee': "Temporal Energy Envelope", nothing@18: 'stft': "Short-term Fourier Transform", nothing@18: 'erb': "Auditory model", nothing@18: 'harm': "Harmonic" nothing@18: } nothing@18: nothing@18: features = { nothing@18: 'Global Descriptors': [ nothing@18: {"Attack": "tee"}, nothing@18: {"Decay": "tee"}, nothing@18: {"Release": "tee"}, nothing@18: {"Log-Attack Time": "tee"}, nothing@18: {"Attack Slope": "tee"}, nothing@18: {"DecreaseSlope": "tee"}, nothing@18: {"Temporal Centroid": "tee"}, nothing@18: {"Effective Duration": "tee"}, nothing@18: {"Frequency of Energy Modulation": "tee"}, nothing@18: {"Amplitude of Energy Modulation": "tee"} nothing@18: ], nothing@18: nothing@18: 'Time-Varying Descriptors': [ nothing@18: {"Autocorrelation": 'au'}, nothing@18: {"Zero Crossing Rate": 'au'}, nothing@18: {"RMS-Energy Envelope": 'tee'}, nothing@18: {"Spectral Centroid": 'stft,erb,harm'}, nothing@18: {"Spectral Spread": 'stft,erb,harm'}, nothing@18: {"Spectral Skewness": 'stft,erb,harm'}, nothing@18: {"Spectral Kurtosis": 'stft,erb,harm'}, nothing@18: {"Spectral Slope": 'stft,erb,harm'}, nothing@18: {"Spectral Decrease": 'stft,erb,harm'}, nothing@18: {"Spectral Rolloff": 'stft,erb,harm'}, nothing@18: {"Spectro-temporal Variation": 'stft,erb,harm'}, nothing@18: {"Spectral Flatness": 'stft,erb'}, nothing@18: {"Spectral Crest": 'stft,erb'}, nothing@18: {"Harmonic Energy": 'harm'}, nothing@18: {"Noise Energy": 'harm'}, nothing@18: {"Noisiness": 'harm'}, nothing@18: {"Fundamental Frequency": 'harm'}, nothing@18: {"Inharmonicity": 'harm'}, nothing@18: {"Tristimulus": 'harm'}, nothing@18: {"Harmonic Spectral Deviation": 'harm'}, nothing@18: {"Odd to even harmonic ratio": 'harm'} nothing@18: ] nothing@18: } nothing@18: nothing@18: for temporal in features.keys(): nothing@18: for feature in features[temporal]: nothing@18: name = feature.keys()[0] nothing@18: id = af + name.replace(" ", "") nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDF.type, nothing@18: RDFS.Resource nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: af['feature'], nothing@18: Literal(name) nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: af['feature'], nothing@18: Literal(name) nothing@18: )) nothing@18: for inp in feature[name].split(","): nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: af['signal'], nothing@18: Literal(input[inp]) nothing@18: )) nothing@18: nothing@18: nothing@18: graph.serialize('/Users/alo/MusicOntology/features/rdf/af-TimbreToolbox.rdf') nothing@18: graph.serialize('/Users/alo/MusicOntology/features/rdfn3/af-TimbreToolbox.n3', format="n3") nothing@18: