separate out InputPath

This commit is contained in:
Hieu Hoang 2016-02-29 21:41:52 +00:00
parent 2c0290e9e0
commit ff17678195
2 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,52 @@
/*
* InputPath.cpp
*
* Created on: 23 Oct 2015
* Author: hieu
*/
#include <boost/foreach.hpp>
#include "InputPath.h"
#include "../TranslationModel/PhraseTable.h"
namespace Moses2
{
InputPath::InputPath(MemPool &pool,
const SubPhrase &subPhrase,
const Range &range,
size_t numPt,
const InputPath *prefixPath)
:InputPathBase(pool, subPhrase, range, numPt, prefixPath)
,m_isUsed(false)
{
targetPhrases = pool.Allocate<const TargetPhrases*>(numPt);
Init<const TargetPhrases*>(targetPhrases, numPt, NULL);
}
InputPath::~InputPath() {
// TODO Auto-generated destructor stub
}
void InputPath::AddTargetPhrases(const PhraseTable &pt, const TargetPhrases *tps)
{
size_t ptInd = pt.GetPtInd();
targetPhrases[ptInd] = tps;
if (tps && tps->GetSize()) {
m_isUsed = true;
}
}
const TargetPhrases *InputPath::GetTargetPhrases(const PhraseTable &pt) const
{
size_t ptInd = pt.GetPtInd();
return targetPhrases[ptInd];
}
std::ostream& operator<<(std::ostream &out, const InputPath &obj)
{
out << obj.range << " " << obj.subPhrase;
return out;
}
}

View File

@ -0,0 +1,38 @@
/*
* InputPath.h
*
* Created on: 23 Oct 2015
* Author: hieu
*/
#ifndef INPUTPATH_H_
#define INPUTPATH_H_
#include <iostream>
#include <vector>
#include "../InputPathBase.h"
namespace Moses2
{
class InputPath : public InputPathBase
{
friend std::ostream& operator<<(std::ostream &, const InputPath &);
public:
const TargetPhrases** targetPhrases;
InputPath(MemPool &pool, const SubPhrase &subPhrase, const Range &range, size_t numPt, const InputPath *prefixPath);
virtual ~InputPath();
void AddTargetPhrases(const PhraseTable &pt, const TargetPhrases *tps);
const TargetPhrases *GetTargetPhrases(const PhraseTable &pt) const;
inline bool IsUsed() const
{ return m_isUsed; }
protected:
bool m_isUsed;
};
}
#endif /* INPUTPATH_H_ */