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@439
|
7 This file copyright 2008 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@725
|
187 Node n = index->matchFirst(Triple(plugin, "vamp:name", Node())).c;
|
Chris@725
|
188 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
189 m_pluginName = n.value;
|
Chris@457
|
190 }
|
Chris@457
|
191
|
Chris@725
|
192 n = index->matchFirst(Triple(plugin, "dc:description", Node())).c;
|
Chris@725
|
193 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
194 m_pluginDescription = n.value;
|
Chris@457
|
195 }
|
Chris@457
|
196
|
Chris@725
|
197 n = index->matchFirst(Triple(plugin, "foaf:maker", Node())).c;
|
Chris@725
|
198 if (n.type == Node::URI || n.type == Node::Blank) {
|
Chris@725
|
199 n = index->matchFirst(Triple(n, "foaf:name", Node())).c;
|
Chris@725
|
200 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
201 m_pluginMaker = n.value;
|
Chris@725
|
202 }
|
Chris@457
|
203 }
|
Chris@457
|
204
|
Chris@462
|
205 // If we have a more-information URL for this plugin, then we take
|
Chris@725
|
206 // that. Otherwise, a more-information URL for the plugin library
|
Chris@725
|
207 // would do nicely.
|
Chris@462
|
208
|
Chris@725
|
209 n = index->matchFirst(Triple(plugin, "foaf:page", Node())).c;
|
Chris@725
|
210 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
211 m_pluginInfoURL = n.value;
|
Chris@725
|
212 }
|
Chris@462
|
213
|
Chris@725
|
214 n = index->matchFirst(Triple(Node(), "vamp:available_plugin", plugin)).a;
|
Chris@725
|
215 if (n.value != "") {
|
Chris@725
|
216 n = index->matchFirst(Triple(n, "foaf:page", Node())).c;
|
Chris@725
|
217 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
218 m_pluginInfoURL = n.value;
|
Chris@462
|
219 }
|
Chris@462
|
220 }
|
Chris@462
|
221
|
Chris@457
|
222 return true;
|
Chris@457
|
223 }
|
Chris@457
|
224
|
Chris@457
|
225 bool
|
Chris@489
|
226 PluginRDFDescription::indexOutputs()
|
Chris@457
|
227 {
|
Chris@457
|
228 Profiler profiler("PluginRDFDescription::indexOutputs");
|
Chris@489
|
229
|
Chris@725
|
230 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
|
Chris@725
|
231 const BasicStore *index = indexer->getIndex();
|
Chris@725
|
232 Uri plugin(m_pluginUri);
|
Chris@457
|
233
|
Chris@725
|
234 Nodes outputs = index->match(Triple(plugin, "vamp:output", Node())).a();
|
Chris@439
|
235
|
Chris@725
|
236 if (outputs.empty()) {
|
Chris@718
|
237 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <"
|
Chris@686
|
238 << m_pluginUri << ">" << endl;
|
Chris@439
|
239 return false;
|
Chris@439
|
240 }
|
Chris@439
|
241
|
Chris@725
|
242 foreach (Node output, outputs) {
|
Chris@439
|
243
|
Chris@725
|
244 if ((output.type != Node::URI && output.type != Node::Blank) ||
|
Chris@725
|
245 output.value == "") {
|
Chris@725
|
246 cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << output << " of plugin <" << m_pluginUri << ">" << endl;
|
Chris@718
|
247 return false;
|
Chris@718
|
248 }
|
Chris@725
|
249
|
Chris@725
|
250 Node n = index->matchFirst(Triple(output, "vamp:identifier", Node())).c;
|
Chris@725
|
251 if (n.type != Node::Literal || n.value == "") {
|
Chris@725
|
252 cerr << "ERROR: PluginRDFDescription::indexURL: No vamp:identifier for output <" << output << ">" << endl;
|
Chris@718
|
253 return false;
|
Chris@718
|
254 }
|
Chris@725
|
255 QString outputId = n.value;
|
Chris@718
|
256
|
Chris@725
|
257 n = index->matchFirst(Triple(output, "a", Node())).c;
|
Chris@725
|
258 QString outputType;
|
Chris@725
|
259 if (n.type == Node::URI) outputType = n.value;
|
Chris@718
|
260
|
Chris@725
|
261 n = index->matchFirst(Triple(output, "vamp:unit", Node())).c;
|
Chris@725
|
262 QString outputUnit;
|
Chris@725
|
263 if (n.type == Node::Literal) outputUnit = n.value;
|
Chris@718
|
264
|
Chris@725
|
265 m_outputUriMap[outputId] = output.value;
|
Chris@494
|
266
|
Chris@439
|
267 if (outputType.contains("DenseOutput")) {
|
Chris@439
|
268 m_outputDispositions[outputId] = OutputDense;
|
Chris@439
|
269 } else if (outputType.contains("SparseOutput")) {
|
Chris@439
|
270 m_outputDispositions[outputId] = OutputSparse;
|
Chris@439
|
271 } else if (outputType.contains("TrackLevelOutput")) {
|
Chris@439
|
272 m_outputDispositions[outputId] = OutputTrackLevel;
|
Chris@457
|
273 } else {
|
Chris@457
|
274 m_outputDispositions[outputId] = OutputDispositionUnknown;
|
Chris@439
|
275 }
|
Chris@439
|
276
|
Chris@718
|
277 if (outputUnit != "") {
|
Chris@718
|
278 m_outputUnitMap[outputId] = outputUnit;
|
Chris@439
|
279 }
|
Chris@440
|
280
|
Chris@725
|
281 n = index->matchFirst(Triple(output, "dc:title", Node())).c;
|
Chris@725
|
282 if (n.type == Node::Literal && n.value != "") {
|
Chris@725
|
283 m_outputNames[outputId] = n.value;
|
Chris@457
|
284 }
|
Chris@457
|
285
|
Chris@725
|
286 n = index->matchFirst(Triple(output, "vamp:computes_event_type", Node())).c;
|
Chris@725
|
287 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
288 m_outputEventTypeURIMap[outputId] = n.value;
|
Chris@440
|
289 }
|
Chris@440
|
290
|
Chris@725
|
291 n = index->matchFirst(Triple(output, "vamp:computes_feature", Node())).c;
|
Chris@725
|
292 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
293 m_outputFeatureAttributeURIMap[outputId] = n.value;
|
Chris@725
|
294 }
|
Chris@440
|
295
|
Chris@725
|
296 n = index->matchFirst(Triple(output, "vamp:computes_signal_type", Node())).c;
|
Chris@725
|
297 if (n.type == Node::URI && n.value != "") {
|
Chris@725
|
298 m_outputSignalTypeURIMap[outputId] = n.value;
|
Chris@440
|
299 }
|
Chris@439
|
300 }
|
Chris@439
|
301
|
Chris@439
|
302 return true;
|
Chris@439
|
303 }
|
Chris@439
|
304
|