annotate rdf/RDFFeatureWriter.h @ 1569:c2c8e071e24f

Comment
author Chris Cannam
date Wed, 07 Nov 2018 15:46:20 +0000
parents c8e291700c0e
children c01cbe41aeb5
rev   line source
Chris@498 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@498 2
Chris@498 3 /*
Chris@498 4 Sonic Visualiser
Chris@498 5 An audio file viewer and annotation editor.
Chris@498 6
Chris@498 7 Sonic Annotator
Chris@498 8 A utility for batch feature extraction from audio files.
Chris@498 9
Chris@498 10 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
Chris@498 11 Copyright 2007-2008 QMUL.
Chris@498 12
Chris@498 13 This program is free software; you can redistribute it and/or
Chris@498 14 modify it under the terms of the GNU General Public License as
Chris@498 15 published by the Free Software Foundation; either version 2 of the
Chris@498 16 License, or (at your option) any later version. See the file
Chris@498 17 COPYING included with this distribution for more information.
Chris@498 18 */
Chris@498 19
Chris@498 20 #ifndef _RDF_FEATURE_WRITER_H_
Chris@498 21 #define _RDF_FEATURE_WRITER_H_
Chris@498 22
Chris@498 23 #include <string>
Chris@498 24 #include <map>
Chris@498 25 #include <set>
Chris@498 26
Chris@498 27 #include <QString>
Chris@498 28
Chris@498 29 #include "transform/FileFeatureWriter.h"
Chris@498 30
Chris@498 31 #include "PluginRDFDescription.h"
Chris@498 32
Chris@498 33 using std::string;
Chris@498 34 using std::map;
Chris@498 35 using std::set;
Chris@498 36 using std::pair;
Chris@498 37
Chris@498 38 class QTextStream;
Chris@498 39 class QFile;
Chris@498 40
Chris@498 41 class RDFFeatureWriter : public FileFeatureWriter
Chris@498 42 {
Chris@498 43 public:
Chris@498 44 RDFFeatureWriter();
Chris@498 45 virtual ~RDFFeatureWriter();
Chris@498 46
Chris@998 47 virtual string getDescription() const;
Chris@998 48
Chris@498 49 virtual ParameterList getSupportedParameters() const;
Chris@498 50 virtual void setParameters(map<string, string> &params);
Chris@498 51
Chris@504 52 virtual void setTrackMetadata(QString trackid, TrackMetadata metadata);
Chris@504 53
Chris@498 54 virtual void write(QString trackid,
Chris@498 55 const Transform &transform,
Chris@498 56 const Vamp::Plugin::OutputDescriptor &output,
Chris@498 57 const Vamp::Plugin::FeatureList &features,
Chris@498 58 std::string summaryType = "");
Chris@498 59
Chris@510 60 virtual void setFixedEventTypeURI(QString uri); // something of a hack
Chris@510 61
Chris@498 62 virtual void finish();
Chris@498 63
Chris@605 64 virtual QString getWriterTag() const { return "rdf"; }
Chris@605 65
Chris@498 66 private:
Chris@498 67 typedef map<QString, PluginRDFDescription> RDFDescriptionMap; // by plugin id
Chris@498 68 RDFDescriptionMap m_rdfDescriptions;
Chris@498 69
Chris@504 70 typedef map<QString, TrackMetadata> TrackMetadataMap;
Chris@504 71 TrackMetadataMap m_metadata;
Chris@504 72
Chris@1144 73 bool haveTitleArtistMetadata(QString trackId) const {
Chris@1144 74 // Formerly in various places we used to test whether a track
Chris@1144 75 // appeared in the metadata map at all, in order to determine
Chris@1144 76 // whether it had any associated metadata. That won't work any
Chris@1144 77 // more because metadata now includes duration, which can
Chris@1144 78 // appear even if no title/artist are given and which is not
Chris@1144 79 // something whose presence indicates the involvement of a
Chris@1144 80 // "publication Track". So check for artist/title explicitly.
Chris@1144 81 auto mitr = m_metadata.find(trackId);
Chris@1144 82 if (mitr == m_metadata.end()) return false;
Chris@1144 83 return (mitr->second.title != "" || mitr->second.maker != "");
Chris@1144 84 }
Chris@1144 85
Chris@510 86 QString m_fixedEventTypeURI;
Chris@510 87
Chris@590 88 virtual void reviewFileForAppending(QString filename);
Chris@590 89
Chris@498 90 void writePrefixes(QTextStream *);
Chris@498 91 void writeSignalDescription(QTextStream *, QString);
Chris@498 92 void writeLocalFeatureTypes(QTextStream *,
Chris@498 93 const Transform &,
Chris@498 94 const Vamp::Plugin::OutputDescriptor &,
Chris@730 95 PluginRDFDescription &,
Chris@730 96 std::string summaryType);
Chris@498 97
Chris@498 98 void writeSparseRDF(QTextStream *stream,
Chris@498 99 const Transform &transform,
Chris@498 100 const Vamp::Plugin::OutputDescriptor &output,
Chris@498 101 const Vamp::Plugin::FeatureList &features,
Chris@498 102 PluginRDFDescription &desc,
Chris@498 103 QString timelineURI);
Chris@498 104
Chris@507 105 void writeTrackLevelRDF(QTextStream *stream,
Chris@507 106 const Transform &transform,
Chris@507 107 const Vamp::Plugin::OutputDescriptor &output,
Chris@507 108 const Vamp::Plugin::FeatureList &features,
Chris@507 109 PluginRDFDescription &desc,
Chris@507 110 QString signalURI);
Chris@507 111
Chris@498 112 void writeDenseRDF(QTextStream *stream,
Chris@498 113 const Transform &transform,
Chris@498 114 const Vamp::Plugin::OutputDescriptor &output,
Chris@498 115 const Vamp::Plugin::FeatureList &features,
Chris@498 116 PluginRDFDescription &desc,
Chris@498 117 QString signalURI,
Chris@498 118 QString timelineURI);
Chris@498 119
Chris@498 120 set<QString> m_startedTrackIds;
Chris@498 121
Chris@498 122 map<QTextStream *, set<Transform> > m_startedStreamTransforms;
Chris@498 123
Chris@585 124 map<QString, QString> m_trackTrackURIs;
Chris@498 125 map<QString, QString> m_trackTimelineURIs;
Chris@498 126 map<QString, QString> m_trackSignalURIs;
Chris@498 127
Chris@498 128 map<Transform, QString> m_transformURIs;
Chris@498 129 map<Transform, QString> m_syntheticEventTypeURIs;
Chris@498 130 map<Transform, QString> m_syntheticSignalTypeURIs;
Chris@498 131
Chris@498 132 typedef pair<QString, Transform> StringTransformPair;
Chris@498 133 typedef pair<QTextStream *, QString> StreamBuffer;
Chris@498 134 map<StringTransformPair, StreamBuffer> m_openDenseFeatures; // signal URI + transform -> stream + text
Chris@594 135 QString m_userAudioFileUri;
Chris@594 136 QString m_userTrackUri;
Chris@594 137 QString m_userMakerUri;
Chris@498 138
Chris@498 139 bool m_plain;
Chris@498 140
Chris@597 141 bool m_network;
Chris@597 142 bool m_networkRetrieved;
Chris@597 143
Chris@930 144 long m_count;
Chris@498 145 };
Chris@498 146
Chris@498 147 #endif