Mercurial > hg > audio-features-catalogue
view rdfpy/writeMIRToolboxOnto.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children | 53069717108c |
line wrap: on
line source
import rdflib, os 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("MIR Toolbox Ontology") )) graph.add(( URIRef(''), OWL.versionInfo, Literal("Version 0.1") )) graph.add(( URIRef(''), DC['description'], Literal("This is an ontology derived from MIR Toolbox for the Audio Features engineering process") )) source = Graph() source.parse(basedir+'rdfonto/af-MIRToolbox.rdf') graph.add(( URIRef(local+'Operator'), RDF.type, OWL.Class )) graph.add(( URIRef(local+'FeatureExtractor'), RDF.type, OWL.Class )) graph.add(( URIRef(local+'HighLevelFeature'), RDF.type, OWL.Class )) for name in ['Structure', 'Statistics', 'Predictions', 'Similarity']: idref = URIRef(local+name) graph.add(( idref, RDF.type, OWL.Class )) graph.add(( idref, RDFS.subClassOf, URIRef(local+'HighLevelFeature') )) for name in ['Dynamics', 'Rhythm', 'Timbre', 'Pitch', 'Tonality']: idref = URIRef(local+name+'FeatureExtractor') graph.add(( idref, RDF.type, OWL.Class )) graph.add(( idref, RDFS.subClassOf, URIRef(local+'FeatureExtractor') )) for su in source.subjects(RDF.type, RDFS.Resource): idref = URIRef(local + su.split('/')[-1]) graph.add(( idref, RDF.type, OWL.Class )) count=sum(1 for _ in source.objects(su, URIRef(local+'tag'))) if count == 1: for it in source.objects(su, URIRef(local+'tag')): graph.add(( idref, RDFS.subClassOf, URIRef(local+it+'FeatureExtractor') )) count = sum(1 for _ in source.objects(su, URIRef(local+'group'))) if count == 1: for it in source.objects(su, URIRef(local+'group')): graph.add(( idref, RDFS.subClassOf, URIRef(local+it) )) count=sum(1 for _ in source.objects(su, URIRef(local+'type'))) if count == 1: for it in source.objects(su, URIRef(local+'type')): if it == "Operator": graph.add(( idref, RDFS.subClassOf, URIRef(local+it) )) graph.serialize(basedir + 'rdfonto/MIR-onto.rdf') graph.serialize(basedir + 'rdfonto/MIR-onto.n3', format='n3')