mosesdecoder/moses/InputPath.cpp

84 lines
2.4 KiB
C++
Raw Normal View History

#include "InputPath.h"
2013-07-09 01:47:02 +04:00
#include "ScoreComponentCollection.h"
2013-07-18 23:39:15 +04:00
#include "TargetPhraseCollection.h"
2013-07-19 02:09:33 +04:00
#include "StaticData.h"
#include "TypeDef.h"
2013-07-19 18:38:13 +04:00
#include "AlignmentInfo.h"
#include "util/exception.hh"
2013-07-19 18:38:13 +04:00
using namespace std;
namespace Moses
{
2013-09-27 12:35:24 +04:00
InputPath::
InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms,
const WordsRange &range, const InputPath *prevNode,
const ScorePair *inputScore)
2013-10-02 19:51:16 +04:00
:m_prevPath(prevNode)
2013-07-09 01:47:02 +04:00
,m_phrase(phrase)
,m_range(range)
,m_inputScore(inputScore)
,m_sourceNonTerms(sourceNonTerms)
2013-10-02 19:51:16 +04:00
,m_nextNode(1)
2013-07-09 01:47:02 +04:00
{
2013-09-10 17:36:21 +04:00
//cerr << "phrase=" << phrase << " m_inputScore=" << *m_inputScore << endl;
2013-07-09 01:47:02 +04:00
}
InputPath::~InputPath()
{
delete m_inputScore;
}
2013-07-07 05:14:51 +04:00
const TargetPhraseCollection *InputPath::GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
{
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> >::const_iterator iter;
iter = m_targetPhrases.find(&phraseDictionary);
if (iter == m_targetPhrases.end()) {
2013-07-05 02:38:18 +04:00
return NULL;
}
return iter->second.first;
}
2013-07-07 05:14:51 +04:00
const void *InputPath::GetPtNode(const PhraseDictionary &phraseDictionary) const
{
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> >::const_iterator iter;
iter = m_targetPhrases.find(&phraseDictionary);
if (iter == m_targetPhrases.end()) {
2013-07-05 02:38:18 +04:00
return NULL;
}
return iter->second.second;
}
2013-07-18 23:23:44 +04:00
void InputPath::SetTargetPhrases(const PhraseDictionary &phraseDictionary
2013-07-19 16:58:39 +04:00
, const TargetPhraseCollection *targetPhrases
, const void *ptNode)
{
std::pair<const TargetPhraseCollection*, const void*> value(targetPhrases, ptNode);
m_targetPhrases[&phraseDictionary] = value;
2013-07-19 18:38:13 +04:00
}
const Word &InputPath::GetLastWord() const
{
size_t len = m_phrase.GetSize();
2013-11-23 00:27:46 +04:00
UTIL_THROW_IF2(len == 0, "Input path phrase cannot be empty");
const Word &ret = m_phrase.GetWord(len - 1);
return ret;
}
2013-07-07 05:14:51 +04:00
std::ostream& operator<<(std::ostream& out, const InputPath& obj)
{
2013-10-02 19:51:16 +04:00
out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevPath() << " " << obj.GetPhrase();
2013-07-05 02:38:18 +04:00
out << "pt: ";
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> >::const_iterator iter;
for (iter = obj.m_targetPhrases.begin(); iter != obj.m_targetPhrases.end(); ++iter) {
const PhraseDictionary *pt = iter->first;
out << pt << " ";
}
2013-07-05 02:38:18 +04:00
return out;
}
}