diff rdfpy/af-marsyas.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/af-marsyas.py	Tue Apr 23 11:49:20 2013 +0100
@@ -0,0 +1,105 @@
+import rdflib
+from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace
+
+basedir = '/Users/alo/MusicOntology/features/'
+
+local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/'
+
+DC = Namespace(u"http://purl.org/dc/elements/1.1/")
+
+graph = Graph()
+graph.bind('af', URIRef(local))
+graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/'))
+graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#'))
+
+graph.add((
+    URIRef(''),
+    RDF.type,
+    OWL.Ontology
+))
+
+graph.add((
+    URIRef(''),
+    DC['title'],
+    Literal("Marsyas Ontology")
+))
+
+graph.add((
+    URIRef(''),
+    OWL.versionInfo,
+    Literal("Version 0.1")
+))
+
+graph.add((
+    URIRef(''),
+    DC['description'],
+    Literal("This is an ontology derived from Marsyas feature extraction tools for the Audio Features engineering process")
+))
+
+
+source = Graph()
+source.parse(basedir+'rdfonto/af-Marsyas.n3', format='n3')
+
+categories = []
+
+for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')):
+    if not ob in categories:
+        categories.append(ob)
+
+graph.add((
+    URIRef(local+'Analysis'),
+    RDF.type,
+    OWL.Class
+))        
+    
+for category in categories:
+    graph.add((
+        URIRef(local+category),
+        RDF.type,
+        OWL.Class    
+    ))
+    graph.add((
+        URIRef(local+category),
+        RDFS.subClassOf,
+        URIRef(local+'Analysis'),
+    )) 
+
+for su in source.subjects(RDF.type, RDFS.Resource):
+    idref = URIRef(local+su.split('/')[-1])
+#    graph.add((
+#        idref,
+#        RDF.type,
+#        OWL.Class
+#    ))
+
+    graph.add((
+        idref,
+        RDF.type,
+        URIRef(local+"AudioFeature")
+    ))
+    
+    count = sum(1 for _ in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')))
+    
+    if count > 0:    
+        for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')):
+            graph.add((
+                idref,
+                RDFS.subClassOf,
+                URIRef(local+ob)
+            ))
+    else:
+        graph.add((
+            idref,
+            RDFS.subClassOf,
+            URIRef(local+'Analysis'),
+        ))
+        
+    for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')):
+        graph.add((
+            idref,
+            URIRef('http://purl.org/dc/elements/1.1/description'),
+            ob
+        ))
+
+graph.serialize(basedir + 'rdfonto/Marsyas-onto.rdf')        
+graph.serialize(basedir + 'rdfonto/Marsyas-onto.n3', format='n3')
\ No newline at end of file