Mercurial > hg > audio-features-catalogue
comparison rdfpy/writeAubioOnto.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:62d2c72e4223 |
---|---|
1 import rdflib | |
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL | |
3 | |
4 basedir = '/Users/alo/MusicOntology/features/' | |
5 | |
6 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' | |
7 | |
8 graph = Graph() | |
9 graph.bind('af', URIRef(local)) | |
10 graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) | |
11 graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) | |
12 | |
13 source = Graph() | |
14 source.parse(basedir+'rdfonto/af-aubio.n3', format='n3') | |
15 | |
16 categories = [] | |
17 | |
18 for su, ob in source.subject_objects(URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): | |
19 if not ob in categories: | |
20 categories.append(ob) | |
21 | |
22 for category in categories: | |
23 graph.add(( | |
24 URIRef(local+category), | |
25 RDF.type, | |
26 OWL.Class | |
27 )) | |
28 | |
29 for su in source.subjects(RDF.type, RDFS.Resource): | |
30 idref = URIRef(local+su.split('/')[-1]) | |
31 graph.add(( | |
32 idref, | |
33 RDF.type, | |
34 OWL.Class | |
35 )) | |
36 | |
37 for ob in source.objects(su,URIRef('file:///Users/alo/MusicOntology/features/rdf/type')): | |
38 graph.add(( | |
39 idref, | |
40 RDFS.subClassOf, | |
41 URIRef(local+ob) | |
42 )) | |
43 | |
44 for ob in source.objects(su,URIRef('http://purl.org/dc/elements/1.1/description')): | |
45 graph.add(( | |
46 idref, | |
47 URIRef('http://purl.org/dc/elements/1.1/description'), | |
48 ob | |
49 )) | |
50 | |
51 graph.serialize(basedir + 'rdfonto/aubio-onto.rdf') | |
52 graph.serialize(basedir + 'rdfonto/aubio-onto.n3', format='n3') |