2015-10-23 22:53:36 +03:00
|
|
|
/*
|
|
|
|
* TargetPhrase.cpp
|
|
|
|
*
|
|
|
|
* Created on: 23 Oct 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "TargetPhrase.h"
|
|
|
|
#include "Scores.h"
|
2015-10-26 00:20:55 +03:00
|
|
|
#include "System.h"
|
2015-10-28 19:11:12 +03:00
|
|
|
#include "MemPool.h"
|
2015-11-03 16:24:39 +03:00
|
|
|
#include "Search/Manager.h"
|
2015-10-23 22:53:36 +03:00
|
|
|
|
2015-10-24 04:02:50 +03:00
|
|
|
using namespace std;
|
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2016-01-21 14:22:55 +03:00
|
|
|
TargetPhrase *TargetPhrase::CreateFromString(MemPool &pool, const PhraseTable &pt, const System &system, const std::string &str)
|
2015-10-23 22:53:36 +03:00
|
|
|
{
|
2015-11-18 18:33:42 +03:00
|
|
|
FactorCollection &vocab = system.GetVocab();
|
2015-10-26 17:58:59 +03:00
|
|
|
|
2015-11-12 02:28:18 +03:00
|
|
|
vector<string> toks = Tokenize(str);
|
2015-10-24 04:02:50 +03:00
|
|
|
size_t size = toks.size();
|
2016-01-21 14:22:55 +03:00
|
|
|
TargetPhrase *ret = new (pool.Allocate<TargetPhrase>()) TargetPhrase(pool, pt, system, size);
|
2016-02-22 21:32:59 +03:00
|
|
|
ret->PhraseImplTemplate<Word>::CreateFromString(vocab, system, toks);
|
2015-10-23 22:53:36 +03:00
|
|
|
|
2015-10-24 04:02:50 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-21 14:22:55 +03:00
|
|
|
TargetPhrase::TargetPhrase(MemPool &pool, const PhraseTable &pt, const System &system, size_t size)
|
2016-02-23 21:32:24 +03:00
|
|
|
:TPBase(pool, pt, system)
|
|
|
|
,PhraseImplTemplate(pool, size)
|
2015-12-28 23:07:47 +03:00
|
|
|
,scoreProperties(NULL)
|
2015-10-24 04:02:50 +03:00
|
|
|
{
|
2015-12-01 02:03:33 +03:00
|
|
|
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool, system.featureFunctions.GetNumScores());
|
2015-12-17 20:08:49 +03:00
|
|
|
|
|
|
|
size_t numWithPtData = system.featureFunctions.GetWithPhraseTableInd().size();
|
|
|
|
ffData = new (pool.Allocate<void *>(numWithPtData)) void *[numWithPtData];
|
2015-10-23 22:53:36 +03:00
|
|
|
}
|
|
|
|
|
2016-01-21 14:22:55 +03:00
|
|
|
/*
|
2015-12-07 19:49:02 +03:00
|
|
|
TargetPhrase::TargetPhrase(MemPool &pool, const System &system, const TargetPhrase ©)
|
|
|
|
:PhraseImpl(pool, copy)
|
2015-12-28 23:07:47 +03:00
|
|
|
,scoreProperties(NULL)
|
2015-12-07 19:49:02 +03:00
|
|
|
{
|
|
|
|
// scores
|
|
|
|
m_estimatedScore = copy.m_estimatedScore;
|
2015-12-30 18:24:01 +03:00
|
|
|
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool, system.featureFunctions.GetNumScores(), copy.GetScores());
|
2015-12-17 20:08:49 +03:00
|
|
|
|
|
|
|
size_t numWithPtData = system.featureFunctions.GetWithPhraseTableInd().size();
|
|
|
|
ffData = new (pool.Allocate<void *>(numWithPtData)) void *[numWithPtData];
|
2015-12-07 19:49:02 +03:00
|
|
|
}
|
2016-01-21 14:22:55 +03:00
|
|
|
*/
|
2015-12-07 19:49:02 +03:00
|
|
|
|
2015-10-23 22:53:36 +03:00
|
|
|
TargetPhrase::~TargetPhrase() {
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:32:47 +03:00
|
|
|
std::ostream& operator<<(std::ostream &out, const TargetPhrase &obj)
|
|
|
|
{
|
2016-02-23 21:32:24 +03:00
|
|
|
out << (const Phrase&) obj << " SCORES:" << obj.GetScores();
|
2015-10-26 19:32:47 +03:00
|
|
|
return out;
|
|
|
|
}
|
2015-12-10 23:49:30 +03:00
|
|
|
|
2015-12-28 23:07:47 +03:00
|
|
|
SCORE *TargetPhrase::GetScoresProperty(int propertyInd) const
|
|
|
|
{
|
2015-12-28 23:41:33 +03:00
|
|
|
return scoreProperties ? scoreProperties + propertyInd : NULL;
|
2015-12-28 23:07:47 +03:00
|
|
|
}
|
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
}
|