00001 /*********************************************************************** 00002 Moses - factored phrase-based language decoder 00003 Copyright (C) 2006 University of Edinburgh 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ***********************************************************************/ 00019 00020 #pragma once 00021 00022 #include "ChartTranslationOptions.h" 00023 #include "ChartParserCallback.h" 00024 #include "StackVec.h" 00025 00026 #include <vector> 00027 00028 namespace Moses 00029 { 00030 00031 class TargetPhraseCollection; 00032 class Range; 00033 class InputType; 00034 class InputPath; 00035 class ChartCellLabel; 00036 00038 class ChartTranslationOptionList : public ChartParserCallback 00039 { 00040 friend std::ostream& operator<<(std::ostream&, const ChartTranslationOptionList&); 00041 00042 public: 00043 ChartTranslationOptionList(size_t ruleLimit, const InputType &input); 00044 ~ChartTranslationOptionList(); 00045 00046 const ChartTranslationOptions &Get(size_t i) const { 00047 return *m_collection[i]; 00048 } 00049 00051 size_t GetSize() const { 00052 return m_size; 00053 } 00054 00055 void Add(const TargetPhraseCollection &, const StackVec &, 00056 const Range &); 00057 00058 void AddPhraseOOV(TargetPhrase &phrase, std::list<TargetPhraseCollection::shared_ptr > &waste_memory, const Range &range); 00059 00060 bool Empty() const { 00061 return m_size == 0; 00062 } 00063 00064 float GetBestScore(const ChartCellLabel *chartCell) const; 00065 00066 void Clear(); 00067 void ApplyThreshold(float threshold); 00068 void EvaluateWithSourceContext(const InputType &input, const InputPath &inputPath); 00069 00070 private: 00071 typedef std::vector<ChartTranslationOptions*> CollType; 00072 00073 struct ScoreThresholdPred { 00074 ScoreThresholdPred(float threshold) : m_thresholdScore(threshold) {} 00075 bool operator()(const ChartTranslationOptions *option) { 00076 return option->GetEstimateOfBestScore() >= m_thresholdScore; 00077 } 00078 float m_thresholdScore; 00079 }; 00080 00081 void SwapTranslationOptions(size_t a, size_t b); 00082 00083 CollType m_collection; 00084 size_t m_size; 00085 float m_scoreThreshold; 00086 const size_t m_ruleLimit; 00087 00088 }; 00089 00090 }