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