nothing@18: import rdflib nothing@18: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace nothing@18: nothing@18: url = 'http://sovarr.c4dm.eecs.qmul.ac.uk/af/' nothing@18: basedir = '/Users/alo/MusicOntology/features/' nothing@18: nothing@18: afc = Namespace(url + 'features/') nothing@18: nothing@18: af = Namespace(url+'ontology/1.0#') 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('afsv', afskos) nothing@18: graph.bind('skos', skos) nothing@18: graph.bind('owl', OWL) nothing@18: graph.bind('af', af) nothing@18: graph.bind('vs', vs) nothing@18: nothing@18: graph.add(( vs['term_status'], RDF.type, OWL.AnnotationProperty )) nothing@18: nothing@18: source = Graph() nothing@18: source.parse(basedir + 'af-catalogue.rdf') nothing@18: nothing@18: for sub in source.subjects(RDF.type, OWL.Class): nothing@18: name = sub.split('/')[-1] nothing@18: id = name.replace("(", "").replace(")", "").replace("4Hz", "") nothing@18: id = URIRef(afskos+id) nothing@18: graph.add((id, RDF.type, skos['Concept'])) nothing@18: graph.add((id, RDFS.subClassOf, af['AudioFeature'])) nothing@18: graph.add((id, vs['term_status'], Literal("testing", lang="en") )) nothing@18: count = sum(1 for _ in source.objects(sub, afc['feature'])) nothing@18: if count > 0: nothing@18: labelAdded = False nothing@18: for label in source.objects(sub, afc['feature']): nothing@18: if not labelAdded: nothing@18: graph.add(( id, skos['prefLabel'], Literal(label, lang="en") )) nothing@18: #graph.add(( id, RDFS.label, Literal(label, lang="en") )) nothing@18: graph.add(( id, skos['note'], Literal(label) )) nothing@18: labelAdded = True nothing@18: else: nothing@18: if name.find("ADRess") == 0: nothing@18: graph.add(( id, skos['prefLabel'], Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") )) nothing@18: #graph.add(( id, RDFS.label, Literal(name + " (Azimuth Discrimination and Resynthesis)", lang="en") )) nothing@18: graph.add(( id, skos['note'], Literal(name + " (Azimuth Discrimination and Resynthesis)") )) nothing@18: else: nothing@18: if name.find("Aim") == 0: nothing@18: graph.add(( id, skos['prefLabel'], Literal(name + " (Auditory Image Model) ", lang="en") )) nothing@18: #graph.add(( id, RDFS.label, Literal(name + " (Auditory Image Model) ", lang="en") )) nothing@18: graph.add(( id, skos['note'], Literal(name + " (Auditory Image Model) ") )) nothing@18: else: nothing@18: graph.add(( id, skos['prefLabel'], Literal(name, lang="en"))) nothing@18: #graph.add(( id, RDFS.label, Literal(name, lang="en"))) nothing@18: graph.add(( id, skos['note'], Literal(name) )) nothing@18: nothing@18: graph.serialize(basedir+'rdfonto/af-skos-vocabulary.rdf') nothing@18: graph.serialize(basedir+'rdfonto/af-skos-vocabulary.n3', format="n3") nothing@18: