changeset 594:f3bb7a3ffd89

* Add rdf-track-uri and rdf-maker-uri options
author Chris Cannam
date Tue, 02 Jun 2009 09:48:54 +0000
parents 4f3e3fb07e0b
children 3bbac921b70a
files rdf/RDFFeatureWriter.cpp rdf/RDFFeatureWriter.h
diffstat 2 files changed, 65 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/rdf/RDFFeatureWriter.cpp	Thu May 21 16:54:43 2009 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Tue Jun 02 09:48:54 2009 +0000
@@ -59,6 +59,16 @@
     p.description = "Link the output RDF to the given audio file URI instead of its actual location.";
     p.hasArg = true;
     pl.push_back(p);
+
+    p.name = "track-uri";
+    p.description = "Link the output RDF to the given track URI.";
+    p.hasArg = true;
+    pl.push_back(p);
+
+    p.name = "maker-uri";
+    p.description = "Link the track in the output RDF to the given foaf:maker URI.";
+    p.hasArg = true;
+    pl.push_back(p);
     
     return pl;
 }
@@ -74,7 +84,13 @@
             m_plain = true;
         }
         if (i->first == "audiofile-uri") {
-            m_suri = i->second.c_str();
+            m_userAudioFileUri = i->second.c_str();
+        }
+        if (i->first == "track-uri") {
+            m_userTrackUri = i->second.c_str();
+        }
+        if (i->first == "maker-uri") {
+            m_userMakerUri = i->second.c_str();
         }
     }
 }
@@ -83,6 +99,7 @@
 RDFFeatureWriter::setTrackMetadata(QString trackId,
                                    TrackMetadata metadata)
 {
+//    cerr << "setTrackMetadata: title = " << metadata.title.toStdString() << ", maker = " << metadata.maker.toStdString() << endl;
     m_metadata[trackId] = metadata;
 }
 
@@ -127,7 +144,7 @@
 
     if (m_startedStreamTransforms.find(stream) ==
         m_startedStreamTransforms.end()) {
-        cerr << "This stream is new, writing prefixes" << endl;
+//        cerr << "This stream is new, writing prefixes" << endl;
         writePrefixes(stream);
         if (m_singleFileName == "" && !m_stdout) {
             writeSignalDescription(stream, trackId);
@@ -226,7 +243,7 @@
     // dirty grubby low-rent way of doing that.  This function is
     // called by FileFeatureWriter::getOutputFile when in append mode.
 
-    std::cerr << "reviewFileForAppending(" << filename.toStdString() << ")" << std::endl;
+//    std::cerr << "reviewFileForAppending(" << filename.toStdString() << ")" << std::endl;
 
     QFile file(filename);
 
@@ -256,7 +273,7 @@
 RDFFeatureWriter::writeSignalDescription(QTextStream *sptr,
                                          QString trackId)
 {
-    std::cerr << "RDFFeatureWriter::writeSignalDescription" << std::endl;
+//    std::cerr << "RDFFeatureWriter::writeSignalDescription" << std::endl;
 
     QTextStream &stream = *sptr;
 
@@ -291,6 +308,13 @@
         m_trackTrackURIs[trackId] = QString(":track_%1").arg(signalCount);
     }
     QString trackURI = m_trackTrackURIs[trackId];
+
+    bool userSpecifiedTrack = false;
+    if (m_userTrackUri != "") {
+        trackURI = "<" + m_userTrackUri + ">";
+        m_trackTrackURIs[trackId] = trackURI;
+        userSpecifiedTrack = true;
+    }
     
     if (m_trackTimelineURIs.find(trackId) == m_trackTimelineURIs.end()) {
         m_trackTimelineURIs[trackId] = QString(":signal_timeline_%1").arg(signalCount);
@@ -298,34 +322,44 @@
     QString timelineURI = m_trackTimelineURIs[trackId];
 
     QString afURI = url.toEncoded().data();
-    if (m_suri != NULL) afURI = m_suri;
+    if (m_userAudioFileUri != "") afURI = m_userAudioFileUri;
 
-    if (m_metadata.find(trackId) != m_metadata.end()) {
-        TrackMetadata tm = m_metadata[trackId];
-        if (tm.title != "" || tm.maker != "") {
-            // We only write a Track at all if we have some
-            // title/artist metadata to put in it.  Otherwise we can't
-            // be sure that what we have is a Track, in the
-            // publication sense -- it may just be a fragment, a test
-            // file, whatever.  Since we'd have no metadata to
-            // associate with our Track, the only effect of including
-            // a Track would be to assert that this was one, which is
-            // the one thing we wouldn't know...
-            stream << trackURI << " a mo:Track ";
-            if (tm.title != "") {
-                stream << ";\n    dc:title \"\"\"" << tm.title << "\"\"\" ";
-            }
-            if (tm.maker != "") {
-                stream << ";\n    foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ";
-            }
-            if (trackId != "") {
-                stream << ";\n    mo:available_as <" << afURI << "> ";
-            }
-            stream << ".\n\n";
+    bool wantTrack = (userSpecifiedTrack ||
+                      (m_userMakerUri != "") ||
+                      (m_metadata.find(trackId) != m_metadata.end()));
+
+//    cerr << "wantTrack = " << wantTrack << " (userSpecifiedTrack = "
+//         << userSpecifiedTrack << ", m_userMakerUri = " << m_userMakerUri.toStdString() << ", have metadata = " << (m_metadata.find(trackId) != m_metadata.end()) << ")" << endl;
+
+    if (wantTrack) {
+        // We only write a Track at all if we have some title/artist
+        // metadata to put in it, or if the user has requested a
+        // specific track URI.  Otherwise we can't be sure that what
+        // we have is a Track, in the publication sense -- it may just
+        // be a fragment, a test file, whatever.  Since we'd have no
+        // metadata to associate with our Track, the only effect of
+        // including a Track would be to assert that this was one,
+        // which is the one thing we wouldn't know...
+        TrackMetadata tm;
+        if (m_metadata.find(trackId) != m_metadata.end()) {
+            tm = m_metadata[trackId];
         }
+        stream << trackURI << " a mo:Track ";
+        if (tm.title != "") {
+            stream << ";\n    dc:title \"\"\"" << tm.title << "\"\"\" ";
+        }
+        if (m_userMakerUri != "") {
+            stream << ";\n    foaf:maker <" << m_userMakerUri << "> ";
+        } else if (tm.maker != "") {
+            stream << ";\n    foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ";
+        }
+        if (afURI != "") {
+            stream << ";\n    mo:available_as <" << afURI << "> ";
+        }
+        stream << ".\n\n";
     }
 
-    if (trackId != "") {
+    if (afURI != "") {
         stream << "<" << afURI << "> a mo:AudioFile ;\n";
         stream << "    mo:encodes " << signalURI << ".\n\n";
     }
--- a/rdf/RDFFeatureWriter.h	Thu May 21 16:54:43 2009 +0000
+++ b/rdf/RDFFeatureWriter.h	Tue Jun 02 09:48:54 2009 +0000
@@ -114,7 +114,9 @@
     typedef pair<QString, Transform> StringTransformPair;
     typedef pair<QTextStream *, QString> StreamBuffer;
     map<StringTransformPair, StreamBuffer> m_openDenseFeatures; // signal URI + transform -> stream + text
-    QString m_suri;
+    QString m_userAudioFileUri;
+    QString m_userTrackUri;
+    QString m_userMakerUri;
 
     bool m_plain;