annotate 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
rev   line source
nothing@0 1 import rdflib
nothing@0 2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL
nothing@0 3
nothing@0 4 basedir = '/Users/alo/MusicOntology/features/'
nothing@0 5
nothing@0 6 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/'
nothing@0 7
nothing@0 8 graph = Graph()
nothing@0 9 graph.bind('af', URIRef(local))
nothing@0 10 graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/'))
nothing@0 11 graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#'))
nothing@0 12
nothing@0 13 source = Graph()
nothing@0 14 source.parse(basedir+'rdfonto/af-aubio.n3', format='n3')
nothing@0 15
nothing@0 16 categories = []
nothing@0 17
nothing@0 18 for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')):
nothing@0 19 if not ob in categories:
nothing@0 20 categories.append(ob)
nothing@0 21
nothing@0 22 for category in categories:
nothing@0 23 graph.add((
nothing@0 24 URIRef(local+category),
nothing@0 25 RDF.type,
nothing@0 26 OWL.Class
nothing@0 27 ))
nothing@0 28
nothing@0 29 for su in source.subjects(RDF.type, RDFS.Resource):
nothing@0 30 idref = URIRef(local+su.split('/')[-1])
nothing@0 31 graph.add((
nothing@0 32 idref,
nothing@0 33 RDF.type,
nothing@0 34 OWL.Class
nothing@0 35 ))
nothing@0 36
nothing@0 37 for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')):
nothing@0 38 graph.add((
nothing@0 39 idref,
nothing@0 40 RDFS.subClassOf,
nothing@0 41 URIRef(local+ob)
nothing@0 42 ))
nothing@0 43
nothing@0 44 for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')):
nothing@0 45 graph.add((
nothing@0 46 idref,
nothing@0 47 URIRef('http://purl.org/dc/elements/1.1/description'),
nothing@0 48 ob
nothing@0 49 ))
nothing@0 50
nothing@0 51 graph.serialize(basedir + 'rdfonto/aubio-onto.rdf')
nothing@0 52 graph.serialize(basedir + 'rdfonto/aubio-onto.n3', format='n3')