Mercurial > hg > audio-features-catalogue
comparison rdfpy/writeMIRToolboxOnto.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children | 53069717108c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:62d2c72e4223 |
---|---|
1 import rdflib, os | |
2 from rdflib import Graph, RDF, RDFS, plugin, URIRef, Literal, OWL, Namespace | |
3 | |
4 basedir = '/Users/alo/MusicOntology/features/' | |
5 | |
6 local = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' | |
7 | |
8 DC = Namespace(u"http://purl.org/dc/elements/1.1/") | |
9 | |
10 graph = Graph() | |
11 graph.bind('af', URIRef(local)) | |
12 graph.bind('dc', URIRef('http://purl.org/dc/elements/1.1/')) | |
13 graph.bind('owl', URIRef('http://www.w3.org/2002/07/owl#')) | |
14 | |
15 graph.add(( | |
16 URIRef(''), | |
17 RDF.type, | |
18 OWL.Ontology | |
19 )) | |
20 | |
21 graph.add(( | |
22 URIRef(''), | |
23 DC['title'], | |
24 Literal("MIR Toolbox Ontology") | |
25 )) | |
26 | |
27 graph.add(( | |
28 URIRef(''), | |
29 OWL.versionInfo, | |
30 Literal("Version 0.1") | |
31 )) | |
32 | |
33 graph.add(( | |
34 URIRef(''), | |
35 DC['description'], | |
36 Literal("This is an ontology derived from MIR Toolbox for the Audio Features engineering process") | |
37 )) | |
38 | |
39 source = Graph() | |
40 source.parse(basedir+'rdfonto/af-MIRToolbox.rdf') | |
41 | |
42 graph.add(( | |
43 URIRef(local+'Operator'), | |
44 RDF.type, | |
45 OWL.Class | |
46 )) | |
47 graph.add(( | |
48 URIRef(local+'FeatureExtractor'), | |
49 RDF.type, | |
50 OWL.Class | |
51 )) | |
52 graph.add(( | |
53 URIRef(local+'HighLevelFeature'), | |
54 RDF.type, | |
55 OWL.Class | |
56 )) | |
57 | |
58 for name in ['Structure', 'Statistics', 'Predictions', 'Similarity']: | |
59 idref = URIRef(local+name) | |
60 graph.add(( | |
61 idref, | |
62 RDF.type, | |
63 OWL.Class | |
64 )) | |
65 graph.add(( | |
66 idref, | |
67 RDFS.subClassOf, | |
68 URIRef(local+'HighLevelFeature') | |
69 )) | |
70 | |
71 | |
72 for name in ['Dynamics', 'Rhythm', 'Timbre', 'Pitch', 'Tonality']: | |
73 idref = URIRef(local+name+'FeatureExtractor') | |
74 graph.add(( | |
75 idref, | |
76 RDF.type, | |
77 OWL.Class | |
78 )) | |
79 graph.add(( | |
80 idref, | |
81 RDFS.subClassOf, | |
82 URIRef(local+'FeatureExtractor') | |
83 )) | |
84 | |
85 for su in source.subjects(RDF.type, RDFS.Resource): | |
86 idref = URIRef(local + su.split('/')[-1]) | |
87 graph.add(( | |
88 idref, | |
89 RDF.type, | |
90 OWL.Class | |
91 )) | |
92 | |
93 count=sum(1 for _ in source.objects(su, URIRef(local+'tag'))) | |
94 | |
95 if count == 1: | |
96 for it in source.objects(su, URIRef(local+'tag')): | |
97 graph.add(( | |
98 idref, | |
99 RDFS.subClassOf, | |
100 URIRef(local+it+'FeatureExtractor') | |
101 )) | |
102 | |
103 count = sum(1 for _ in source.objects(su, URIRef(local+'group'))) | |
104 | |
105 if count == 1: | |
106 for it in source.objects(su, URIRef(local+'group')): | |
107 graph.add(( | |
108 idref, | |
109 RDFS.subClassOf, | |
110 URIRef(local+it) | |
111 )) | |
112 | |
113 count=sum(1 for _ in source.objects(su, URIRef(local+'type'))) | |
114 | |
115 if count == 1: | |
116 for it in source.objects(su, URIRef(local+'type')): | |
117 if it == "Operator": | |
118 graph.add(( | |
119 idref, | |
120 RDFS.subClassOf, | |
121 URIRef(local+it) | |
122 )) | |
123 | |
124 graph.serialize(basedir + 'rdfonto/MIR-onto.rdf') | |
125 graph.serialize(basedir + 'rdfonto/MIR-onto.n3', format='n3') |