Mercurial > hg > audio-features-catalogue
comparison rdfpy/af-mirtoolbox.py @ 18:d5012016bf64 tip
added rdfpy and rdfonto directories
author | nothing@tehis.net |
---|---|
date | Tue, 23 Apr 2013 11:49:20 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:2b5c292ad12f | 18:d5012016bf64 |
---|---|
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 orig = 'http://sovarr.c4dm.eecs.qmul.ac.uk/features/' | |
7 | |
8 local = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/mir/MIRToolbox/1.0#') | |
9 | |
10 af = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/ontology/1.0#') | |
11 | |
12 afv = Namespace('http://sovarr.c4dm.eecs.qmul.ac.uk/af/vocabulary/1.0#') | |
13 | |
14 DC = Namespace("http://purl.org/dc/elements/1.1/") | |
15 | |
16 vs = Namespace('http://www.w3.org/2003/06/sw-vocab-status/ns#') | |
17 | |
18 afskos = Namespace(url + '/vocabulary/skos/1.0#') | |
19 | |
20 skos = Namespace('http://www.w3.org/2004/02/skos/core#') | |
21 | |
22 graph = Graph() | |
23 graph.bind('af', af) | |
24 graph.bind('afv', afv) | |
25 graph.bind('mirtoolbox', local) | |
26 graph.bind('dc', DC) | |
27 graph.bind('owl', OWL) | |
28 graph.bind('vs', vs) | |
29 graph.bind('skos', skos) | |
30 graph.bind('afsv', afskos) | |
31 | |
32 graph.add(( | |
33 URIRef(''), | |
34 RDF.type, | |
35 OWL.Ontology | |
36 )) | |
37 | |
38 graph.add(( | |
39 URIRef(''), | |
40 DC['title'], | |
41 Literal("MIR Toolbox Ontology", lang="en") | |
42 )) | |
43 | |
44 graph.add(( | |
45 URIRef(''), | |
46 OWL.versionInfo, | |
47 Literal("Version 1.0", lang="en") | |
48 )) | |
49 | |
50 graph.add(( | |
51 URIRef(''), | |
52 DC['description'], | |
53 Literal("This is an ontology for annotating MIR Toolbox audio features", lang="en") | |
54 )) | |
55 | |
56 graph.add(( vs['term_status'], RDF.type, OWL.AnnotationProperty )) | |
57 | |
58 source = Graph() | |
59 source.parse(basedir+'rdfonto/MIRToolbox.rdf') | |
60 | |
61 ''' | |
62 graph.add(( | |
63 URIRef(local+'Operator'), | |
64 RDF.type, | |
65 OWL.Class | |
66 )) | |
67 graph.add(( | |
68 URIRef(local+'FeatureExtractor'), | |
69 RDF.type, | |
70 OWL.Class | |
71 )) | |
72 graph.add(( | |
73 URIRef(local+'HighLevelFeature'), | |
74 RDF.type, | |
75 OWL.Class | |
76 )) | |
77 | |
78 for name in ['Structure', 'Statistics', 'Predictions', 'Similarity']: | |
79 idref = URIRef(local+name) | |
80 graph.add(( | |
81 idref, | |
82 RDF.type, | |
83 OWL.Class | |
84 )) | |
85 graph.add(( | |
86 idref, | |
87 RDFS.subClassOf, | |
88 URIRef(local+'HighLevelFeature') | |
89 )) | |
90 | |
91 | |
92 for name in ['Dynamics', 'Rhythm', 'Timbre', 'Pitch', 'Tonality']: | |
93 idref = URIRef(local+name+'FeatureExtractor') | |
94 graph.add(( | |
95 idref, | |
96 RDF.type, | |
97 OWL.Class | |
98 )) | |
99 graph.add(( | |
100 idref, | |
101 RDFS.subClassOf, | |
102 URIRef(local+'FeatureExtractor') | |
103 )) | |
104 ''' | |
105 for su in source.subjects(RDF.type, RDFS.Resource): | |
106 name = su.split('/')[-1] | |
107 idref = URIRef(local + name) | |
108 graph.add(( | |
109 idref, | |
110 RDF.type, | |
111 OWL.Class | |
112 )) | |
113 | |
114 graph.add(( | |
115 idref, | |
116 OWL.sameAs, | |
117 afv[su.split('/')[-1]] | |
118 )) | |
119 | |
120 graph.add((idref, vs['term_status'], Literal("testing", lang="en") )) | |
121 | |
122 graph.add(( idref, RDFS.label, Literal(name, lang="en") )) | |
123 | |
124 graph.add(( idref, RDFS.comment, Literal( name + " MIR Toolbox audio feature") )) | |
125 | |
126 count=sum(1 for _ in source.objects(su, URIRef(orig+'tag'))) | |
127 | |
128 if count == 1: | |
129 for it in source.objects(su, URIRef(orig+'tag')): | |
130 graph.add(( | |
131 idref, | |
132 RDFS.subClassOf, | |
133 af[it+'FeatureExtractor'] | |
134 )) | |
135 | |
136 count = sum(1 for _ in source.objects(su, URIRef(orig+'group'))) | |
137 | |
138 if count == 1: | |
139 for it in source.objects(su, URIRef(orig+'group')): | |
140 graph.add(( | |
141 idref, | |
142 RDFS.subClassOf, | |
143 af[it] | |
144 )) | |
145 | |
146 count=sum(1 for _ in source.objects(su, URIRef(orig+'type'))) | |
147 | |
148 if count == 1: | |
149 for it in source.objects(su, URIRef(orig+'type')): | |
150 if it == "Operator": | |
151 graph.add(( | |
152 idref, | |
153 RDFS.subClassOf, | |
154 af[it] | |
155 )) | |
156 | |
157 graph.serialize(basedir + 'rdfonto/af-mirtoolbox.rdf') | |
158 graph.serialize(basedir + 'rdfonto/af-mirtoolbox.n3', format='n3') |