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)
|
2013-10-29 22:20:55 +04:00
|
|
|
: PhraseDictionary(line)
|
2013-09-25 01:50:43 +04:00
|
|
|
{
|
|
|
|
ReadParameters();
|
|
|
|
}
|
|
|
|
|
2013-12-10 16:42:05 +04:00
|
|
|
void SkeletonPT::Load()
|
|
|
|
{
|
|
|
|
SetFeaturesToApply();
|
|
|
|
}
|
|
|
|
|
2014-01-14 15:08:57 +04:00
|
|
|
void SkeletonPT::InitializeForInput(InputType const& source)
|
2013-09-25 19:57:01 +04:00
|
|
|
{
|
2014-01-14 15:08:57 +04:00
|
|
|
ReduceCache();
|
2013-09-25 19:57:01 +04:00
|
|
|
}
|
|
|
|
|
2013-10-03 21:58:45 +04:00
|
|
|
void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
|
2013-09-25 01:50:43 +04:00
|
|
|
{
|
2014-01-14 15:08:57 +04:00
|
|
|
CacheColl &cache = GetCache();
|
|
|
|
|
2013-09-25 01:50:43 +04:00
|
|
|
InputPathList::const_iterator iter;
|
2013-10-03 21:58:45 +04:00
|
|
|
for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
|
2013-09-25 01:50:43 +04:00
|
|
|
InputPath &inputPath = **iter;
|
2014-01-14 15:08:57 +04:00
|
|
|
const Phrase &sourcePhrase = inputPath.GetPhrase();
|
2013-09-25 19:57:01 +04:00
|
|
|
|
2014-01-14 15:08:57 +04:00
|
|
|
TargetPhrase *tp = CreateTargetPhrase(sourcePhrase);
|
2013-09-25 19:57:01 +04:00
|
|
|
TargetPhraseCollection *tpColl = new TargetPhraseCollection();
|
|
|
|
tpColl->Add(tp);
|
|
|
|
|
2014-01-14 15:08:57 +04:00
|
|
|
// 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:'
|
2013-11-20 18:02:38 +04:00
|
|
|
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,
|
2014-03-14 12:49:09 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|