# HG changeset patch # User Chris Cannam # Date 1228486744 0 # Node ID 0944d13689b2705f643b3f5ac294aac794fafecf # Parent 823e8a4feff57ebef673bc4e11607f4ae0e8adce * Implement proper RDF feature writing for track level features, using the feature attribute URI given in the plugin description RDF (if there is one) diff -r 823e8a4feff5 -r 0944d13689b2 rdf/PluginRDFDescription.cpp --- a/rdf/PluginRDFDescription.cpp Fri Dec 05 11:31:51 2008 +0000 +++ b/rdf/PluginRDFDescription.cpp Fri Dec 05 14:19:04 2008 +0000 @@ -372,11 +372,14 @@ } v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("feature_attribute"), "feature_attribute"); + (m, queryTemplate.arg("feature"), "feature"); if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { + cerr << "Feature attribute URI: \"" << v.value.toStdString() << "\"" << endl; m_outputFeatureAttributeURIMap[outputId] = v.value; - } + } else { + cerr << "No feature attribute URI: \"" << v.value.toStdString() << "\"" << endl; + } v = SimpleSPARQLQuery::singleResultQuery (m, queryTemplate.arg("signal_type"), "signal_type"); diff -r 823e8a4feff5 -r 0944d13689b2 rdf/RDFFeatureWriter.cpp --- a/rdf/RDFFeatureWriter.cpp Fri Dec 05 11:31:51 2008 +0000 +++ b/rdf/RDFFeatureWriter.cpp Fri Dec 05 14:19:04 2008 +0000 @@ -82,8 +82,6 @@ RDFFeatureWriter::setTrackMetadata(QString trackId, TrackMetadata metadata) { - std::cerr << "RDFFeatureWriter::setTrackMetadata: \"" - << trackId.toStdString() << "\" -> \"" << metadata.title.toStdString() << "\",\"" << metadata.maker.toStdString() << "\"" << std::endl; m_metadata[trackId] = metadata; } @@ -165,6 +163,24 @@ writeDenseRDF(stream, transform, output, features, m_rdfDescriptions[pluginId], signalURI, timelineURI); + } else if (!m_plain && + m_rdfDescriptions[pluginId].haveDescription() && + m_rdfDescriptions[pluginId].getOutputDisposition + (output.identifier.c_str()) == + PluginRDFDescription::OutputTrackLevel && + m_rdfDescriptions[pluginId].getOutputFeatureAttributeURI + (output.identifier.c_str()) != "") { + + QString signalURI = m_trackSignalURIs[trackId]; + + if (signalURI == "") { + cerr << "RDFFeatureWriter: INTERNAL ERROR: writing track-level features without having established a signal URI!" << endl; + exit(1); + } + + writeTrackLevelRDF(stream, transform, output, features, + m_rdfDescriptions[pluginId], signalURI); + } else { writeSparseRDF(stream, transform, output, features, @@ -249,7 +265,7 @@ stream << " dc:title \"\"\"" << tm.title << "\"\"\" ;\n"; } if (tm.maker != "") { - stream << " dc:creator [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ;\n"; + stream << " foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ;\n"; } } @@ -268,11 +284,14 @@ QString outputId = od.identifier.c_str(); QTextStream &stream = *sptr; + // There is no "needFeatureType" for track-level outputs, because + // we can't meaningfully write a feature at all if we don't know + // what property to use for it. If the output is track level but + // there is no feature type given, we have to revert to events. + bool needEventType = false; bool needSignalType = false; - //!!! feature attribute type is not yet supported - //!!! bin names, extents and so on can be written out using e.g. vamp:bin_names ( "a" "b" "c" ) if (desc.getOutputDisposition(outputId) == @@ -290,6 +309,26 @@ needSignalType = true; } + } else if (desc.getOutputDisposition(outputId) == + PluginRDFDescription::OutputTrackLevel) { + + // see note above -- need to generate an event type if no + // feature type given, or if in plain mode + + cerr << "Note: track level output" << endl; + + if (m_plain) { + + needEventType = true; + + } else if (desc.getOutputFeatureAttributeURI(outputId) == "") { + + if (desc.getOutputEventTypeURI(outputId) == "") { + + needEventType = true; + } + } + } else { // may need event type but won't need signal type @@ -443,6 +482,46 @@ } void +RDFFeatureWriter::writeTrackLevelRDF(QTextStream *sptr, + const Transform &transform, + const Plugin::OutputDescriptor& od, + const Plugin::FeatureList& featureList, + PluginRDFDescription &desc, + QString signalURI) +{ + if (featureList.empty()) return; + QTextStream &stream = *sptr; + + bool plain = (m_plain || !desc.haveDescription()); + + QString outputId = od.identifier.c_str(); + QString featureUri = desc.getOutputFeatureAttributeURI(outputId); + + if (featureUri == "") { + cerr << "RDFFeatureWriter::writeTrackLevelRDF: ERROR: No feature URI available -- this function should not have been called!" << endl; + return; + } + + for (int i = 0; i < featureList.size(); ++i) { + + const Plugin::Feature &feature = featureList[i]; + + if (feature.values.empty()) { + + if (feature.label == "") continue; + + stream << signalURI << " " << featureUri << " \"" + << feature.label.c_str() << "\" .\n"; + + } else { + + stream << signalURI << " " << featureUri << " \"" + << feature.values[0] << "\"^^xsd:float .\n"; + } + } +} + +void RDFFeatureWriter::writeDenseRDF(QTextStream *sptr, const Transform &transform, const Plugin::OutputDescriptor& od, diff -r 823e8a4feff5 -r 0944d13689b2 rdf/RDFFeatureWriter.h --- a/rdf/RDFFeatureWriter.h Fri Dec 05 11:31:51 2008 +0000 +++ b/rdf/RDFFeatureWriter.h Fri Dec 05 14:19:04 2008 +0000 @@ -78,6 +78,13 @@ PluginRDFDescription &desc, QString timelineURI); + void writeTrackLevelRDF(QTextStream *stream, + const Transform &transform, + const Vamp::Plugin::OutputDescriptor &output, + const Vamp::Plugin::FeatureList &features, + PluginRDFDescription &desc, + QString signalURI); + void writeDenseRDF(QTextStream *stream, const Transform &transform, const Vamp::Plugin::OutputDescriptor &output, diff -r 823e8a4feff5 -r 0944d13689b2 rdf/SimpleSPARQLQuery.cpp --- a/rdf/SimpleSPARQLQuery.cpp Fri Dec 05 11:31:51 2008 +0000 +++ b/rdf/SimpleSPARQLQuery.cpp Fri Dec 05 14:19:04 2008 +0000 @@ -213,8 +213,10 @@ errorString = "Failed to initialise Redland parser"; return false; } - + +#ifdef DEBUG_SIMPLE_SPARQL_QUERY std::cerr << "About to parse \"" << uri.toStdString() << "\"" << std::endl; +#endif Profiler p("SimpleSPARQLQuery: Parse URI into LIBRDF model"); diff -r 823e8a4feff5 -r 0944d13689b2 transform/FileFeatureWriter.cpp --- a/transform/FileFeatureWriter.cpp Fri Dec 05 11:31:51 2008 +0000 +++ b/transform/FileFeatureWriter.cpp Fri Dec 05 14:19:04 2008 +0000 @@ -171,8 +171,9 @@ QString infilename = url.toLocalFile(); if (infilename == "") infilename = url.path(); basename = QFileInfo(infilename).baseName(); -// cerr << "url = " << url.toString().toStdString() << ", infilename = " -// << infilename.toStdString() << ", basename = " << basename.toStdString() << endl; + + cerr << "trackId = " << trackId.toStdString() << ", url = " << url.toString().toStdString() << ", infilename = " + << infilename.toStdString() << ", basename = " << basename.toStdString() << endl; if (m_baseDir != "") dirname = QFileInfo(m_baseDir).absoluteFilePath();