// // Copyright RIME Developers // Distributed under the BSD License // // simplistic sentence-making // // 2011-10-06 GONG Chen // #ifndef RIME_POET_H_ #define RIME_POET_H_ #include #include #include #include namespace rime { using WordGraph = map>; class Grammar; class Language; struct Line; class Poet { public: // Line "less", used to compare composed line of the same input range. using Compare = function; static bool CompareWeight(const Line& one, const Line& other); static bool LeftAssociateCompare(const Line& one, const Line& other); Poet(const Language* language, Config* config, Compare compare = CompareWeight); ~Poet(); an MakeSentence(const WordGraph& graph, size_t total_length, const string& preceding_text); deque> MakeSentences(const WordGraph& graph, size_t total_length, const string& preceding_text, size_t count, double cutoff_threshold); template an ContextualWeighted(an translation, const string& input, size_t start, TranslatorT* translator) { if (!translator->contextual_suggestions() || !grammar_) { return translation; } auto preceding_text = translator->GetPrecedingText(start); if (preceding_text.empty()) { return translation; } return New(translation, input, preceding_text, grammar_.get()); } private: template an MakeSentenceWithStrategy(const WordGraph& graph, size_t total_length, const string& preceding_text); const Language* language_; the grammar_; Compare compare_; }; } // namespace rime #endif // RIME_POET_H_