comparison rdf/RDFImporter.cpp @ 493:3931711b5671

* RDF importer: add model titles where possible * RDF transform factory: report whether something appears to be RDF or not (so we can avoid trying to load it as something else if the RDF query fails)
author Chris Cannam
date Tue, 25 Nov 2008 13:43:56 +0000
parents 23945cdd7161
children b71116d3c180
comparison
equal deleted inserted replaced
492:23945cdd7161 493:3931711b5671
57 int m_sampleRate; 57 int m_sampleRate;
58 58
59 void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *); 59 void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *);
60 void getDataModelsDense(std::vector<Model *> &, ProgressReporter *); 60 void getDataModelsDense(std::vector<Model *> &, ProgressReporter *);
61 61
62 void getDenseModelTitle(Model *, QString, QString);
63
62 void getDenseFeatureProperties(QString featureUri, 64 void getDenseFeatureProperties(QString featureUri,
63 int &sampleRate, int &windowLength, 65 int &sampleRate, int &windowLength,
64 int &hopSize, int &width, int &height); 66 int &hopSize, int &width, int &height);
65 67
66 68
182 QString 184 QString
183 ( 185 (
184 " PREFIX mo: <http://purl.org/ontology/mo/>" 186 " PREFIX mo: <http://purl.org/ontology/mo/>"
185 " PREFIX af: <http://purl.org/ontology/af/>" 187 " PREFIX af: <http://purl.org/ontology/af/>"
186 188
187 " SELECT ?feature ?signal_source ?feature_signal_type ?value " 189 " SELECT ?feature ?feature_signal_type ?value "
188 " FROM <%1> " 190 " FROM <%1> "
189 191
190 " WHERE { " 192 " WHERE { "
191 193
192 " ?signal a mo:Signal ; " 194 " ?signal af:signal_feature ?feature . "
193 " mo:available_as ?signal_source ; "
194 " af:signal_feature ?feature . "
195 195
196 " ?feature a ?feature_signal_type ; " 196 " ?feature a ?feature_signal_type ; "
197 " af:value ?value . " 197 " af:value ?value . "
198 198
199 " } " 199 " } "
213 } 213 }
214 214
215 for (int i = 0; i < results.size(); ++i) { 215 for (int i = 0; i < results.size(); ++i) {
216 216
217 QString feature = results[i]["feature"].value; 217 QString feature = results[i]["feature"].value;
218 QString source = results[i]["signal_source"].value;
219 QString type = results[i]["feature_signal_type"].value; 218 QString type = results[i]["feature_signal_type"].value;
220 QString value = results[i]["value"].value; 219 QString value = results[i]["value"].value;
221 220
222 int sampleRate = 0; 221 int sampleRate = 0;
223 int windowLength = 0; 222 int windowLength = 0;
257 for (int j = 0; j < values.size(); ++j) { 256 for (int j = 0; j < values.size(); ++j) {
258 float f = values[j].toFloat(); 257 float f = values[j].toFloat();
259 SparseTimeValueModel::Point point(j * hopSize, f, ""); 258 SparseTimeValueModel::Point point(j * hopSize, f, "");
260 m->addPoint(point); 259 m->addPoint(point);
261 } 260 }
261
262 getDenseModelTitle(m, feature, type);
262 263
263 models.push_back(m); 264 models.push_back(m);
264 265
265 } else { 266 } else {
266 267
282 283
283 if (!column.empty()) { 284 if (!column.empty()) {
284 m->setColumn(x++, column); 285 m->setColumn(x++, column);
285 } 286 }
286 287
288 getDenseModelTitle(m, feature, type);
289
287 models.push_back(m); 290 models.push_back(m);
288 } 291 }
289 } 292 }
293 }
294
295 void
296 RDFImporterImpl::getDenseModelTitle(Model *m,
297 QString featureUri,
298 QString featureTypeUri)
299 {
300 QString titleQuery = QString
301 (
302 " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
303 " SELECT ?title "
304 " FROM <%1> "
305 " WHERE { "
306 " <%2> dc:title ?title . "
307 " } "
308 ).arg(m_uristring);
309
310 SimpleSPARQLQuery::Value v;
311
312 v = SimpleSPARQLQuery::singleResultQuery
313 (SimpleSPARQLQuery::QueryFromSingleSource,
314 titleQuery.arg(featureUri),
315 "title");
316
317 if (v.value != "") {
318 std::cerr << "RDFImporterImpl::getDenseModelTitle: Title (from signal) \"" << v.value.toStdString() << "\"" << std::endl;
319 m->setObjectName(v.value);
320 return;
321 }
322
323 v = SimpleSPARQLQuery::singleResultQuery
324 (SimpleSPARQLQuery::QueryFromSingleSource,
325 titleQuery.arg(featureTypeUri),
326 "title");
327
328 if (v.value != "") {
329 std::cerr << "RDFImporterImpl::getDenseModelTitle: Title (from signal type) \"" << v.value.toStdString() << "\"" << std::endl;
330 m->setObjectName(v.value);
331 return;
332 }
333
334 std::cerr << "RDFImporterImpl::getDenseModelTitle: No title available for feature <" << featureUri.toStdString() << ">" << std::endl;
290 } 335 }
291 336
292 void 337 void
293 RDFImporterImpl::getDenseFeatureProperties(QString featureUri, 338 RDFImporterImpl::getDenseFeatureProperties(QString featureUri,
294 int &sampleRate, int &windowLength, 339 int &sampleRate, int &windowLength,
641 // std::cerr << "NoteModel" << std::endl; 686 // std::cerr << "NoteModel" << std::endl;
642 model = new NoteModel(m_sampleRate, 1, false); 687 model = new NoteModel(m_sampleRate, 1, false);
643 } 688 }
644 } 689 }
645 690
691 QString titleQuery = QString
692 (
693 " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
694 " SELECT ?title "
695 " FROM <%1> "
696 " WHERE { "
697 " <%2> dc:title ?title . "
698 " } "
699 ).arg(m_uristring).arg(type);
700 QString title = SimpleSPARQLQuery::singleResultQuery
701 (s, titleQuery, "title").value;
702 if (title != "") model->setObjectName(title);
703
646 modelMap[source][type][dimensions][haveDuration] = model; 704 modelMap[source][type][dimensions][haveDuration] = model;
647 models.push_back(model); 705 models.push_back(model);
648 } 706 }
649 707
650 model = modelMap[source][type][dimensions][haveDuration]; 708 model = modelMap[source][type][dimensions][haveDuration];
663 long fduration, 721 long fduration,
664 bool haveDuration, 722 bool haveDuration,
665 std::vector<float> &values, 723 std::vector<float> &values,
666 QString label) 724 QString label)
667 { 725 {
668 std::cerr << "RDFImporterImpl::fillModel: adding point at frame " << ftime << std::endl; 726 // std::cerr << "RDFImporterImpl::fillModel: adding point at frame " << ftime << std::endl;
669 727
670 SparseOneDimensionalModel *sodm = 728 SparseOneDimensionalModel *sodm =
671 dynamic_cast<SparseOneDimensionalModel *>(model); 729 dynamic_cast<SparseOneDimensionalModel *>(model);
672 if (sodm) { 730 if (sodm) {
673 SparseOneDimensionalModel::Point point(ftime, label); 731 SparseOneDimensionalModel::Point point(ftime, label);