comparison rdf/PluginRDFDescription.cpp @ 457:ef14acd6d102

* Add beginnings of capability to search plugins that are not yet installed -- lots more work to do here, though
author Chris Cannam
date Tue, 14 Oct 2008 16:36:35 +0000
parents 5746c559af15
children 2019d89ebcf9
comparison
equal deleted inserted replaced
456:64e64e304a12 457:ef14acd6d102
16 #include "PluginRDFDescription.h" 16 #include "PluginRDFDescription.h"
17 17
18 #include "PluginRDFIndexer.h" 18 #include "PluginRDFIndexer.h"
19 #include "SimpleSPARQLQuery.h" 19 #include "SimpleSPARQLQuery.h"
20 20
21 #include "data/fileio/FileSource.h"
22
23 #include "base/Profiler.h"
24
21 #include "plugin/PluginIdentifier.h" 25 #include "plugin/PluginIdentifier.h"
22 26
23 #include <iostream> 27 #include <iostream>
24 using std::cerr; 28 using std::cerr;
25 using std::endl; 29 using std::endl;
26 30
27 PluginRDFDescription::PluginRDFDescription(QString pluginId) : 31 PluginRDFDescription::PluginRDFDescription(QString pluginId) :
32 m_source(0),
28 m_pluginId(pluginId), 33 m_pluginId(pluginId),
29 m_haveDescription(false) 34 m_haveDescription(false)
30 { 35 {
31 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); 36 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance();
32 QString url = indexer->getDescriptionURLForPluginId(pluginId); 37 QString url = indexer->getDescriptionURLForPluginId(pluginId);
43 } 48 }
44 } 49 }
45 50
46 PluginRDFDescription::~PluginRDFDescription() 51 PluginRDFDescription::~PluginRDFDescription()
47 { 52 {
53 delete m_source;
48 } 54 }
49 55
50 bool 56 bool
51 PluginRDFDescription::haveDescription() const 57 PluginRDFDescription::haveDescription() const
52 { 58 {
53 return m_haveDescription; 59 return m_haveDescription;
54 } 60 }
55 61
62 QString
63 PluginRDFDescription::getPluginName() const
64 {
65 return m_pluginName;
66 }
67
68 QString
69 PluginRDFDescription::getPluginDescription() const
70 {
71 return m_pluginDescription;
72 }
73
74 QString
75 PluginRDFDescription::getPluginMaker() const
76 {
77 return m_pluginMaker;
78 }
79
80 QStringList
81 PluginRDFDescription::getOutputIds() const
82 {
83 QStringList ids;
84 for (OutputDispositionMap::const_iterator i = m_outputDispositions.begin();
85 i != m_outputDispositions.end(); ++i) {
86 ids.push_back(i->first);
87 }
88 return ids;
89 }
90
91 QString
92 PluginRDFDescription::getOutputName(QString outputId) const
93 {
94 if (m_outputNames.find(outputId) == m_outputNames.end()) {
95 return "";
96 }
97 return m_outputNames.find(outputId)->second;
98 }
99
56 PluginRDFDescription::OutputDisposition 100 PluginRDFDescription::OutputDisposition
57 PluginRDFDescription::getOutputDisposition(QString outputId) const 101 PluginRDFDescription::getOutputDisposition(QString outputId) const
58 { 102 {
59 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) { 103 if (m_outputDispositions.find(outputId) == m_outputDispositions.end()) {
60 return OutputDispositionUnknown; 104 return OutputDispositionUnknown;
102 } 146 }
103 147
104 bool 148 bool
105 PluginRDFDescription::indexURL(QString url) 149 PluginRDFDescription::indexURL(QString url)
106 { 150 {
151 Profiler profiler("PluginRDFDescription::indexURL");
152
107 QString type, soname, label; 153 QString type, soname, label;
108 PluginIdentifier::parseIdentifier(m_pluginId, type, soname, label); 154 PluginIdentifier::parseIdentifier(m_pluginId, type, soname, label);
155
156 bool success = true;
157
158 QString local = url;
159
160 if (FileSource::isRemote(url) &&
161 FileSource::canHandleScheme(url)) {
162
163 m_source = new FileSource(url);
164 if (!m_source->isAvailable()) {
165 delete m_source;
166 m_source = 0;
167 return false;
168 }
169 m_source->waitForData();
170 local = QUrl::fromLocalFile(m_source->getLocalFilename()).toString();
171 }
172
173 if (!indexMetadata(local, label)) success = false;
174 if (!indexOutputs(local, label)) success = false;
175
176 return success;
177 }
178
179 bool
180 PluginRDFDescription::indexMetadata(QString url, QString label)
181 {
182 Profiler profiler("PluginRDFDescription::indexMetadata");
183
184 QString queryTemplate =
185 QString(
186 " PREFIX vamp: <http://purl.org/ontology/vamp/> "
187 " PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
188 " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
189 " SELECT ?%4 FROM <%1> "
190 " WHERE { "
191 " ?plugin a vamp:Plugin ; "
192 " vamp:identifier \"%2\" ; "
193 " %3 ?%4 . "
194 " }")
195 .arg(url)
196 .arg(label);
197
198 SimpleSPARQLQuery::Value v;
199
200 v = SimpleSPARQLQuery::singleResultQuery
201 (queryTemplate.arg("vamp:name").arg("name"), "name");
202
203 if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") {
204 m_pluginName = v.value;
205 }
206
207 v = SimpleSPARQLQuery::singleResultQuery
208 (queryTemplate.arg("dc:description").arg("description"), "description");
209
210 if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") {
211 m_pluginDescription = v.value;
212 }
213
214 v = SimpleSPARQLQuery::singleResultQuery
215 (QString(
216 " PREFIX vamp: <http://purl.org/ontology/vamp/> "
217 " PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
218 " SELECT ?name FROM <%1> "
219 " WHERE { "
220 " ?plugin a vamp:Plugin ; "
221 " vamp:identifier \"%2\" ; "
222 " foaf:maker ?maker . "
223 " ?maker foaf:name ?name . "
224 " }")
225 .arg(url)
226 .arg(label), "name");
227
228 if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") {
229 m_pluginMaker = v.value;
230 }
231
232 return true;
233 }
234
235 bool
236 PluginRDFDescription::indexOutputs(QString url, QString label)
237 {
238 Profiler profiler("PluginRDFDescription::indexOutputs");
109 239
110 SimpleSPARQLQuery query 240 SimpleSPARQLQuery query
111 (QString 241 (QString
112 ( 242 (
113 " PREFIX vamp: <http://purl.org/ontology/vamp/> " 243 " PREFIX vamp: <http://purl.org/ontology/vamp/> "
164 m_outputDispositions[outputId] = OutputDense; 294 m_outputDispositions[outputId] = OutputDense;
165 } else if (outputType.contains("SparseOutput")) { 295 } else if (outputType.contains("SparseOutput")) {
166 m_outputDispositions[outputId] = OutputSparse; 296 m_outputDispositions[outputId] = OutputSparse;
167 } else if (outputType.contains("TrackLevelOutput")) { 297 } else if (outputType.contains("TrackLevelOutput")) {
168 m_outputDispositions[outputId] = OutputTrackLevel; 298 m_outputDispositions[outputId] = OutputTrackLevel;
299 } else {
300 m_outputDispositions[outputId] = OutputDispositionUnknown;
169 } 301 }
170 302
171 if (results[i]["unit"].type == SimpleSPARQLQuery::LiteralValue) { 303 if (results[i]["unit"].type == SimpleSPARQLQuery::LiteralValue) {
172 304
173 QString unit = results[i]["unit"].value; 305 QString unit = results[i]["unit"].value;
175 if (unit != "") { 307 if (unit != "") {
176 m_outputUnitMap[outputId] = unit; 308 m_outputUnitMap[outputId] = unit;
177 } 309 }
178 } 310 }
179 311
312 SimpleSPARQLQuery::Value v;
313
314 v = SimpleSPARQLQuery::singleResultQuery
315 (QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> "
316 " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
317 " SELECT ?title FROM <%1> "
318 " WHERE { <%2> dc:title ?title } ")
319 .arg(url).arg(outputUri), "title");
320
321 if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") {
322 m_outputNames[outputId] = v.value;
323 }
324
180 QString queryTemplate = 325 QString queryTemplate =
181 QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " 326 QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> "
182 " SELECT ?%3 FROM <%1> " 327 " SELECT ?%3 FROM <%1> "
183 " WHERE { <%2> vamp:computes_%3 ?%3 } ") 328 " WHERE { <%2> vamp:computes_%3 ?%3 } ")
184 .arg(url).arg(outputUri); 329 .arg(url).arg(outputUri);
185 330
186 SimpleSPARQLQuery::Value v;
187
188 v = SimpleSPARQLQuery::singleResultQuery 331 v = SimpleSPARQLQuery::singleResultQuery
189 (queryTemplate.arg("event_type"), "event_type"); 332 (queryTemplate.arg("event_type"), "event_type");
190 333
191 if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { 334 if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") {
192 m_outputEventTypeURIMap[outputId] = v.value; 335 m_outputEventTypeURIMap[outputId] = v.value;