diff rdfpy/writeTimbreToolboxOnto.py @ 18:d5012016bf64 tip

added rdfpy and rdfonto directories
author nothing@tehis.net
date Tue, 23 Apr 2013 11:49:20 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdfpy/writeTimbreToolboxOnto.py	Tue Apr 23 11:49:20 2013 +0100
@@ -0,0 +1,171 @@
+import rdflib, os, fnmatch, urllib2
+from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, XSD, Namespace
+
+graph = Graph()
+
+af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/features/')
+graph.bind('af', af)
+
+dc = Namespace('http://purl.org/dc/elements/1.1/')
+graph.bind('dc', dc)
+
+owl = Namespace('http://www.w3.org/2002/07/owl#')
+graph.bind('owl', owl)
+
+xsd = Namespace('http://www.w3.org/2001/XMLSchema#')
+graph.bind('xsd', xsd)
+
+
+input = {
+    'au': "Audio Signal",
+    'tee': "Temporal Energy Envelope",
+    'stft': "Short-term Fourier Transform",
+    'erb': "Auditory model",
+    'harm': "Harmonic"
+}
+
+graph.add((
+    URIRef(af+"AudioDescriptor"),
+    RDF.type,
+    OWL.Class
+))
+graph.add((
+    URIRef(af+"AudioDescriptor"),
+    RDFS.label,
+    Literal("Timbre Toolbox Audio Descriptor", lang="en")
+))
+
+
+graph.add((
+    URIRef(af+"InputSignal"),
+    RDF.type,
+    OWL.Class
+))
+graph.add((
+    URIRef(af+"InputSignal"),
+    RDFS.label,
+    Literal("Timbre Toolbox Input Representation", lang="en")
+))
+
+graph.add((
+    URIRef(af+"inputRepresentation"),
+    RDF.type,
+    OWL.ObjectProperty
+))
+graph.add((
+    URIRef(af+"inputRepresentation"),
+    RDFS.domain,
+    URIRef(af+"AudioDescriptor")
+))
+graph.add((
+    URIRef(af+"inputRepresentation"),
+    RDFS.range,
+    URIRef(af+"InputSignal")
+))
+
+
+
+for inkey in input.keys():
+    id = af+input[inkey].replace(" ", "")
+    graph.add((
+        URIRef(id),
+        RDF.type,
+        OWL.Class
+    ))
+    graph.add((
+        URIRef(id),
+        RDFS.label,
+        Literal(input[inkey], lang="en")
+    ))
+    graph.add((
+        URIRef(id),
+        RDFS.subClassOf,
+        URIRef(af+"InputSignal")
+    ))
+
+features = {
+    'Global Descriptors': [
+        {"Attack": "tee"},
+        {"Decay": "tee"},
+        {"Release": "tee"},
+        {"Log-Attack Time": "tee"},
+        {"Attack Slope": "tee"},
+        {"DecreaseSlope": "tee"},
+        {"Temporal Centroid": "tee"},
+        {"Effective Duration": "tee"},
+        {"Frequency of Energy Modulation": "tee"},
+        {"Amplitude of Energy Modulation": "tee"}
+    ],
+
+    'Time-Varying Descriptors': [
+        {"Autocorrelation": 'au'},
+        {"Zero Crossing Rate": 'au'},
+        {"RMS-Energy Envelope": 'tee'},
+        {"Spectral Centroid": 'stft,erb,harm'},
+        {"Spectral Spread": 'stft,erb,harm'},
+        {"Spectral Skewness": 'stft,erb,harm'},
+        {"Spectral Kurtosis": 'stft,erb,harm'},
+        {"Spectral Slope": 'stft,erb,harm'},
+        {"Spectral Decrease": 'stft,erb,harm'},
+        {"Spectral Rolloff": 'stft,erb,harm'},
+        {"Spectro-temporal Variation": 'stft,erb,harm'},
+        {"Spectral Flatness": 'stft,erb'},
+        {"Spectral Crest": 'stft,erb'},
+        {"Harmonic Energy": 'harm'},
+        {"Noise Energy": 'harm'},
+        {"Noisiness": 'harm'},
+        {"Fundamental Frequency": 'harm'},
+        {"Inharmonicity": 'harm'},
+        {"Tristimulus": 'harm'},
+        {"Harmonic Spectral Deviation": 'harm'},
+        {"Odd to even harmonic ratio": 'harm'}
+    ]
+}
+
+for temporal in features.keys():
+    auid = af + temporal[:-1].replace("-", "").replace(" ", "")
+    graph.add((
+        URIRef(auid),
+        RDF.type,
+        OWL.Class
+    ))
+    graph.add((
+        URIRef(auid),
+        RDFS.subClassOf,
+        URIRef(af+"AudioDescriptor")
+    ))
+    
+    for feature in features[temporal]:
+        name = feature.keys()[0]
+        id = af + name.replace(" ", "")
+        #graph.add((
+        #    URIRef(id),
+        #    RDF.type,
+        #    OWL.Class
+        #))
+        graph.add((
+            URIRef(id),
+            RDF.type,
+            URIRef(af+"AudioFeature")
+        ))        
+        graph.add((
+            URIRef(id),
+            RDFS.label,
+            Literal(name, lang="en")
+        ))
+        graph.add((
+            URIRef(id),
+            RDFS.subClassOf,
+            URIRef(auid)
+        ))
+        for inp in feature[name].split(","):
+            graph.add((
+                URIRef(id),
+                URIRef(af+"inputRepresentation"),
+                URIRef(af+input[inp].replace(" ", ""))
+            ))
+            
+
+graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.rdf')
+graph.serialize('/Users/alo/MusicOntology/features/rdfonto/TimbreToolbox-onto.n3', format="n3")
+            
\ No newline at end of file