comparison rdf/RDFFeatureWriter.cpp @ 594:f3bb7a3ffd89

* Add rdf-track-uri and rdf-maker-uri options
author Chris Cannam
date Tue, 02 Jun 2009 09:48:54 +0000
parents 063da8955f65
children 4fa2b135acbc
comparison
equal deleted inserted replaced
593:4f3e3fb07e0b 594:f3bb7a3ffd89
57 57
58 p.name = "audiofile-uri"; 58 p.name = "audiofile-uri";
59 p.description = "Link the output RDF to the given audio file URI instead of its actual location."; 59 p.description = "Link the output RDF to the given audio file URI instead of its actual location.";
60 p.hasArg = true; 60 p.hasArg = true;
61 pl.push_back(p); 61 pl.push_back(p);
62
63 p.name = "track-uri";
64 p.description = "Link the output RDF to the given track URI.";
65 p.hasArg = true;
66 pl.push_back(p);
67
68 p.name = "maker-uri";
69 p.description = "Link the track in the output RDF to the given foaf:maker URI.";
70 p.hasArg = true;
71 pl.push_back(p);
62 72
63 return pl; 73 return pl;
64 } 74 }
65 75
66 void 76 void
72 i != params.end(); ++i) { 82 i != params.end(); ++i) {
73 if (i->first == "plain") { 83 if (i->first == "plain") {
74 m_plain = true; 84 m_plain = true;
75 } 85 }
76 if (i->first == "audiofile-uri") { 86 if (i->first == "audiofile-uri") {
77 m_suri = i->second.c_str(); 87 m_userAudioFileUri = i->second.c_str();
88 }
89 if (i->first == "track-uri") {
90 m_userTrackUri = i->second.c_str();
91 }
92 if (i->first == "maker-uri") {
93 m_userMakerUri = i->second.c_str();
78 } 94 }
79 } 95 }
80 } 96 }
81 97
82 void 98 void
83 RDFFeatureWriter::setTrackMetadata(QString trackId, 99 RDFFeatureWriter::setTrackMetadata(QString trackId,
84 TrackMetadata metadata) 100 TrackMetadata metadata)
85 { 101 {
102 // cerr << "setTrackMetadata: title = " << metadata.title.toStdString() << ", maker = " << metadata.maker.toStdString() << endl;
86 m_metadata[trackId] = metadata; 103 m_metadata[trackId] = metadata;
87 } 104 }
88 105
89 void 106 void
90 RDFFeatureWriter::setFixedEventTypeURI(QString uri) 107 RDFFeatureWriter::setFixedEventTypeURI(QString uri)
125 exit(1); 142 exit(1);
126 } 143 }
127 144
128 if (m_startedStreamTransforms.find(stream) == 145 if (m_startedStreamTransforms.find(stream) ==
129 m_startedStreamTransforms.end()) { 146 m_startedStreamTransforms.end()) {
130 cerr << "This stream is new, writing prefixes" << endl; 147 // cerr << "This stream is new, writing prefixes" << endl;
131 writePrefixes(stream); 148 writePrefixes(stream);
132 if (m_singleFileName == "" && !m_stdout) { 149 if (m_singleFileName == "" && !m_stdout) {
133 writeSignalDescription(stream, trackId); 150 writeSignalDescription(stream, trackId);
134 } 151 }
135 } 152 }
224 // Appending to an RDF file is tricky, because we need to ensure 241 // Appending to an RDF file is tricky, because we need to ensure
225 // that our URIs differ from any already in the file. This is a 242 // that our URIs differ from any already in the file. This is a
226 // dirty grubby low-rent way of doing that. This function is 243 // dirty grubby low-rent way of doing that. This function is
227 // called by FileFeatureWriter::getOutputFile when in append mode. 244 // called by FileFeatureWriter::getOutputFile when in append mode.
228 245
229 std::cerr << "reviewFileForAppending(" << filename.toStdString() << ")" << std::endl; 246 // std::cerr << "reviewFileForAppending(" << filename.toStdString() << ")" << std::endl;
230 247
231 QFile file(filename); 248 QFile file(filename);
232 249
233 // just return, don't report failure -- function that called us will do that 250 // just return, don't report failure -- function that called us will do that
234 if (!file.open(QIODevice::ReadOnly)) return; 251 if (!file.open(QIODevice::ReadOnly)) return;
254 271
255 void 272 void
256 RDFFeatureWriter::writeSignalDescription(QTextStream *sptr, 273 RDFFeatureWriter::writeSignalDescription(QTextStream *sptr,
257 QString trackId) 274 QString trackId)
258 { 275 {
259 std::cerr << "RDFFeatureWriter::writeSignalDescription" << std::endl; 276 // std::cerr << "RDFFeatureWriter::writeSignalDescription" << std::endl;
260 277
261 QTextStream &stream = *sptr; 278 QTextStream &stream = *sptr;
262 279
263 /* 280 /*
264 * Describe signal we're analysing (AudioFile, Signal, TimeLine, etc.) 281 * Describe signal we're analysing (AudioFile, Signal, TimeLine, etc.)
289 306
290 if (m_trackTrackURIs.find(trackId) == m_trackTrackURIs.end()) { 307 if (m_trackTrackURIs.find(trackId) == m_trackTrackURIs.end()) {
291 m_trackTrackURIs[trackId] = QString(":track_%1").arg(signalCount); 308 m_trackTrackURIs[trackId] = QString(":track_%1").arg(signalCount);
292 } 309 }
293 QString trackURI = m_trackTrackURIs[trackId]; 310 QString trackURI = m_trackTrackURIs[trackId];
311
312 bool userSpecifiedTrack = false;
313 if (m_userTrackUri != "") {
314 trackURI = "<" + m_userTrackUri + ">";
315 m_trackTrackURIs[trackId] = trackURI;
316 userSpecifiedTrack = true;
317 }
294 318
295 if (m_trackTimelineURIs.find(trackId) == m_trackTimelineURIs.end()) { 319 if (m_trackTimelineURIs.find(trackId) == m_trackTimelineURIs.end()) {
296 m_trackTimelineURIs[trackId] = QString(":signal_timeline_%1").arg(signalCount); 320 m_trackTimelineURIs[trackId] = QString(":signal_timeline_%1").arg(signalCount);
297 } 321 }
298 QString timelineURI = m_trackTimelineURIs[trackId]; 322 QString timelineURI = m_trackTimelineURIs[trackId];
299 323
300 QString afURI = url.toEncoded().data(); 324 QString afURI = url.toEncoded().data();
301 if (m_suri != NULL) afURI = m_suri; 325 if (m_userAudioFileUri != "") afURI = m_userAudioFileUri;
302 326
303 if (m_metadata.find(trackId) != m_metadata.end()) { 327 bool wantTrack = (userSpecifiedTrack ||
304 TrackMetadata tm = m_metadata[trackId]; 328 (m_userMakerUri != "") ||
305 if (tm.title != "" || tm.maker != "") { 329 (m_metadata.find(trackId) != m_metadata.end()));
306 // We only write a Track at all if we have some 330
307 // title/artist metadata to put in it. Otherwise we can't 331 // cerr << "wantTrack = " << wantTrack << " (userSpecifiedTrack = "
308 // be sure that what we have is a Track, in the 332 // << userSpecifiedTrack << ", m_userMakerUri = " << m_userMakerUri.toStdString() << ", have metadata = " << (m_metadata.find(trackId) != m_metadata.end()) << ")" << endl;
309 // publication sense -- it may just be a fragment, a test 333
310 // file, whatever. Since we'd have no metadata to 334 if (wantTrack) {
311 // associate with our Track, the only effect of including 335 // We only write a Track at all if we have some title/artist
312 // a Track would be to assert that this was one, which is 336 // metadata to put in it, or if the user has requested a
313 // the one thing we wouldn't know... 337 // specific track URI. Otherwise we can't be sure that what
314 stream << trackURI << " a mo:Track "; 338 // we have is a Track, in the publication sense -- it may just
315 if (tm.title != "") { 339 // be a fragment, a test file, whatever. Since we'd have no
316 stream << ";\n dc:title \"\"\"" << tm.title << "\"\"\" "; 340 // metadata to associate with our Track, the only effect of
317 } 341 // including a Track would be to assert that this was one,
318 if (tm.maker != "") { 342 // which is the one thing we wouldn't know...
319 stream << ";\n foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] "; 343 TrackMetadata tm;
320 } 344 if (m_metadata.find(trackId) != m_metadata.end()) {
321 if (trackId != "") { 345 tm = m_metadata[trackId];
322 stream << ";\n mo:available_as <" << afURI << "> "; 346 }
323 } 347 stream << trackURI << " a mo:Track ";
324 stream << ".\n\n"; 348 if (tm.title != "") {
325 } 349 stream << ";\n dc:title \"\"\"" << tm.title << "\"\"\" ";
326 } 350 }
327 351 if (m_userMakerUri != "") {
328 if (trackId != "") { 352 stream << ";\n foaf:maker <" << m_userMakerUri << "> ";
353 } else if (tm.maker != "") {
354 stream << ";\n foaf:maker [ a mo:MusicArtist; foaf:name \"\"\"" << tm.maker << "\"\"\" ] ";
355 }
356 if (afURI != "") {
357 stream << ";\n mo:available_as <" << afURI << "> ";
358 }
359 stream << ".\n\n";
360 }
361
362 if (afURI != "") {
329 stream << "<" << afURI << "> a mo:AudioFile ;\n"; 363 stream << "<" << afURI << "> a mo:AudioFile ;\n";
330 stream << " mo:encodes " << signalURI << ".\n\n"; 364 stream << " mo:encodes " << signalURI << ".\n\n";
331 } 365 }
332 366
333 stream << signalURI << " a mo:Signal ;\n"; 367 stream << signalURI << " a mo:Signal ;\n";