comparison rdf/RDFFeatureWriter.cpp @ 507:0944d13689b2

* Implement proper RDF feature writing for track level features, using the feature attribute URI given in the plugin description RDF (if there is one)
author Chris Cannam
date Fri, 05 Dec 2008 14:19:04 +0000
parents 3376dc26dece
children 1b8c748fd7ea
comparison
equal deleted inserted replaced
506:823e8a4feff5 507:0944d13689b2
80 80
81 void 81 void
82 RDFFeatureWriter::setTrackMetadata(QString trackId, 82 RDFFeatureWriter::setTrackMetadata(QString trackId,
83 TrackMetadata metadata) 83 TrackMetadata metadata)
84 { 84 {
85 std::cerr << "RDFFeatureWriter::setTrackMetadata: \""
86 << trackId.toStdString() << "\" -> \"" << metadata.title.toStdString() << "\",\"" << metadata.maker.toStdString() << "\"" << std::endl;
87 m_metadata[trackId] = metadata; 85 m_metadata[trackId] = metadata;
88 } 86 }
89 87
90 void 88 void
91 RDFFeatureWriter::write(QString trackId, 89 RDFFeatureWriter::write(QString trackId,
162 exit(1); 160 exit(1);
163 } 161 }
164 162
165 writeDenseRDF(stream, transform, output, features, 163 writeDenseRDF(stream, transform, output, features,
166 m_rdfDescriptions[pluginId], signalURI, timelineURI); 164 m_rdfDescriptions[pluginId], signalURI, timelineURI);
165
166 } else if (!m_plain &&
167 m_rdfDescriptions[pluginId].haveDescription() &&
168 m_rdfDescriptions[pluginId].getOutputDisposition
169 (output.identifier.c_str()) ==
170 PluginRDFDescription::OutputTrackLevel &&
171 m_rdfDescriptions[pluginId].getOutputFeatureAttributeURI
172 (output.identifier.c_str()) != "") {
173
174 QString signalURI = m_trackSignalURIs[trackId];
175
176 if (signalURI == "") {
177 cerr << "RDFFeatureWriter: INTERNAL ERROR: writing track-level features without having established a signal URI!" << endl;
178 exit(1);
179 }
180
181 writeTrackLevelRDF(stream, transform, output, features,
182 m_rdfDescriptions[pluginId], signalURI);
167 183
168 } else { 184 } else {
169 185
170 writeSparseRDF(stream, transform, output, features, 186 writeSparseRDF(stream, transform, output, features,
171 m_rdfDescriptions[pluginId], timelineURI); 187 m_rdfDescriptions[pluginId], timelineURI);
247 TrackMetadata tm = m_metadata[trackId]; 263 TrackMetadata tm = m_metadata[trackId];
248 if (tm.title != "") { 264 if (tm.title != "") {
249 stream << " dc:title \"\"\"" << tm.title << "\"\"\" ;\n"; 265 stream << " dc:title \"\"\"" << tm.title << "\"\"\" ;\n";
250 } 266 }
251 if (tm.maker != "") { 267 if (tm.maker != "") {
252 stream << " dc:creator [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ;\n"; 268 stream << " foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ;\n";
253 } 269 }
254 } 270 }
255 271
256 stream << " mo:time [\n" 272 stream << " mo:time [\n"
257 << " a tl:Interval ;\n" 273 << " a tl:Interval ;\n"
266 PluginRDFDescription &desc) 282 PluginRDFDescription &desc)
267 { 283 {
268 QString outputId = od.identifier.c_str(); 284 QString outputId = od.identifier.c_str();
269 QTextStream &stream = *sptr; 285 QTextStream &stream = *sptr;
270 286
287 // There is no "needFeatureType" for track-level outputs, because
288 // we can't meaningfully write a feature at all if we don't know
289 // what property to use for it. If the output is track level but
290 // there is no feature type given, we have to revert to events.
291
271 bool needEventType = false; 292 bool needEventType = false;
272 bool needSignalType = false; 293 bool needSignalType = false;
273
274 //!!! feature attribute type is not yet supported
275 294
276 //!!! bin names, extents and so on can be written out using e.g. vamp:bin_names ( "a" "b" "c" ) 295 //!!! bin names, extents and so on can be written out using e.g. vamp:bin_names ( "a" "b" "c" )
277 296
278 if (desc.getOutputDisposition(outputId) == 297 if (desc.getOutputDisposition(outputId) ==
279 PluginRDFDescription::OutputDense) { 298 PluginRDFDescription::OutputDense) {
286 needSignalType = true; 305 needSignalType = true;
287 306
288 } else if (desc.getOutputSignalTypeURI(outputId) == "") { 307 } else if (desc.getOutputSignalTypeURI(outputId) == "") {
289 308
290 needSignalType = true; 309 needSignalType = true;
310 }
311
312 } else if (desc.getOutputDisposition(outputId) ==
313 PluginRDFDescription::OutputTrackLevel) {
314
315 // see note above -- need to generate an event type if no
316 // feature type given, or if in plain mode
317
318 cerr << "Note: track level output" << endl;
319
320 if (m_plain) {
321
322 needEventType = true;
323
324 } else if (desc.getOutputFeatureAttributeURI(outputId) == "") {
325
326 if (desc.getOutputEventTypeURI(outputId) == "") {
327
328 needEventType = true;
329 }
291 } 330 }
292 331
293 } else { 332 } else {
294 333
295 // may need event type but won't need signal type 334 // may need event type but won't need signal type
441 stream << ".\n"; 480 stream << ".\n";
442 } 481 }
443 } 482 }
444 483
445 void 484 void
485 RDFFeatureWriter::writeTrackLevelRDF(QTextStream *sptr,
486 const Transform &transform,
487 const Plugin::OutputDescriptor& od,
488 const Plugin::FeatureList& featureList,
489 PluginRDFDescription &desc,
490 QString signalURI)
491 {
492 if (featureList.empty()) return;
493 QTextStream &stream = *sptr;
494
495 bool plain = (m_plain || !desc.haveDescription());
496
497 QString outputId = od.identifier.c_str();
498 QString featureUri = desc.getOutputFeatureAttributeURI(outputId);
499
500 if (featureUri == "") {
501 cerr << "RDFFeatureWriter::writeTrackLevelRDF: ERROR: No feature URI available -- this function should not have been called!" << endl;
502 return;
503 }
504
505 for (int i = 0; i < featureList.size(); ++i) {
506
507 const Plugin::Feature &feature = featureList[i];
508
509 if (feature.values.empty()) {
510
511 if (feature.label == "") continue;
512
513 stream << signalURI << " " << featureUri << " \""
514 << feature.label.c_str() << "\" .\n";
515
516 } else {
517
518 stream << signalURI << " " << featureUri << " \""
519 << feature.values[0] << "\"^^xsd:float .\n";
520 }
521 }
522 }
523
524 void
446 RDFFeatureWriter::writeDenseRDF(QTextStream *sptr, 525 RDFFeatureWriter::writeDenseRDF(QTextStream *sptr,
447 const Transform &transform, 526 const Transform &transform,
448 const Plugin::OutputDescriptor& od, 527 const Plugin::OutputDescriptor& od,
449 const Plugin::FeatureList& featureList, 528 const Plugin::FeatureList& featureList,
450 PluginRDFDescription &desc, 529 PluginRDFDescription &desc,