# HG changeset patch # User Chris Cannam # Date 1242316036 0 # Node ID 063da8955f65d476399187c5b02e29bc28e0596e # Parent a03aafaacb5abcd0ac7b62a1a00855778c9f0b6e * Try to avoid URI clashes with existing URIs in the file, when writing with --rdf-append diff -r a03aafaacb5a -r 063da8955f65 rdf/RDFFeatureWriter.cpp --- a/rdf/RDFFeatureWriter.cpp Thu May 14 14:33:40 2009 +0000 +++ b/rdf/RDFFeatureWriter.cpp Thu May 14 15:47:16 2009 +0000 @@ -219,6 +219,40 @@ } void +RDFFeatureWriter::reviewFileForAppending(QString filename) +{ + // Appending to an RDF file is tricky, because we need to ensure + // that our URIs differ from any already in the file. This is a + // 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; + + QFile file(filename); + + // just return, don't report failure -- function that called us will do that + if (!file.open(QIODevice::ReadOnly)) return; + + QTextStream in(&file); + + QRegExp localObjectUriWithDigits(":[^ ]+_([0-9]+) a "); + + while (!in.atEnd()) { + QString line = in.readLine(); + if (line.length() > 120) { // probably data + continue; + } + if (localObjectUriWithDigits.indexIn(line) > -1) { + QString numeric = localObjectUriWithDigits.cap(1); + int number = numeric.toInt(); + if (number >= m_count) m_count = number + 1; + } + } + + file.close(); +} + +void RDFFeatureWriter::writeSignalDescription(QTextStream *sptr, QString trackId) { @@ -244,8 +278,7 @@ } } - //!!! FIX: If we are appending, we need to start counting after - //all of the existing counts that are already in the file! + // Note reviewFileForAppending above (when opening in append mode) uint64_t signalCount = m_count++; diff -r a03aafaacb5a -r 063da8955f65 rdf/RDFFeatureWriter.h --- a/rdf/RDFFeatureWriter.h Thu May 14 14:33:40 2009 +0000 +++ b/rdf/RDFFeatureWriter.h Thu May 14 15:47:16 2009 +0000 @@ -68,6 +68,8 @@ QString m_fixedEventTypeURI; + virtual void reviewFileForAppending(QString filename); + void writePrefixes(QTextStream *); void writeSignalDescription(QTextStream *, QString); void writeLocalFeatureTypes(QTextStream *,