Mercurial > hg > audio-features-catalogue
view rdfpy/writeAubioOnto.py @ 18:d5012016bf64 tip
added rdfpy and rdfonto directories
author | nothing@tehis.net |
---|---|
date | Tue, 23 Apr 2013 11:49:20 +0100 |
parents | 62d2c72e4223 |
children |
line wrap: on
line source
import rdflib from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL basedir = '/Users/alo/MusicOntology/features/' local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' 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#')) source = Graph() source.parse(basedir+'rdfonto/af-aubio.n3', format='n3') categories = [] for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): if not ob in categories: categories.append(ob) for category in categories: graph.add(( URIRef(local+category), RDF.type, OWL.Class )) for su in source.subjects(RDF.type, RDFS.Resource): idref = URIRef(local+su.split('/')[-1]) graph.add(( idref, RDF.type, OWL.Class )) for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): graph.add(( idref, RDFS.subClassOf, URIRef(local+ob) )) for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')): graph.add(( idref, URIRef('http://purl.org/dc/elements/1.1/description'), ob )) graph.serialize(basedir + 'rdfonto/aubio-onto.rdf') graph.serialize(basedir + 'rdfonto/aubio-onto.n3', format='n3')