00001 /*********************************************************************** 00002 Moses - statistical machine translation system 00003 Copyright (C) 2006-2011 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 "StackVec.h" 00023 #include "ChartTranslationOptions.h" 00024 #include <vector> 00025 00026 namespace Moses 00027 { 00028 00029 class ChartCellCollection; 00030 class ChartHypothesis; 00031 class ChartManager; 00032 class TargetPhrase; 00033 00034 typedef std::vector<const ChartHypothesis*> HypoList; 00035 00039 class TranslationDimension 00040 { 00041 public: 00042 TranslationDimension(std::size_t pos, 00043 const ChartTranslationOptions::CollType &orderedTargetPhrases) 00044 : m_pos(pos) 00045 , m_orderedTargetPhrases(orderedTargetPhrases) { 00046 } 00047 00048 std::size_t IncrementPos() { 00049 return m_pos++; 00050 } 00051 00052 bool HasMoreTranslations() const { 00053 return m_pos+1 < m_orderedTargetPhrases.size(); 00054 } 00055 00056 const boost::shared_ptr<ChartTranslationOption> GetTranslationOption() const { 00057 return m_orderedTargetPhrases[m_pos]; 00058 } 00059 00060 bool operator<(const TranslationDimension &compare) const { 00061 return GetTranslationOption().get() < compare.GetTranslationOption().get(); 00062 } 00063 00064 bool operator==(const TranslationDimension &compare) const { 00065 return GetTranslationOption().get() == compare.GetTranslationOption().get(); 00066 } 00067 00068 private: 00069 std::size_t m_pos; 00070 const ChartTranslationOptions::CollType &m_orderedTargetPhrases; 00071 }; 00072 00073 00077 class HypothesisDimension 00078 { 00079 public: 00080 HypothesisDimension(std::size_t pos, const HypoList &orderedHypos) 00081 : m_pos(pos) 00082 , m_orderedHypos(&orderedHypos) { 00083 } 00084 00085 std::size_t IncrementPos() { 00086 return m_pos++; 00087 } 00088 00089 bool HasMoreHypo() const { 00090 return m_pos+1 < m_orderedHypos->size(); 00091 } 00092 00093 const ChartHypothesis *GetHypothesis() const { 00094 return (*m_orderedHypos)[m_pos]; 00095 } 00096 00097 bool operator<(const HypothesisDimension &compare) const { 00098 return GetHypothesis() < compare.GetHypothesis(); 00099 } 00100 00101 bool operator==(const HypothesisDimension &compare) const { 00102 return GetHypothesis() == compare.GetHypothesis(); 00103 } 00104 00105 private: 00106 std::size_t m_pos; 00107 const HypoList *m_orderedHypos; 00108 }; 00109 00110 std::size_t hash_value(const HypothesisDimension &); 00111 00113 class RuleCubeItem 00114 { 00115 public: 00116 RuleCubeItem(const ChartTranslationOptions &, const ChartCellCollection &); 00117 RuleCubeItem(const RuleCubeItem &, int); 00118 ~RuleCubeItem(); 00119 00120 const TranslationDimension &GetTranslationDimension() const { 00121 return m_translationDimension; 00122 } 00123 00124 const std::vector<HypothesisDimension> &GetHypothesisDimensions() const { 00125 return m_hypothesisDimensions; 00126 } 00127 00128 float GetScore() const { 00129 return m_score; 00130 } 00131 00132 void EstimateScore(); 00133 00134 void CreateHypothesis(const ChartTranslationOptions &, ChartManager &); 00135 00136 ChartHypothesis *ReleaseHypothesis(); 00137 00138 bool operator<(const RuleCubeItem &) const; 00139 00140 private: 00141 RuleCubeItem(const RuleCubeItem &); // Not implemented 00142 RuleCubeItem &operator=(const RuleCubeItem &); // Not implemented 00143 00144 void CreateHypothesisDimensions(const StackVec &); 00145 00146 TranslationDimension m_translationDimension; 00147 std::vector<HypothesisDimension> m_hypothesisDimensions; 00148 ChartHypothesis *m_hypothesis; 00149 float m_score; 00150 }; 00151 00152 }