Mercurial > hg > audio-features-catalogue
view rdfpy/af-mirtoolbox.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 source
import rdflib, os from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace basedir = '/Users/alo/MusicOntology/features/' orig = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' local = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/mir/MIRToolbox/1.0#') af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/ontology/1.0#') afv = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/vocabulary/1.0#') DC = Namespace("http://purl.org/dc/elements/1.1/") vs = Namespace('http://www.w3.org/2003/06/sw-vocab-status/ns#') afskos = Namespace(url + '/vocabulary/skos/1.0#') skos = Namespace('http://www.w3.org/2004/02/skos/core#') graph = Graph() graph.bind('af', af) graph.bind('afv', afv) graph.bind('mirtoolbox', local) graph.bind('dc', DC) graph.bind('owl', OWL) graph.bind('vs', vs) graph.bind('skos', skos) graph.bind('afsv', afskos) graph.add(( URIRef(''), RDF.type, OWL.Ontology )) graph.add(( URIRef(''), DC['title'], Literal("MIR Toolbox Ontology", lang="en") )) graph.add(( URIRef(''), OWL.versionInfo, Literal("Version 1.0", lang="en") )) graph.add(( URIRef(''), DC['description'], Literal("This is an ontology for annotating MIR Toolbox audio features", lang="en") )) graph.add(( vs['term_status'], RDF.type, OWL.AnnotationProperty )) source = Graph() source.parse(basedir+'rdfonto/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): name = su.split('/')[-1] idref = URIRef(local + name) graph.add(( idref, RDF.type, OWL.Class )) graph.add(( idref, OWL.sameAs, afv[su.split('/')[-1]] )) graph.add((idref, vs['term_status'], Literal("testing", lang="en") )) graph.add(( idref, RDFS.label, Literal(name, lang="en") )) graph.add(( idref, RDFS.comment, Literal( name + " MIR Toolbox audio feature") )) count=sum(1 for _ in source.objects(su, URIRef(orig+'tag'))) if count == 1: for it in source.objects(su, URIRef(orig+'tag')): graph.add(( idref, RDFS.subClassOf, af[it+'FeatureExtractor'] )) count = sum(1 for _ in source.objects(su, URIRef(orig+'group'))) if count == 1: for it in source.objects(su, URIRef(orig+'group')): graph.add(( idref, RDFS.subClassOf, af[it] )) count=sum(1 for _ in source.objects(su, URIRef(orig+'type'))) if count == 1: for it in source.objects(su, URIRef(orig+'type')): if it == "Operator": graph.add(( idref, RDFS.subClassOf, af[it] )) graph.serialize(basedir + 'rdfonto/af-mirtoolbox.rdf') graph.serialize(basedir + 'rdfonto/af-mirtoolbox.n3', format='n3')