svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008-2012 QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "PluginRDFDescription.h" 00017 00018 #include "PluginRDFIndexer.h" 00019 00020 #include "base/Profiler.h" 00021 00022 #include "plugin/PluginIdentifier.h" 00023 00024 #include <dataquay/BasicStore.h> 00025 00026 #include <iostream> 00027 00028 using Dataquay::Uri; 00029 using Dataquay::Node; 00030 using Dataquay::Nodes; 00031 using Dataquay::Triple; 00032 using Dataquay::Triples; 00033 using Dataquay::BasicStore; 00034 00035 PluginRDFDescription::PluginRDFDescription(QString pluginId) : 00036 m_pluginId(pluginId), 00037 m_haveDescription(false) 00038 { 00039 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); 00040 m_pluginUri = indexer->getURIForPluginId(pluginId); 00041 if (m_pluginUri == "") { 00042 cerr << "PluginRDFDescription: WARNING: No RDF description available for plugin ID \"" 00043 << pluginId << "\"" << endl; 00044 } else { 00045 // All the data we need should be in our RDF model already: 00046 // if it's not there, we don't know where to find it anyway 00047 if (index()) { 00048 m_haveDescription = true; 00049 } 00050 } 00051 } 00052 00053 PluginRDFDescription::~PluginRDFDescription() 00054 { 00055 } 00056 00057 bool 00058 PluginRDFDescription::haveDescription() const 00059 { 00060 return m_haveDescription; 00061 } 00062 00063 QString 00064 PluginRDFDescription::getPluginName() const 00065 { 00066 return m_pluginName; 00067 } 00068 00069 QString 00070 PluginRDFDescription::getPluginDescription() const 00071 { 00072 return m_pluginDescription; 00073 } 00074 00075 QString 00076 PluginRDFDescription::getPluginMaker() const 00077 { 00078 return m_pluginMaker; 00079 } 00080 00081 QString 00082 PluginRDFDescription::getPluginInfoURL() const 00083 { 00084 return m_pluginInfoURL; 00085 } 00086 00087 QStringList 00088 PluginRDFDescription::getOutputIds() const 00089 { 00090 QStringList ids; 00091 for (OutputDispositionMap::const_iterator i = m_outputDispositions.begin(); 00092 i != m_outputDispositions.end(); ++i) { 00093 ids.push_back(i->first); 00094 } 00095 return ids; 00096 } 00097 00098 QString 00099 PluginRDFDescription::getOutputName(QString outputId) const 00100 { 00101 if (m_outputNames.find(outputId) == m_outputNames.end()) { 00102 return ""; 00103 } 00104 return m_outputNames.find(outputId)->second; 00105 } 00106 00107 PluginRDFDescription::OutputDisposition 00108 PluginRDFDescription::getOutputDisposition(QString outputId) const 00109 { 00110 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) { 00111 return OutputDispositionUnknown; 00112 } 00113 return m_outputDispositions.find(outputId)->second; 00114 } 00115 00116 QString 00117 PluginRDFDescription::getOutputEventTypeURI(QString outputId) const 00118 { 00119 if (m_outputEventTypeURIMap.find(outputId) == 00120 m_outputEventTypeURIMap.end()) { 00121 return ""; 00122 } 00123 return m_outputEventTypeURIMap.find(outputId)->second; 00124 } 00125 00126 QString 00127 PluginRDFDescription::getOutputFeatureAttributeURI(QString outputId) const 00128 { 00129 if (m_outputFeatureAttributeURIMap.find(outputId) == 00130 m_outputFeatureAttributeURIMap.end()) { 00131 return ""; 00132 } 00133 return m_outputFeatureAttributeURIMap.find(outputId)->second; 00134 } 00135 00136 QString 00137 PluginRDFDescription::getOutputSignalTypeURI(QString outputId) const 00138 { 00139 if (m_outputSignalTypeURIMap.find(outputId) == 00140 m_outputSignalTypeURIMap.end()) { 00141 return ""; 00142 } 00143 return m_outputSignalTypeURIMap.find(outputId)->second; 00144 } 00145 00146 QString 00147 PluginRDFDescription::getOutputUnit(QString outputId) const 00148 { 00149 if (m_outputUnitMap.find(outputId) == m_outputUnitMap.end()) { 00150 return ""; 00151 } 00152 return m_outputUnitMap.find(outputId)->second; 00153 } 00154 00155 QString 00156 PluginRDFDescription::getOutputUri(QString outputId) const 00157 { 00158 if (m_outputUriMap.find(outputId) == m_outputUriMap.end()) { 00159 return ""; 00160 } 00161 return m_outputUriMap.find(outputId)->second; 00162 } 00163 00164 bool 00165 PluginRDFDescription::index() 00166 { 00167 Profiler profiler("PluginRDFDescription::index"); 00168 00169 bool success = true; 00170 if (!indexMetadata()) success = false; 00171 if (!indexOutputs()) success = false; 00172 00173 return success; 00174 } 00175 00176 bool 00177 PluginRDFDescription::indexMetadata() 00178 { 00179 Profiler profiler("PluginRDFDescription::index"); 00180 00181 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); 00182 const BasicStore *index = indexer->getIndex(); 00183 Uri plugin(m_pluginUri); 00184 00185 Node n = index->complete 00186 (Triple(plugin, index->expand("vamp:name"), Node())); 00187 00188 if (n.type == Node::Literal && n.value != "") { 00189 m_pluginName = n.value; 00190 } 00191 00192 n = index->complete 00193 (Triple(plugin, index->expand("dc:description"), Node())); 00194 00195 if (n.type == Node::Literal && n.value != "") { 00196 m_pluginDescription = n.value; 00197 } 00198 00199 n = index->complete 00200 (Triple(plugin, index->expand("foaf:maker"), Node())); 00201 00202 if (n.type == Node::URI || n.type == Node::Blank) { 00203 n = index->complete(Triple(n, index->expand("foaf:name"), Node())); 00204 if (n.type == Node::Literal && n.value != "") { 00205 m_pluginMaker = n.value; 00206 } 00207 } 00208 00209 // If we have a more-information URL for this plugin, then we take 00210 // that. Otherwise, a more-information URL for the plugin library 00211 // would do nicely. 00212 00213 n = index->complete 00214 (Triple(plugin, index->expand("foaf:page"), Node())); 00215 00216 if (n.type == Node::URI && n.value != "") { 00217 m_pluginInfoURL = n.value; 00218 } 00219 00220 n = index->complete 00221 (Triple(Node(), index->expand("vamp:available_plugin"), plugin)); 00222 00223 if (n.value != "") { 00224 n = index->complete(Triple(n, index->expand("foaf:page"), Node())); 00225 if (n.type == Node::URI && n.value != "") { 00226 m_pluginInfoURL = n.value; 00227 } 00228 } 00229 00230 return true; 00231 } 00232 00233 bool 00234 PluginRDFDescription::indexOutputs() 00235 { 00236 Profiler profiler("PluginRDFDescription::indexOutputs"); 00237 00238 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); 00239 const BasicStore *index = indexer->getIndex(); 00240 Uri plugin(m_pluginUri); 00241 00242 Nodes outputs = index->match 00243 (Triple(plugin, index->expand("vamp:output"), Node())).objects(); 00244 00245 if (outputs.empty()) { 00246 cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <" 00247 << m_pluginUri << ">" << endl; 00248 return false; 00249 } 00250 00251 foreach (Node output, outputs) { 00252 00253 if ((output.type != Node::URI && output.type != Node::Blank) || 00254 output.value == "") { 00255 cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << output << " of plugin <" << m_pluginUri << ">" << endl; 00256 return false; 00257 } 00258 00259 Node n = index->complete(Triple(output, index->expand("vamp:identifier"), Node())); 00260 if (n.type != Node::Literal || n.value == "") { 00261 cerr << "ERROR: PluginRDFDescription::indexURL: No vamp:identifier for output <" << output << ">" << endl; 00262 return false; 00263 } 00264 QString outputId = n.value; 00265 00266 m_outputUriMap[outputId] = output.value; 00267 00268 n = index->complete(Triple(output, Uri("a"), Node())); 00269 QString outputType; 00270 if (n.type == Node::URI) outputType = n.value; 00271 00272 n = index->complete(Triple(output, index->expand("vamp:unit"), Node())); 00273 QString outputUnit; 00274 if (n.type == Node::Literal) outputUnit = n.value; 00275 00276 if (outputType.contains("DenseOutput")) { 00277 m_outputDispositions[outputId] = OutputDense; 00278 } else if (outputType.contains("SparseOutput")) { 00279 m_outputDispositions[outputId] = OutputSparse; 00280 } else if (outputType.contains("TrackLevelOutput")) { 00281 m_outputDispositions[outputId] = OutputTrackLevel; 00282 } else { 00283 m_outputDispositions[outputId] = OutputDispositionUnknown; 00284 } 00285 // cerr << "output " << output << " -> id " << outputId << ", type " << outputType << ", unit " 00286 // << outputUnit << ", disposition " << m_outputDispositions[outputId] << endl; 00287 00288 if (outputUnit != "") { 00289 m_outputUnitMap[outputId] = outputUnit; 00290 } 00291 00292 n = index->complete(Triple(output, index->expand("dc:title"), Node())); 00293 if (n.type == Node::Literal && n.value != "") { 00294 m_outputNames[outputId] = n.value; 00295 } 00296 00297 n = index->complete(Triple(output, index->expand("vamp:computes_event_type"), Node())); 00298 // cerr << output << " -> computes_event_type " << n << endl; 00299 if (n.type == Node::URI && n.value != "") { 00300 m_outputEventTypeURIMap[outputId] = n.value; 00301 } 00302 00303 n = index->complete(Triple(output, index->expand("vamp:computes_feature"), Node())); 00304 if (n.type == Node::URI && n.value != "") { 00305 m_outputFeatureAttributeURIMap[outputId] = n.value; 00306 } 00307 00308 n = index->complete(Triple(output, index->expand("vamp:computes_signal_type"), Node())); 00309 if (n.type == Node::URI && n.value != "") { 00310 m_outputSignalTypeURIMap[outputId] = n.value; 00311 } 00312 } 00313 00314 return true; 00315 } 00316