mosesdecoder/moses/TranslationModel/SkeletonPT.cpp

86 lines
2.2 KiB
C++
Raw Normal View History

2013-09-25 01:50:43 +04:00
// vim:tabstop=2
#include "SkeletonPT.h"
2013-09-25 23:59:13 +04:00
#include "moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h"
2013-09-25 01:50:43 +04:00
using namespace std;
namespace Moses
{
SkeletonPT::SkeletonPT(const std::string &line)
: PhraseDictionary(line)
2013-09-25 01:50:43 +04:00
{
ReadParameters();
}
void SkeletonPT::Load()
{
SetFeaturesToApply();
}
void SkeletonPT::InitializeForInput(InputType const& source)
2013-09-25 19:57:01 +04:00
{
ReduceCache();
2013-09-25 19:57:01 +04:00
}
void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
2013-09-25 01:50:43 +04:00
{
CacheColl &cache = GetCache();
2013-09-25 01:50:43 +04:00
InputPathList::const_iterator iter;
for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
2013-09-25 01:50:43 +04:00
InputPath &inputPath = **iter;
const Phrase &sourcePhrase = inputPath.GetPhrase();
2013-09-25 19:57:01 +04:00
TargetPhrase *tp = CreateTargetPhrase(sourcePhrase);
2013-09-25 19:57:01 +04:00
TargetPhraseCollection *tpColl = new TargetPhraseCollection();
tpColl->Add(tp);
// add target phrase to phrase-table cache
size_t hash = hash_value(sourcePhrase);
std::pair<const TargetPhraseCollection*, clock_t> value(tpColl, clock());
cache[hash] = value;
2013-09-25 19:57:01 +04:00
inputPath.SetTargetPhrases(*this, tpColl, NULL);
2013-09-25 01:50:43 +04:00
}
}
2013-09-25 19:57:01 +04:00
TargetPhrase *SkeletonPT::CreateTargetPhrase(const Phrase &sourcePhrase) const
{
2013-09-27 12:35:24 +04:00
// create a target phrase from the 1st word of the source, prefix with 'SkeletonPT:'
assert(sourcePhrase.GetSize());
assert(m_output.size() == 1);
2013-09-25 22:24:50 +04:00
2013-09-27 12:35:24 +04:00
string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string();
str = "SkeletonPT:" + str;
2013-09-25 19:57:01 +04:00
2013-09-27 12:35:24 +04:00
TargetPhrase *tp = new TargetPhrase();
Word &word = tp->AddWord();
word.CreateFromString(Output, m_output, str, false);
2013-09-25 19:57:01 +04:00
2013-09-27 12:35:24 +04:00
// score for this phrase table
vector<float> scores(m_numScoreComponents, 1.3);
tp->GetScoreBreakdown().PlusEquals(this, scores);
2013-09-25 19:57:01 +04:00
2013-09-27 12:35:24 +04:00
// score of all other ff when this rule is being loaded
tp->Evaluate(sourcePhrase, GetFeaturesToApply());
2013-09-25 19:57:01 +04:00
2013-09-27 12:35:24 +04:00
return tp;
2013-09-25 19:57:01 +04:00
}
2013-09-25 23:59:13 +04:00
ChartRuleLookupManager* SkeletonPT::CreateRuleLookupManager(const ChartParser &parser,
const ChartCellCollectionBase &cellCollection,
std::size_t /*maxChartSpan*/)
2013-09-25 01:50:43 +04:00
{
2013-09-25 23:59:13 +04:00
return new ChartRuleLookupManagerSkeleton(parser, cellCollection, *this);
2013-09-25 01:50:43 +04:00
}
TO_STRING_BODY(SkeletonPT);
// friend
ostream& operator<<(ostream& out, const SkeletonPT& phraseDict)
{
return out;
}
}