changeset 510:af7b6e55895b

* Ensure text models are exported with text properties in RDF, and imported back into text models again (instead of time/value models)
author Chris Cannam
date Mon, 08 Dec 2008 11:53:10 +0000
parents 6066bde1c126
children 7207e3eba44f
files data/fileio/MP3FileReader.cpp data/model/Model.cpp rdf/RDFExporter.cpp rdf/RDFFeatureWriter.cpp rdf/RDFFeatureWriter.h rdf/RDFImporter.cpp
diffstat 6 files changed, 76 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp	Mon Dec 08 11:15:13 2008 +0000
+++ b/data/fileio/MP3FileReader.cpp	Mon Dec 08 11:53:10 2008 +0000
@@ -31,7 +31,7 @@
 #ifdef HAVE_ID3TAG
 #include <id3tag.h>
 #endif
-#define DEBUG_ID3TAG 1
+//#define DEBUG_ID3TAG 1
 
 #include <QFileInfo>
 
--- a/data/model/Model.cpp	Mon Dec 08 11:15:13 2008 +0000
+++ b/data/model/Model.cpp	Mon Dec 08 11:53:10 2008 +0000
@@ -24,7 +24,7 @@
 
 Model::~Model()
 {
-    std::cerr << "Model::~Model(" << this << ")" << std::endl;
+//    std::cerr << "Model::~Model(" << this << ")" << std::endl;
 
     if (!m_aboutToDelete) {
         std::cerr << "NOTE: Model::~Model(" << this << ", \""
--- a/rdf/RDFExporter.cpp	Mon Dec 08 11:15:13 2008 +0000
+++ b/rdf/RDFExporter.cpp	Mon Dec 08 11:53:10 2008 +0000
@@ -155,6 +155,7 @@
             f.hasTimestamp = true;
             f.hasDuration = false;
             const TextModel::PointList &pl(m->getPoints());
+            m_fw->setFixedEventTypeURI("af:Text");
             for (TextModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
                 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
--- a/rdf/RDFFeatureWriter.cpp	Mon Dec 08 11:15:13 2008 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Mon Dec 08 11:53:10 2008 +0000
@@ -87,6 +87,12 @@
 }
 
 void
+RDFFeatureWriter::setFixedEventTypeURI(QString uri)
+{
+    m_fixedEventTypeURI = uri;
+}
+
+void
 RDFFeatureWriter::write(QString trackId,
                         const Transform &transform,
                         const Plugin::OutputDescriptor& output,
@@ -357,7 +363,7 @@
                << endl;
     }
 
-    if (needEventType) {
+    if (needEventType && m_fixedEventTypeURI == "") {
 
         QString uri;
         if (m_syntheticEventTypeURIs.find(transform) !=
@@ -420,16 +426,20 @@
 
         stream << ":event_" << featureNumber << " a ";
 
-        QString eventTypeURI = desc.getOutputEventTypeURI(outputId);
-        if (plain || eventTypeURI == "") {
-            if (m_syntheticEventTypeURIs.find(transform) != 
-                m_syntheticEventTypeURIs.end()) {
-                stream << m_syntheticEventTypeURIs[transform] << " ;\n";
+        if (m_fixedEventTypeURI != "") {
+            stream << m_fixedEventTypeURI << " ;\n";
+        } else {
+            QString eventTypeURI = desc.getOutputEventTypeURI(outputId);
+            if (plain || eventTypeURI == "") {
+                if (m_syntheticEventTypeURIs.find(transform) != 
+                    m_syntheticEventTypeURIs.end()) {
+                    stream << m_syntheticEventTypeURIs[transform] << " ;\n";
+                } else {
+                    stream << ":event_type_" << outputId << " ;\n";
+                }
             } else {
-                stream << ":event_type_" << outputId << " ;\n";
+                stream << "<" << eventTypeURI << "> ;\n";
             }
-        } else {
-            stream << "<" << eventTypeURI << "> ;\n";
         }
 
         QString timestamp = feature.timestamp.toString().c_str();
@@ -465,7 +475,7 @@
 
         if (feature.label.length() > 0) {
             stream << ";\n";
-            stream << "    rdfs:label \"" << feature.label.c_str() << "\" ";
+            stream << "    rdfs:label \"\"\"" << feature.label.c_str() << "\"\"\" ";
         }
 
         if (!feature.values.empty()) {
--- a/rdf/RDFFeatureWriter.h	Mon Dec 08 11:15:13 2008 +0000
+++ b/rdf/RDFFeatureWriter.h	Mon Dec 08 11:53:10 2008 +0000
@@ -55,6 +55,8 @@
                        const Vamp::Plugin::FeatureList &features,
                        std::string summaryType = "");
 
+    virtual void setFixedEventTypeURI(QString uri); // something of a hack
+
     virtual void finish();
 
 private:
@@ -64,6 +66,8 @@
     typedef map<QString, TrackMetadata> TrackMetadataMap;
     TrackMetadataMap m_metadata;
 
+    QString m_fixedEventTypeURI;
+
     void writePrefixes(QTextStream *);
     void writeSignalDescription(QTextStream *, QString);
     void writeLocalFeatureTypes(QTextStream *,
--- a/rdf/RDFImporter.cpp	Mon Dec 08 11:15:13 2008 +0000
+++ b/rdf/RDFImporter.cpp	Mon Dec 08 11:53:10 2008 +0000
@@ -30,6 +30,7 @@
 #include "data/model/SparseTimeValueModel.h"
 #include "data/model/EditableDenseThreeDimensionalModel.h"
 #include "data/model/NoteModel.h"
+#include "data/model/TextModel.h"
 #include "data/model/RegionModel.h"
 #include "data/model/WaveFileModel.h"
 
@@ -566,6 +567,15 @@
 
         ).arg(m_uristring);
 
+    QString textQueryString = prefixes + QString(
+        
+        " SELECT ?label FROM <%1> "
+        " WHERE { "
+        "   <%2> af:text ?label . "
+        " } "
+
+        ).arg(m_uristring);
+
     SimpleSPARQLQuery query(s, queryString);
     query.setProgressReporter(reporter);
 
@@ -626,8 +636,18 @@
         bool haveTime = false;
         bool haveDuration = false;
 
-        QString label = SimpleSPARQLQuery::singleResultQuery
-            (s, labelQueryString.arg(thinguri), "label").value;
+        QString label = "";
+        bool text = (type.contains("Text") || type.contains("text")); // Ha, ha
+
+        if (text) {
+            label = SimpleSPARQLQuery::singleResultQuery
+                (s, textQueryString.arg(thinguri), "label").value;
+        }
+
+        if (label == "") {
+            label = SimpleSPARQLQuery::singleResultQuery
+                (s, labelQueryString.arg(thinguri), "label").value;
+        }
 
         SimpleSPARQLQuery rangeQuery(s, rangeQueryString.arg(thinguri));
         SimpleSPARQLQuery::ResultList rangeResults = rangeQuery.execute();
@@ -682,13 +702,25 @@
 
                 if (dimensions == 1) {
 
-//                    std::cerr << "SparseOneDimensionalModel" << std::endl;
-                    model = new SparseOneDimensionalModel(m_sampleRate, 1, false);
+                    if (text) {
+                        
+                        model = new TextModel(m_sampleRate, 1, false);
+
+                    } else {
+
+                        model = new SparseOneDimensionalModel(m_sampleRate, 1, false);
+                    }
 
                 } else if (dimensions == 2) {
 
-//                    std::cerr << "SparseTimeValueModel" << std::endl;
-                    model = new SparseTimeValueModel(m_sampleRate, 1, false);
+                    if (text) {
+
+                        model = new TextModel(m_sampleRate, 1, false);
+
+                    } else {
+
+                        model = new SparseTimeValueModel(m_sampleRate, 1, false);
+                    }
 
                 } else {
 
@@ -699,7 +731,6 @@
                     // but it's hard to apply it because we don't have
                     // all the necessary timing data yet... hmm
 
-//                    std::cerr << "NoteModel" << std::endl;
                     model = new NoteModel(m_sampleRate, 1, false);
                 }
 
@@ -710,7 +741,6 @@
                     // If our units are frequency or midi pitch, we
                     // should be using a note model... hm
                     
-//                    std::cerr << "RegionModel" << std::endl;
                     model = new RegionModel(m_sampleRate, 1, false);
 
                 } else {
@@ -722,7 +752,6 @@
                     // but it's hard to apply it because we don't have
                     // all the necessary timing data yet... hmm
 
-//                    std::cerr << "NoteModel" << std::endl;
                     model = new NoteModel(m_sampleRate, 1, false);
                 }
             }
@@ -777,6 +806,17 @@
         return;
     }
 
+    TextModel *tm =
+        dynamic_cast<TextModel *>(model);
+    if (tm) {
+        TextModel::Point point
+            (ftime,
+             values.empty() ? 0.5f : values[0] < 0.f ? 0.f : values[0] > 1.f ? 1.f : values[0], // I was young and feckless once too
+             label);
+        tm->addPoint(point);
+        return;
+    }
+
     SparseTimeValueModel *stvm =
         dynamic_cast<SparseTimeValueModel *>(model);
     if (stvm) {