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