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('af', af) nothing@18: nothing@18: dc = Namespace('http://purl.org/dc/elements/1.1/') nothing@18: graph.bind('dc', dc) nothing@18: nothing@18: owl = Namespace('http://www.w3.org/2002/07/owl#') nothing@18: graph.bind('owl', owl) nothing@18: nothing@18: xsd = Namespace('http://www.w3.org/2001/XMLSchema#') nothing@18: graph.bind('xsd', xsd) nothing@18: 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: graph.add(( nothing@18: URIRef(af+"AudioDescriptor"), nothing@18: RDF.type, nothing@18: OWL.Class nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(af+"AudioDescriptor"), nothing@18: RDFS.label, nothing@18: Literal("Timbre Toolbox Audio Descriptor", lang="en") nothing@18: )) nothing@18: nothing@18: nothing@18: graph.add(( nothing@18: URIRef(af+"InputSignal"), nothing@18: RDF.type, nothing@18: OWL.Class nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(af+"InputSignal"), nothing@18: RDFS.label, nothing@18: Literal("Timbre Toolbox Input Representation", lang="en") nothing@18: )) nothing@18: nothing@18: graph.add(( nothing@18: URIRef(af+"inputRepresentation"), nothing@18: RDF.type, nothing@18: OWL.ObjectProperty nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(af+"inputRepresentation"), nothing@18: RDFS.domain, nothing@18: URIRef(af+"AudioDescriptor") nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(af+"inputRepresentation"), nothing@18: RDFS.range, nothing@18: URIRef(af+"InputSignal") nothing@18: )) nothing@18: nothing@18: nothing@18: nothing@18: for inkey in input.keys(): nothing@18: id = af+input[inkey].replace(" ", "") nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDF.type, nothing@18: OWL.Class nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDFS.label, nothing@18: Literal(input[inkey], lang="en") nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDFS.subClassOf, nothing@18: URIRef(af+"InputSignal") 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: auid = af + temporal[:-1].replace("-", "").replace(" ", "") nothing@18: graph.add(( nothing@18: URIRef(auid), nothing@18: RDF.type, nothing@18: OWL.Class nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(auid), nothing@18: RDFS.subClassOf, nothing@18: URIRef(af+"AudioDescriptor") nothing@18: )) nothing@18: 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: # OWL.Class nothing@18: #)) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDF.type, nothing@18: URIRef(af+"AudioFeature") nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDFS.label, nothing@18: Literal(name, lang="en") nothing@18: )) nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: RDFS.subClassOf, nothing@18: URIRef(auid) nothing@18: )) nothing@18: for inp in feature[name].split(","): nothing@18: graph.add(( nothing@18: URIRef(id), nothing@18: URIRef(af+"inputRepresentation"), nothing@18: URIRef(af+input[inp].replace(" ", "")) nothing@18: )) nothing@18: nothing@18: nothing@18: graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.rdf') nothing@18: graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.n3', format="n3") nothing@18: