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