00001 #include "InputPath.h"
00002 #include "ScoreComponentCollection.h"
00003 #include "TargetPhraseCollection.h"
00004 #include "StaticData.h"
00005 #include "TypeDef.h"
00006 #include "AlignmentInfo.h"
00007 #include "util/exception.hh"
00008 #include "TranslationModel/PhraseDictionary.h"
00009 using namespace std;
00010
00011 namespace Moses
00012 {
00013 InputPath::
00014 InputPath(TranslationTask const* theTask,
00015 Phrase const& phrase,
00016 NonTerminalSet const& sourceNonTerms,
00017 Range const& range, InputPath const *prevNode,
00018 const ScorePair *inputScore)
00019 : ttask(theTask)
00020 , m_prevPath(prevNode)
00021 , m_phrase(phrase)
00022 , m_range(range)
00023 , m_inputScore(inputScore)
00024 , m_nextNode(1)
00025 , m_sourceNonTerms(sourceNonTerms)
00026 , m_sourceNonTermArray(FactorCollection::Instance().GetNumNonTerminals(), false)
00027 {
00028 for (NonTerminalSet::const_iterator iter = sourceNonTerms.begin(); iter != sourceNonTerms.end(); ++iter) {
00029 size_t idx = (*iter)[0]->GetId();
00030 m_sourceNonTermArray[idx] = true;
00031 }
00032
00033
00034
00035 }
00036
00037 InputPath::~InputPath()
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 delete m_inputScore;
00057 }
00058
00059 TargetPhraseCollection::shared_ptr
00060 InputPath::
00061 GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
00062 {
00063 TargetPhrases::const_iterator iter;
00064 iter = m_targetPhrases.find(&phraseDictionary);
00065 if (iter == m_targetPhrases.end()) {
00066 return TargetPhraseCollection::shared_ptr();
00067 }
00068 return iter->second.first;
00069 }
00070
00071 const void*
00072 InputPath::
00073 GetPtNode(const PhraseDictionary &phraseDictionary) const
00074 {
00075 TargetPhrases::const_iterator iter;
00076 iter = m_targetPhrases.find(&phraseDictionary);
00077 if (iter == m_targetPhrases.end()) {
00078 return NULL;
00079 }
00080 return iter->second.second;
00081 }
00082
00083 void
00084 InputPath::
00085 SetTargetPhrases(const PhraseDictionary &phraseDictionary,
00086 TargetPhraseCollection::shared_ptr const& targetPhrases,
00087 const void *ptNode)
00088 {
00089 std::pair<TargetPhraseCollection::shared_ptr, const void*>
00090 value(targetPhrases, ptNode);
00091 m_targetPhrases[&phraseDictionary] = value;
00092 }
00093
00094 const Word &InputPath::GetLastWord() const
00095 {
00096 size_t len = m_phrase.GetSize();
00097 UTIL_THROW_IF2(len == 0, "Input path phrase cannot be empty");
00098 const Word &ret = m_phrase.GetWord(len - 1);
00099 return ret;
00100 }
00101
00102 size_t InputPath::GetTotalRuleSize() const
00103 {
00104 size_t ret = 0;
00105 TargetPhrases::const_iterator iter;
00106 for (iter = m_targetPhrases.begin(); iter != m_targetPhrases.end(); ++iter) {
00107
00108 TargetPhraseCollection::shared_ptr tpColl = iter->second.first;
00109
00110 if (tpColl) {
00111 ret += tpColl->GetSize();
00112 }
00113 }
00114
00115 return ret;
00116 }
00117
00118 std::ostream& operator<<(std::ostream& out, const InputPath& obj)
00119 {
00120 out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevPath() << " " << obj.GetPhrase();
00121
00122 InputPath::TargetPhrases::const_iterator iter;
00123 for (iter = obj.m_targetPhrases.begin(); iter != obj.m_targetPhrases.end(); ++iter) {
00124 const PhraseDictionary *pt = iter->first;
00125 boost::shared_ptr<TargetPhraseCollection const> tpColl = iter->second.first;
00126
00127 out << pt << "=";
00128 if (tpColl) {
00129 cerr << tpColl->GetSize() << " ";
00130 } else {
00131 cerr << "NULL ";
00132 }
00133 }
00134
00135 return out;
00136 }
00137
00138 }