annotate rdf/PluginRDFDescription.cpp @ 1643:7a23dfe65d66 single-point

Update NoteModel to use EventSeries. This is incomplete and won't provide enough to update svgui for it yet; must also refactor to avoid duplication of nasty APIs when updating the rest of the models
author Chris Cannam
date Wed, 13 Mar 2019 14:50:10 +0000
parents e802e550a1f2
children 3ec563af0a4f
rev   line source
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
Chris@725 28 using Dataquay::Uri;
Chris@725 29 using Dataquay::Node;
Chris@725 30 using Dataquay::Nodes;
Chris@725 31 using Dataquay::Triple;
Chris@725 32 using Dataquay::Triples;
Chris@725 33 using Dataquay::BasicStore;
Chris@725 34
Chris@439 35 PluginRDFDescription::PluginRDFDescription(QString pluginId) :
Chris@439 36 m_pluginId(pluginId),
Chris@439 37 m_haveDescription(false)
Chris@439 38 {
Chris@439 39 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
Chris@489 40 m_pluginUri = indexer->getURIForPluginId(pluginId);
Chris@489 41 if (m_pluginUri == "") {
Chris@439 42 cerr << "PluginRDFDescription: WARNING: No RDF description available for plugin ID \""
Chris@686 43 << pluginId << "\"" << endl;
Chris@439 44 } else {
Chris@489 45 // All the data we need should be in our RDF model already:
Chris@489 46 // if it's not there, we don't know where to find it anyway
Chris@489 47 if (index()) {
Chris@439 48 m_haveDescription = true;
Chris@439 49 }
Chris@439 50 }
Chris@439 51 }
Chris@439 52
Chris@439 53 PluginRDFDescription::~PluginRDFDescription()
Chris@439 54 {
Chris@439 55 }
Chris@439 56
Chris@439 57 bool
Chris@439 58 PluginRDFDescription::haveDescription() const
Chris@439 59 {
Chris@439 60 return m_haveDescription;
Chris@439 61 }
Chris@439 62
Chris@457 63 QString
Chris@457 64 PluginRDFDescription::getPluginName() const
Chris@457 65 {
Chris@457 66 return m_pluginName;
Chris@457 67 }
Chris@457 68
Chris@457 69 QString
Chris@457 70 PluginRDFDescription::getPluginDescription() const
Chris@457 71 {
Chris@457 72 return m_pluginDescription;
Chris@457 73 }
Chris@457 74
Chris@457 75 QString
Chris@457 76 PluginRDFDescription::getPluginMaker() const
Chris@457 77 {
Chris@457 78 return m_pluginMaker;
Chris@457 79 }
Chris@457 80
Chris@462 81 QString
Chris@462 82 PluginRDFDescription::getPluginInfoURL() const
Chris@462 83 {
Chris@462 84 return m_pluginInfoURL;
Chris@462 85 }
Chris@462 86
Chris@457 87 QStringList
Chris@457 88 PluginRDFDescription::getOutputIds() const
Chris@457 89 {
Chris@457 90 QStringList ids;
Chris@457 91 for (OutputDispositionMap::const_iterator i = m_outputDispositions.begin();
Chris@457 92 i != m_outputDispositions.end(); ++i) {
Chris@457 93 ids.push_back(i->first);
Chris@457 94 }
Chris@457 95 return ids;
Chris@457 96 }
Chris@457 97
Chris@457 98 QString
Chris@457 99 PluginRDFDescription::getOutputName(QString outputId) const
Chris@457 100 {
Chris@457 101 if (m_outputNames.find(outputId) == m_outputNames.end()) {
Chris@457 102 return "";
Chris@457 103 }
Chris@457 104 return m_outputNames.find(outputId)->second;
Chris@457 105 }
Chris@457 106
Chris@439 107 PluginRDFDescription::OutputDisposition
Chris@439 108 PluginRDFDescription::getOutputDisposition(QString outputId) const
Chris@439 109 {
Chris@439 110 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) {
Chris@439 111 return OutputDispositionUnknown;
Chris@439 112 }
Chris@439 113 return m_outputDispositions.find(outputId)->second;
Chris@439 114 }
Chris@439 115
Chris@439 116 QString
Chris@439 117 PluginRDFDescription::getOutputEventTypeURI(QString outputId) const
Chris@439 118 {
Chris@439 119 if (m_outputEventTypeURIMap.find(outputId) ==
Chris@439 120 m_outputEventTypeURIMap.end()) {
Chris@439 121 return "";
Chris@439 122 }
Chris@439 123 return m_outputEventTypeURIMap.find(outputId)->second;
Chris@439 124 }
Chris@439 125
Chris@439 126 QString
Chris@440 127 PluginRDFDescription::getOutputFeatureAttributeURI(QString outputId) const
Chris@440 128 {
Chris@440 129 if (m_outputFeatureAttributeURIMap.find(outputId) ==
Chris@440 130 m_outputFeatureAttributeURIMap.end()) {
Chris@440 131 return "";
Chris@440 132 }
Chris@440 133 return m_outputFeatureAttributeURIMap.find(outputId)->second;
Chris@440 134 }
Chris@440 135
Chris@440 136 QString
Chris@440 137 PluginRDFDescription::getOutputSignalTypeURI(QString outputId) const
Chris@440 138 {
Chris@440 139 if (m_outputSignalTypeURIMap.find(outputId) ==
Chris@440 140 m_outputSignalTypeURIMap.end()) {
Chris@440 141 return "";
Chris@440 142 }
Chris@440 143 return m_outputSignalTypeURIMap.find(outputId)->second;
Chris@440 144 }
Chris@440 145
Chris@440 146 QString
Chris@439 147 PluginRDFDescription::getOutputUnit(QString outputId) const
Chris@439 148 {
Chris@439 149 if (m_outputUnitMap.find(outputId) == m_outputUnitMap.end()) {
Chris@439 150 return "";
Chris@439 151 }
Chris@439 152 return m_outputUnitMap.find(outputId)->second;
Chris@439 153 }
Chris@439 154
Chris@494 155 QString
Chris@494 156 PluginRDFDescription::getOutputUri(QString outputId) const
Chris@494 157 {
Chris@494 158 if (m_outputUriMap.find(outputId) == m_outputUriMap.end()) {
Chris@494 159 return "";
Chris@494 160 }
Chris@494 161 return m_outputUriMap.find(outputId)->second;
Chris@494 162 }
Chris@494 163
Chris@439 164 bool
Chris@489 165 PluginRDFDescription::index()
Chris@439 166 {
Chris@489 167 Profiler profiler("PluginRDFDescription::index");
Chris@439 168
Chris@457 169 bool success = true;
Chris@489 170 if (!indexMetadata()) success = false;
Chris@489 171 if (!indexOutputs()) success = false;
Chris@457 172
Chris@457 173 return success;
Chris@457 174 }
Chris@457 175
Chris@457 176 bool
Chris@489 177 PluginRDFDescription::indexMetadata()
Chris@457 178 {
Chris@489 179 Profiler profiler("PluginRDFDescription::index");
Chris@489 180
Chris@725 181 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
Chris@725 182 const BasicStore *index = indexer->getIndex();
Chris@725 183 Uri plugin(m_pluginUri);
Chris@457 184
Chris@730 185 Node n = index->complete
Chris@730 186 (Triple(plugin, index->expand("vamp:name"), Node()));
Chris@730 187
Chris@725 188 if (n.type == Node::Literal && n.value != "") {
Chris@725 189 m_pluginName = n.value;
Chris@457 190 }
Chris@457 191
Chris@730 192 n = index->complete
Chris@730 193 (Triple(plugin, index->expand("dc:description"), Node()));
Chris@730 194
Chris@725 195 if (n.type == Node::Literal && n.value != "") {
Chris@725 196 m_pluginDescription = n.value;
Chris@457 197 }
Chris@457 198
Chris@730 199 n = index->complete
Chris@730 200 (Triple(plugin, index->expand("foaf:maker"), Node()));
Chris@730 201
Chris@725 202 if (n.type == Node::URI || n.type == Node::Blank) {
Chris@730 203 n = index->complete(Triple(n, index->expand("foaf:name"), Node()));
Chris@725 204 if (n.type == Node::Literal && n.value != "") {
Chris@725 205 m_pluginMaker = n.value;
Chris@725 206 }
Chris@457 207 }
Chris@457 208
Chris@462 209 // If we have a more-information URL for this plugin, then we take
Chris@725 210 // that. Otherwise, a more-information URL for the plugin library
Chris@725 211 // would do nicely.
Chris@462 212
Chris@730 213 n = index->complete
Chris@730 214 (Triple(plugin, index->expand("foaf:page"), Node()));
Chris@730 215
Chris@725 216 if (n.type == Node::URI && n.value != "") {
Chris@725 217 m_pluginInfoURL = n.value;
Chris@725 218 }
Chris@462 219
Chris@730 220 n = index->complete
Chris@730 221 (Triple(Node(), index->expand("vamp:available_plugin"), plugin));
Chris@730 222
Chris@725 223 if (n.value != "") {
Chris@730 224 n = index->complete(Triple(n, index->expand("foaf:page"), Node()));
Chris@725 225 if (n.type == Node::URI && n.value != "") {
Chris@725 226 m_pluginInfoURL = n.value;
Chris@462 227 }
Chris@462 228 }
Chris@462 229
Chris@457 230 return true;
Chris@457 231 }
Chris@457 232
Chris@457 233 bool
Chris@489 234 PluginRDFDescription::indexOutputs()
Chris@457 235 {
Chris@457 236 Profiler profiler("PluginRDFDescription::indexOutputs");
Chris@489 237
Chris@725 238 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
Chris@725 239 const BasicStore *index = indexer->getIndex();
Chris@725 240 Uri plugin(m_pluginUri);
Chris@457 241
Chris@730 242 Nodes outputs = index->match
Chris@730 243 (Triple(plugin, index->expand("vamp:output"), Node())).objects();
Chris@439 244
Chris@725 245 if (outputs.empty()) {
Chris@718 246 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <"
Chris@686 247 << m_pluginUri << ">" << endl;
Chris@439 248 return false;
Chris@439 249 }
Chris@439 250
Chris@725 251 foreach (Node output, outputs) {
Chris@439 252
Chris@725 253 if ((output.type != Node::URI && output.type != Node::Blank) ||
Chris@725 254 output.value == "") {
Chris@725 255 cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << output << " of plugin <" << m_pluginUri << ">" << endl;
Chris@718 256 return false;
Chris@718 257 }
Chris@725 258
Chris@730 259 Node n = index->complete(Triple(output, index->expand("vamp:identifier"), Node()));
Chris@725 260 if (n.type != Node::Literal || n.value == "") {
Chris@725 261 cerr << "ERROR: PluginRDFDescription::indexURL: No vamp:identifier for output <" << output << ">" << endl;
Chris@718 262 return false;
Chris@718 263 }
Chris@725 264 QString outputId = n.value;
Chris@718 265
Chris@730 266 m_outputUriMap[outputId] = output.value;
Chris@730 267
Chris@730 268 n = index->complete(Triple(output, Uri("a"), Node()));
Chris@725 269 QString outputType;
Chris@725 270 if (n.type == Node::URI) outputType = n.value;
Chris@718 271
Chris@730 272 n = index->complete(Triple(output, index->expand("vamp:unit"), Node()));
Chris@725 273 QString outputUnit;
Chris@725 274 if (n.type == Node::Literal) outputUnit = n.value;
Chris@718 275
Chris@439 276 if (outputType.contains("DenseOutput")) {
Chris@439 277 m_outputDispositions[outputId] = OutputDense;
Chris@439 278 } else if (outputType.contains("SparseOutput")) {
Chris@439 279 m_outputDispositions[outputId] = OutputSparse;
Chris@439 280 } else if (outputType.contains("TrackLevelOutput")) {
Chris@439 281 m_outputDispositions[outputId] = OutputTrackLevel;
Chris@457 282 } else {
Chris@457 283 m_outputDispositions[outputId] = OutputDispositionUnknown;
Chris@439 284 }
Chris@732 285 // cerr << "output " << output << " -> id " << outputId << ", type " << outputType << ", unit "
Chris@732 286 // << outputUnit << ", disposition " << m_outputDispositions[outputId] << endl;
Chris@439 287
Chris@718 288 if (outputUnit != "") {
Chris@718 289 m_outputUnitMap[outputId] = outputUnit;
Chris@439 290 }
Chris@440 291
Chris@730 292 n = index->complete(Triple(output, index->expand("dc:title"), Node()));
Chris@725 293 if (n.type == Node::Literal && n.value != "") {
Chris@725 294 m_outputNames[outputId] = n.value;
Chris@457 295 }
Chris@457 296
Chris@730 297 n = index->complete(Triple(output, index->expand("vamp:computes_event_type"), Node()));
Chris@732 298 // cerr << output << " -> computes_event_type " << n << endl;
Chris@725 299 if (n.type == Node::URI && n.value != "") {
Chris@725 300 m_outputEventTypeURIMap[outputId] = n.value;
Chris@440 301 }
Chris@440 302
Chris@730 303 n = index->complete(Triple(output, index->expand("vamp:computes_feature"), Node()));
Chris@725 304 if (n.type == Node::URI && n.value != "") {
Chris@725 305 m_outputFeatureAttributeURIMap[outputId] = n.value;
Chris@725 306 }
Chris@440 307
Chris@730 308 n = index->complete(Triple(output, index->expand("vamp:computes_signal_type"), Node()));
Chris@725 309 if (n.type == Node::URI && n.value != "") {
Chris@725 310 m_outputSignalTypeURIMap[outputId] = n.value;
Chris@440 311 }
Chris@439 312 }
Chris@439 313
Chris@439 314 return true;
Chris@439 315 }
Chris@439 316