Chris@439
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@439
|
2
|
Chris@439
|
3 /*
|
Chris@439
|
4 Sonic Visualiser
|
Chris@439
|
5 An audio file viewer and annotation editor.
|
Chris@439
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@727
|
7 This file copyright 2008-2012 QMUL.
|
Chris@439
|
8
|
Chris@439
|
9 This program is free software; you can redistribute it and/or
|
Chris@439
|
10 modify it under the terms of the GNU General Public License as
|
Chris@439
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@439
|
12 License, or (at your option) any later version. See the file
|
Chris@439
|
13 COPYING included with this distribution for more information.
|
Chris@439
|
14 */
|
Chris@439
|
15
|
Chris@439
|
16 #include "PluginRDFDescription.h"
|
Chris@439
|
17
|
Chris@439
|
18 #include "PluginRDFIndexer.h"
|
Chris@439
|
19
|
Chris@457
|
20 #include "base/Profiler.h"
|
Chris@457
|
21
|
Chris@439
|
22 #include "plugin/PluginIdentifier.h"
|
Chris@439
|
23
|
Chris@725
|
24 #include <dataquay/BasicStore.h>
|
Chris@725
|
25
|
Chris@439
|
26 #include <iostream>
|
Chris@439
|
27 using std::cerr;
|
Chris@439
|
28 using std::endl;
|
Chris@439
|
29
|
Chris@725
|
30 using Dataquay::Uri;
|
Chris@725
|
31 using Dataquay::Node;
|
Chris@725
|
32 using Dataquay::Nodes;
|
Chris@725
|
33 using Dataquay::Triple;
|
Chris@725
|
34 using Dataquay::Triples;
|
Chris@725
|
35 using Dataquay::BasicStore;
|
Chris@725
|
36
|
Chris@439
|
37 PluginRDFDescription::PluginRDFDescription(QString pluginId) :
|
Chris@439
|
38 m_pluginId(pluginId),
|
Chris@439
|
39 m_haveDescription(false)
|
Chris@439
|
40 {
|
Chris@439
|
41 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
|
Chris@489
|
42 m_pluginUri = indexer->getURIForPluginId(pluginId);
|
Chris@489
|
43 if (m_pluginUri == "") {
|
Chris@439
|
44 cerr << "PluginRDFDescription: WARNING: No RDF description available for plugin ID \""
|
Chris@686
|
45 << pluginId << "\"" << endl;
|
Chris@439
|
46 } else {
|
Chris@489
|
47 // All the data we need should be in our RDF model already:
|
Chris@489
|
48 // if it's not there, we don't know where to find it anyway
|
Chris@489
|
49 if (index()) {
|
Chris@439
|
50 m_haveDescription = true;
|
Chris@439
|
51 }
|
Chris@439
|
52 }
|
Chris@439
|
53 }
|
Chris@439
|
54
|
Chris@439
|
55 PluginRDFDescription::~PluginRDFDescription()
|
Chris@439
|
56 {
|
Chris@439
|
57 }
|
Chris@439
|
58
|
Chris@439
|
59 bool
|
Chris@439
|
60 PluginRDFDescription::haveDescription() const
|
Chris@439
|
61 {
|
Chris@439
|
62 return m_haveDescription;
|
Chris@439
|
63 }
|
Chris@439
|
64
|
Chris@457
|
65 QString
|
Chris@457
|
66 PluginRDFDescription::getPluginName() const
|
Chris@457
|
67 {
|
Chris@457
|
68 return m_pluginName;
|
Chris@457
|
69 }
|
Chris@457
|
70
|
Chris@457
|
71 QString
|
Chris@457
|
72 PluginRDFDescription::getPluginDescription() const
|
Chris@457
|
73 {
|
Chris@457
|
74 return m_pluginDescription;
|
Chris@457
|
75 }
|
Chris@457
|
76
|
Chris@457
|
77 QString
|
Chris@457
|
78 PluginRDFDescription::getPluginMaker() const
|
Chris@457
|
79 {
|
Chris@457
|
80 return m_pluginMaker;
|
Chris@457
|
81 }
|
Chris@457
|
82
|
Chris@462
|
83 QString
|
Chris@462
|
84 PluginRDFDescription::getPluginInfoURL() const
|
Chris@462
|
85 {
|
Chris@462
|
86 return m_pluginInfoURL;
|
Chris@462
|
87 }
|
Chris@462
|
88
|
Chris@457
|
89 QStringList
|
Chris@457
|
90 PluginRDFDescription::getOutputIds() const
|
Chris@457
|
91 {
|
Chris@457
|
92 QStringList ids;
|
Chris@457
|
93 for (OutputDispositionMap::const_iterator i = m_outputDispositions.begin();
|
Chris@457
|
94 i != m_outputDispositions.end(); ++i) {
|
Chris@457
|
95 ids.push_back(i->first);
|
Chris@457
|
96 }
|
Chris@457
|
97 return ids;
|
Chris@457
|
98 }
|
Chris@457
|
99
|
Chris@457
|
100 QString
|
Chris@457
|
101 PluginRDFDescription::getOutputName(QString outputId) const
|
Chris@457
|
102 {
|
Chris@457
|
103 if (m_outputNames.find(outputId) == m_outputNames.end()) {
|
Chris@457
|
104 return "";
|
Chris@457
|
105 }
|
Chris@457
|
106 return m_outputNames.find(outputId)->second;
|
Chris@457
|
107 }
|
Chris@457
|
108
|
Chris@439
|
109 PluginRDFDescription::OutputDisposition
|
Chris@439
|
110 PluginRDFDescription::getOutputDisposition(QString outputId) const
|
Chris@439
|
111 {
|
Chris@439
|
112 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) {
|
Chris@439
|
113 return OutputDispositionUnknown;
|
Chris@439
|
114 }
|
Chris@439
|
115 return m_outputDispositions.find(outputId)->second;
|
Chris@439
|
116 }
|
Chris@439
|
117
|
Chris@439
|
118 QString
|
Chris@439
|
119 PluginRDFDescription::getOutputEventTypeURI(QString outputId) const
|
Chris@439
|
120 {
|
Chris@439
|
121 if (m_outputEventTypeURIMap.find(outputId) ==
|
Chris@439
|
122 m_outputEventTypeURIMap.end()) {
|
Chris@439
|
123 return "";
|
Chris@439
|
124 }
|
Chris@439
|
125 return m_outputEventTypeURIMap.find(outputId)->second;
|
Chris@439
|
126 }
|
Chris@439
|
127
|
Chris@439
|
128 QString
|
Chris@440
|
129 PluginRDFDescription::getOutputFeatureAttributeURI(QString outputId) const
|
Chris@440
|
130 {
|
Chris@440
|
131 if (m_outputFeatureAttributeURIMap.find(outputId) ==
|
Chris@440
|
132 m_outputFeatureAttributeURIMap.end()) {
|
Chris@440
|
133 return "";
|
Chris@440
|
134 }
|
Chris@440
|
135 return m_outputFeatureAttributeURIMap.find(outputId)->second;
|
Chris@440
|
136 }
|
Chris@440
|
137
|
Chris@440
|
138 QString
|
Chris@440
|
139 PluginRDFDescription::getOutputSignalTypeURI(QString outputId) const
|
Chris@440
|
140 {
|
Chris@440
|
141 if (m_outputSignalTypeURIMap.find(outputId) ==
|
Chris@440
|
142 m_outputSignalTypeURIMap.end()) {
|
Chris@440
|
143 return "";
|
Chris@440
|
144 }
|
Chris@440
|
145 return m_outputSignalTypeURIMap.find(outputId)->second;
|
Chris@440
|
146 }
|
Chris@440
|
147
|
Chris@440
|
148 QString
|
Chris@439
|
149 PluginRDFDescription::getOutputUnit(QString outputId) const
|
Chris@439
|
150 {
|
Chris@439
|
151 if (m_outputUnitMap.find(outputId) == m_outputUnitMap.end()) {
|
Chris@439
|
152 return "";
|
Chris@439
|
153 }
|
Chris@439
|
154 return m_outputUnitMap.find(outputId)->second;
|
Chris@439
|
155 }
|
Chris@439
|
156
|
Chris@494
|
157 QString
|
Chris@494
|
158 PluginRDFDescription::getOutputUri(QString outputId) const
|
Chris@494
|
159 {
|
Chris@494
|
160 if (m_outputUriMap.find(outputId) == m_outputUriMap.end()) {
|
Chris@494
|
161 return "";
|
Chris@494
|
162 }
|
Chris@494
|
163 return m_outputUriMap.find(outputId)->second;
|
Chris@494
|
164 }
|
Chris@494
|
165
|
Chris@439
|
166 bool
|
Chris@489
|
167 PluginRDFDescription::index()
|
Chris@439
|
168 {
|
Chris@489
|
169 Profiler profiler("PluginRDFDescription::index");
|
Chris@439
|
170
|
Chris@457
|
171 bool success = true;
|
Chris@489
|
172 if (!indexMetadata()) success = false;
|
Chris@489
|
173 if (!indexOutputs()) success = false;
|
Chris@457
|
174
|
Chris@457
|
175 return success;
|
Chris@457
|
176 }
|
Chris@457
|
177
|
Chris@457
|
178 bool
|
Chris@489
|
179 PluginRDFDescription::indexMetadata()
|
Chris@457
|
180 {
|
Chris@489
|
181 Profiler profiler("PluginRDFDescription::index");
|
Chris@489
|
182
|
Chris@725
|
183 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
|
Chris@725
|
184 const BasicStore *index = indexer->getIndex();
|
Chris@725
|
185 Uri plugin(m_pluginUri);
|
Chris@457
|
186
|
Chris@730
|
187 Node n = index->complete
|
Chris@730
|
188 (Triple(plugin, index->expand("vamp:name"), Node()));
|
Chris@730
|
189
|
Chris@725
|
190 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
191 m_pluginName = n.value;
|
Chris@457
|
192 }
|
Chris@457
|
193
|
Chris@730
|
194 n = index->complete
|
Chris@730
|
195 (Triple(plugin, index->expand("dc:description"), Node()));
|
Chris@730
|
196
|
Chris@725
|
197 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
198 m_pluginDescription = n.value;
|
Chris@457
|
199 }
|
Chris@457
|
200
|
Chris@730
|
201 n = index->complete
|
Chris@730
|
202 (Triple(plugin, index->expand("foaf:maker"), Node()));
|
Chris@730
|
203
|
Chris@725
|
204 if (n.type == Node::URI || n.type == Node::Blank) {
|
Chris@730
|
205 n = index->complete(Triple(n, index->expand("foaf:name"), Node()));
|
Chris@725
|
206 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
207 m_pluginMaker = n.value;
|
Chris@725
|
208 }
|
Chris@457
|
209 }
|
Chris@457
|
210
|
Chris@462
|
211 // If we have a more-information URL for this plugin, then we take
|
Chris@725
|
212 // that. Otherwise, a more-information URL for the plugin library
|
Chris@725
|
213 // would do nicely.
|
Chris@462
|
214
|
Chris@730
|
215 n = index->complete
|
Chris@730
|
216 (Triple(plugin, index->expand("foaf:page"), Node()));
|
Chris@730
|
217
|
Chris@725
|
218 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
219 m_pluginInfoURL = n.value;
|
Chris@725
|
220 }
|
Chris@462
|
221
|
Chris@730
|
222 n = index->complete
|
Chris@730
|
223 (Triple(Node(), index->expand("vamp:available_plugin"), plugin));
|
Chris@730
|
224
|
Chris@725
|
225 if (n.value != "") {
|
Chris@730
|
226 n = index->complete(Triple(n, index->expand("foaf:page"), Node()));
|
Chris@725
|
227 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
228 m_pluginInfoURL = n.value;
|
Chris@462
|
229 }
|
Chris@462
|
230 }
|
Chris@462
|
231
|
Chris@457
|
232 return true;
|
Chris@457
|
233 }
|
Chris@457
|
234
|
Chris@457
|
235 bool
|
Chris@489
|
236 PluginRDFDescription::indexOutputs()
|
Chris@457
|
237 {
|
Chris@457
|
238 Profiler profiler("PluginRDFDescription::indexOutputs");
|
Chris@489
|
239
|
Chris@725
|
240 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
|
Chris@725
|
241 const BasicStore *index = indexer->getIndex();
|
Chris@725
|
242 Uri plugin(m_pluginUri);
|
Chris@457
|
243
|
Chris@730
|
244 Nodes outputs = index->match
|
Chris@730
|
245 (Triple(plugin, index->expand("vamp:output"), Node())).objects();
|
Chris@439
|
246
|
Chris@725
|
247 if (outputs.empty()) {
|
Chris@718
|
248 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <"
|
Chris@686
|
249 << m_pluginUri << ">" << endl;
|
Chris@439
|
250 return false;
|
Chris@439
|
251 }
|
Chris@439
|
252
|
Chris@725
|
253 foreach (Node output, outputs) {
|
Chris@439
|
254
|
Chris@725
|
255 if ((output.type != Node::URI && output.type != Node::Blank) ||
|
Chris@725
|
256 output.value == "") {
|
Chris@725
|
257 cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << output << " of plugin <" << m_pluginUri << ">" << endl;
|
Chris@718
|
258 return false;
|
Chris@718
|
259 }
|
Chris@725
|
260
|
Chris@730
|
261 Node n = index->complete(Triple(output, index->expand("vamp:identifier"), Node()));
|
Chris@725
|
262 if (n.type != Node::Literal || n.value == "") {
|
Chris@725
|
263 cerr << "ERROR: PluginRDFDescription::indexURL: No vamp:identifier for output <" << output << ">" << endl;
|
Chris@718
|
264 return false;
|
Chris@718
|
265 }
|
Chris@725
|
266 QString outputId = n.value;
|
Chris@718
|
267
|
Chris@730
|
268 m_outputUriMap[outputId] = output.value;
|
Chris@730
|
269
|
Chris@730
|
270 n = index->complete(Triple(output, Uri("a"), Node()));
|
Chris@725
|
271 QString outputType;
|
Chris@725
|
272 if (n.type == Node::URI) outputType = n.value;
|
Chris@718
|
273
|
Chris@730
|
274 n = index->complete(Triple(output, index->expand("vamp:unit"), Node()));
|
Chris@725
|
275 QString outputUnit;
|
Chris@725
|
276 if (n.type == Node::Literal) outputUnit = n.value;
|
Chris@718
|
277
|
Chris@439
|
278 if (outputType.contains("DenseOutput")) {
|
Chris@439
|
279 m_outputDispositions[outputId] = OutputDense;
|
Chris@439
|
280 } else if (outputType.contains("SparseOutput")) {
|
Chris@439
|
281 m_outputDispositions[outputId] = OutputSparse;
|
Chris@439
|
282 } else if (outputType.contains("TrackLevelOutput")) {
|
Chris@439
|
283 m_outputDispositions[outputId] = OutputTrackLevel;
|
Chris@457
|
284 } else {
|
Chris@457
|
285 m_outputDispositions[outputId] = OutputDispositionUnknown;
|
Chris@439
|
286 }
|
Chris@730
|
287 cerr << "output " << output << " -> id " << outputId << ", type " << outputType << ", unit "
|
Chris@730
|
288 << outputUnit << ", disposition " << m_outputDispositions[outputId] << endl;
|
Chris@439
|
289
|
Chris@718
|
290 if (outputUnit != "") {
|
Chris@718
|
291 m_outputUnitMap[outputId] = outputUnit;
|
Chris@439
|
292 }
|
Chris@440
|
293
|
Chris@730
|
294 n = index->complete(Triple(output, index->expand("dc:title"), Node()));
|
Chris@725
|
295 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
296 m_outputNames[outputId] = n.value;
|
Chris@457
|
297 }
|
Chris@457
|
298
|
Chris@730
|
299 n = index->complete(Triple(output, index->expand("vamp:computes_event_type"), Node()));
|
Chris@730
|
300 cerr << output << " -> computes_event_type " << n << endl;
|
Chris@725
|
301 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
302 m_outputEventTypeURIMap[outputId] = n.value;
|
Chris@440
|
303 }
|
Chris@440
|
304
|
Chris@730
|
305 n = index->complete(Triple(output, index->expand("vamp:computes_feature"), Node()));
|
Chris@725
|
306 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
307 m_outputFeatureAttributeURIMap[outputId] = n.value;
|
Chris@725
|
308 }
|
Chris@440
|
309
|
Chris@730
|
310 n = index->complete(Triple(output, index->expand("vamp:computes_signal_type"), Node()));
|
Chris@725
|
311 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
312 m_outputSignalTypeURIMap[outputId] = n.value;
|
Chris@440
|
313 }
|
Chris@439
|
314 }
|
Chris@439
|
315
|
Chris@439
|
316 return true;
|
Chris@439
|
317 }
|
Chris@439
|
318
|