00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #ifndef moses_TrellisPath_h 00023 #define moses_TrellisPath_h 00024 00025 #include <iostream> 00026 #include <vector> 00027 #include <limits> 00028 #include "Hypothesis.h" 00029 #include "TypeDef.h" 00030 00031 namespace Moses 00032 { 00033 00034 class TrellisPathCollection; 00035 class TrellisPathList; 00036 00041 class TrellisPath 00042 { 00043 friend std::ostream& operator<<(std::ostream&, const TrellisPath&); 00044 friend class Manager; 00045 00046 protected: 00047 std::vector<const Hypothesis *> m_path; //< list of hypotheses/arcs 00048 size_t m_prevEdgeChanged; 00052 ScoreComponentCollection m_scoreBreakdown; 00053 float m_totalScore; 00054 00055 //Used by Manager::LatticeSample() 00056 TrellisPath(const std::vector<const Hypothesis*> edges); 00057 00058 void InitScore(); 00059 00060 public: 00061 00062 TrellisPath(); // not implemented 00063 00065 TrellisPath(const Hypothesis *hypo); 00066 00070 TrellisPath(const TrellisPath ©, size_t edgeIndex, const Hypothesis *arc); 00071 00073 inline float GetTotalScore() const { 00074 return m_totalScore; 00075 } 00076 00080 inline const std::vector<const Hypothesis *> &GetEdges() const { 00081 return m_path; 00082 } 00083 00085 void CreateDeviantPaths(TrellisPathCollection &pathColl) const; 00086 00088 void CreateDeviantPaths(TrellisPathList &pathColl) const; 00089 00090 inline const ScoreComponentCollection &GetScoreBreakdown() const { 00091 return m_scoreBreakdown; 00092 } 00093 00095 WordsRange GetTargetWordsRange(const Hypothesis &hypo) const; 00096 00097 Phrase GetTargetPhrase() const; 00098 Phrase GetSurfacePhrase() const; 00099 00100 TO_STRING(); 00101 00102 }; 00103 00104 // friend 00105 inline std::ostream& operator<<(std::ostream& out, const TrellisPath& path) 00106 { 00107 const size_t sizePath = path.m_path.size(); 00108 for (int pos = (int) sizePath - 1 ; pos >= 0 ; pos--) { 00109 const Hypothesis *edge = path.m_path[pos]; 00110 const WordsRange &sourceRange = edge->GetCurrSourceWordsRange(); 00111 out << edge->GetId() << " " << sourceRange.GetStartPos() << "-" << sourceRange.GetEndPos() << ", "; 00112 } 00113 // scores 00114 out << " total=" << path.GetTotalScore() 00115 << " " << path.GetScoreBreakdown() 00116 << std::endl; 00117 00118 return out; 00119 } 00120 00121 } 00122 #endif
1.5.9