.. _program_listing_file_src_translator_output_collector.h: Program Listing for File output_collector.h =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/translator/output_collector.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "common/definitions.h" #include "common/file_stream.h" #include #include #include namespace marian { class PrintingStrategy { public: virtual ~PrintingStrategy() {} virtual bool shouldBePrinted(long) = 0; }; class DefaultPrinting : public PrintingStrategy { public: bool shouldBePrinted(long) override { return true; } }; class QuietPrinting : public PrintingStrategy { public: bool shouldBePrinted(long) override { return false; } }; class GeometricPrinting : public PrintingStrategy { public: bool shouldBePrinted(long id) override { if(id == 0) next_ = (long)start_; if(id <= 5) return true; if(next_ == id) { next_ += next_; return true; } return false; } private: size_t start_{10}; long next_{10}; }; class OutputCollector { public: OutputCollector(); OutputCollector(std::string outFile); template OutputCollector(T&& arg) : nextId_(0), outStrm_(new io::OutputFileStream(arg)) {} OutputCollector(const OutputCollector&) = delete; void Write(long sourceId, const std::string& best1, const std::string& bestn, bool nbest); void setPrintingStrategy(Ptr strategy) { printing_ = strategy; } protected: typedef std::map> Outputs; Outputs outputs_; long nextId_; UPtr outStrm_; Ptr printing_; std::mutex mutex_; }; class StringCollector { public: StringCollector(bool quiet = false); StringCollector(const StringCollector&) = delete; void add(long sourceId, const std::string& best1, const std::string& bestn); std::vector collect(bool nbest); protected: long maxId_; // the largest index of the translated source sentences bool quiet_; // if true do not log best translations std::mutex mutex_; typedef std::map> Outputs; Outputs outputs_; }; } // namespace marian