nothing@0: import rdflib nothing@0: from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL nothing@0: nothing@0: basedir = '/Users/alo/MusicOntology/features/' nothing@0: nothing@0: local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' nothing@0: nothing@0: graph = Graph() nothing@0: graph.bind('af', URIRef(local)) nothing@0: graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) nothing@0: graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) nothing@0: nothing@0: source = Graph() nothing@0: source.parse(basedir+'rdfonto/af-aubio.n3', format='n3') nothing@0: nothing@0: categories = [] nothing@0: nothing@0: for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): nothing@0: if not ob in categories: nothing@0: categories.append(ob) nothing@0: nothing@0: for category in categories: nothing@0: graph.add(( nothing@0: URIRef(local+category), nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: for su in source.subjects(RDF.type, RDFS.Resource): nothing@0: idref = URIRef(local+su.split('/')[-1]) nothing@0: graph.add(( nothing@0: idref, nothing@0: RDF.type, nothing@0: OWL.Class nothing@0: )) nothing@0: nothing@0: for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): nothing@0: graph.add(( nothing@0: idref, nothing@0: RDFS.subClassOf, nothing@0: URIRef(local+ob) nothing@0: )) nothing@0: nothing@0: for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')): nothing@0: graph.add(( nothing@0: idref, nothing@0: URIRef('http://purl.org/dc/elements/1.1/description'), nothing@0: ob nothing@0: )) nothing@0: nothing@0: graph.serialize(basedir + 'rdfonto/aubio-onto.rdf') nothing@0: graph.serialize(basedir + 'rdfonto/aubio-onto.n3', format='n3')