2013-07-07 01:42:52 +04:00
|
|
|
#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"
|
2013-11-19 21:23:19 +04:00
|
|
|
#include "util/exception.hh"
|
2014-03-24 14:55:47 +04:00
|
|
|
#include "TranslationModel/PhraseDictionary.h"
|
2013-07-19 18:38:13 +04:00
|
|
|
using namespace std;
|
2013-07-09 18:48:36 +04:00
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2013-09-27 12:35:24 +04:00
|
|
|
InputPath::
|
2015-12-12 19:23:37 +03:00
|
|
|
InputPath(TranslationTask const* theTask,
|
2015-10-19 02:00:40 +03:00
|
|
|
Phrase const& phrase,
|
|
|
|
NonTerminalSet const& sourceNonTerms,
|
2015-10-25 16:37:59 +03:00
|
|
|
Range const& range, InputPath const *prevNode,
|
2013-09-27 12:35:24 +04:00
|
|
|
const ScorePair *inputScore)
|
2015-10-19 02:00:40 +03:00
|
|
|
: ttask(theTask)
|
2015-10-17 18:36:21 +03:00
|
|
|
, m_prevPath(prevNode)
|
|
|
|
, m_phrase(phrase)
|
|
|
|
, m_range(range)
|
|
|
|
, m_inputScore(inputScore)
|
|
|
|
, m_nextNode(1)
|
|
|
|
, m_sourceNonTerms(sourceNonTerms)
|
|
|
|
, m_sourceNonTermArray(FactorCollection::Instance().GetNumNonTerminals(), false)
|
2013-07-09 01:47:02 +04:00
|
|
|
{
|
2014-03-21 14:53:15 +04:00
|
|
|
for (NonTerminalSet::const_iterator iter = sourceNonTerms.begin(); iter != sourceNonTerms.end(); ++iter) {
|
|
|
|
size_t idx = (*iter)[0]->GetId();
|
|
|
|
m_sourceNonTermArray[idx] = true;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2015-10-19 02:00:40 +03:00
|
|
|
|
2015-10-17 18:36:21 +03:00
|
|
|
// std::cerr << "Deconstructing InputPath" << std::endl;
|
|
|
|
|
2015-10-18 23:27:58 +03:00
|
|
|
|
|
|
|
// // NOT NEEDED ANY MORE SINCE THE SWITCH TO SHARED POINTERS
|
|
|
|
// // Since there is no way for the Phrase Dictionaries to tell in
|
|
|
|
// // which (sentence) context phrases were looked up, we tell them
|
|
|
|
// // now that the phrase isn't needed any more by this inputPath
|
|
|
|
// typedef std::pair<boost::shared_ptr<TargetPhraseCollection>, const void* > entry;
|
|
|
|
// std::map<const PhraseDictionary*, entry>::iterator iter;
|
|
|
|
// ttasksptr theTask = this->ttask.lock();
|
|
|
|
// for (iter = m_targetPhrases.begin(); iter != m_targetPhrases.end(); ++iter)
|
|
|
|
// {
|
|
|
|
// // std::cerr << iter->second.first << " decommissioned." << std::endl;
|
|
|
|
// iter->first->Release(theTask, iter->second.first);
|
|
|
|
// }
|
2014-05-19 17:34:27 +04:00
|
|
|
|
2013-07-09 01:47:02 +04:00
|
|
|
delete m_inputScore;
|
|
|
|
}
|
|
|
|
|
2015-10-18 23:27:58 +03:00
|
|
|
TargetPhraseCollection::shared_ptr
|
|
|
|
InputPath::
|
|
|
|
GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
|
2013-07-02 02:27:13 +04:00
|
|
|
{
|
2015-10-18 23:27:58 +03:00
|
|
|
TargetPhrases::const_iterator iter;
|
2013-07-02 02:27:13 +04:00
|
|
|
iter = m_targetPhrases.find(&phraseDictionary);
|
2013-07-04 12:24:13 +04:00
|
|
|
if (iter == m_targetPhrases.end()) {
|
2015-10-18 23:27:58 +03:00
|
|
|
return TargetPhraseCollection::shared_ptr();
|
2013-07-04 12:24:13 +04:00
|
|
|
}
|
2013-07-02 02:27:13 +04:00
|
|
|
return iter->second.first;
|
|
|
|
}
|
|
|
|
|
2015-10-18 23:27:58 +03:00
|
|
|
const void*
|
|
|
|
InputPath::
|
|
|
|
GetPtNode(const PhraseDictionary &phraseDictionary) const
|
2013-07-03 22:07:36 +04:00
|
|
|
{
|
2015-10-18 23:27:58 +03:00
|
|
|
TargetPhrases::const_iterator iter;
|
2013-07-03 22:07:36 +04:00
|
|
|
iter = m_targetPhrases.find(&phraseDictionary);
|
2013-07-04 12:24:13 +04:00
|
|
|
if (iter == m_targetPhrases.end()) {
|
2013-07-05 02:38:18 +04:00
|
|
|
return NULL;
|
2013-07-04 12:24:13 +04:00
|
|
|
}
|
2013-07-03 22:07:36 +04:00
|
|
|
return iter->second.second;
|
|
|
|
}
|
|
|
|
|
2015-10-19 02:00:40 +03:00
|
|
|
void
|
2015-10-18 23:27:58 +03:00
|
|
|
InputPath::
|
2015-10-19 02:00:40 +03:00
|
|
|
SetTargetPhrases(const PhraseDictionary &phraseDictionary,
|
|
|
|
TargetPhraseCollection::shared_ptr const& targetPhrases,
|
|
|
|
const void *ptNode)
|
2013-07-19 16:58:39 +04:00
|
|
|
{
|
2015-10-19 02:00:40 +03:00
|
|
|
std::pair<TargetPhraseCollection::shared_ptr, const void*>
|
|
|
|
value(targetPhrases, ptNode);
|
2013-07-26 22:39:10 +04:00
|
|
|
m_targetPhrases[&phraseDictionary] = value;
|
2013-07-19 18:38:13 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 18:28:20 +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");
|
2013-07-30 18:28:20 +04:00
|
|
|
const Word &ret = m_phrase.GetWord(len - 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-30 23:20:07 +04:00
|
|
|
size_t InputPath::GetTotalRuleSize() const
|
|
|
|
{
|
|
|
|
size_t ret = 0;
|
2015-10-18 23:27:58 +03:00
|
|
|
TargetPhrases::const_iterator iter;
|
2014-04-30 23:47:58 +04:00
|
|
|
for (iter = m_targetPhrases.begin(); iter != m_targetPhrases.end(); ++iter) {
|
2014-06-05 04:40:51 +04:00
|
|
|
// const PhraseDictionary *pt = iter->first;
|
2015-10-18 23:27:58 +03:00
|
|
|
TargetPhraseCollection::shared_ptr tpColl = iter->second.first;
|
2014-04-30 23:20:07 +04:00
|
|
|
|
2014-06-08 11:44:59 +04:00
|
|
|
if (tpColl) {
|
|
|
|
ret += tpColl->GetSize();
|
|
|
|
}
|
2014-04-30 23:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-07 05:14:51 +04:00
|
|
|
std::ostream& operator<<(std::ostream& out, const InputPath& obj)
|
2013-07-03 22:07:36 +04:00
|
|
|
{
|
2013-10-02 19:51:16 +04:00
|
|
|
out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevPath() << " " << obj.GetPhrase();
|
2013-07-04 12:24:13 +04:00
|
|
|
|
2015-10-18 23:27:58 +03:00
|
|
|
InputPath::TargetPhrases::const_iterator iter;
|
2013-07-05 02:38:18 +04:00
|
|
|
for (iter = obj.m_targetPhrases.begin(); iter != obj.m_targetPhrases.end(); ++iter) {
|
|
|
|
const PhraseDictionary *pt = iter->first;
|
2015-10-18 23:27:58 +03:00
|
|
|
boost::shared_ptr<TargetPhraseCollection const> tpColl = iter->second.first;
|
2014-04-30 23:20:07 +04:00
|
|
|
|
|
|
|
out << pt << "=";
|
|
|
|
if (tpColl) {
|
2014-06-08 11:44:59 +04:00
|
|
|
cerr << tpColl->GetSize() << " ";
|
|
|
|
} else {
|
|
|
|
cerr << "NULL ";
|
2014-04-30 23:20:07 +04:00
|
|
|
}
|
2013-07-05 02:38:18 +04:00
|
|
|
}
|
2013-07-04 12:24:13 +04:00
|
|
|
|
2013-07-05 02:38:18 +04:00
|
|
|
return out;
|
2013-07-03 22:07:36 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
}
|