mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 21:42:19 +03:00
Ondrej Odchazel's update for AJAX-CAT
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3217 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
4cc43c61f2
commit
30921793a4
@ -53,7 +53,7 @@ Hypothesis::Hypothesis(Manager& manager, InputType const& source, const TargetPh
|
||||
: m_prevHypo(NULL)
|
||||
, m_targetPhrase(emptyTarget)
|
||||
, m_sourcePhrase(0)
|
||||
, m_sourceCompleted(source.GetSize())
|
||||
, m_sourceCompleted(source.GetSize(), manager.m_source.translated_words)
|
||||
, m_sourceInput(source)
|
||||
, m_currSourceWordsRange(NOT_FOUND, NOT_FOUND)
|
||||
, m_currTargetWordsRange(NOT_FOUND, NOT_FOUND)
|
||||
|
@ -50,6 +50,9 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
std::vector<bool> translated_words;
|
||||
std::string translated_target;
|
||||
|
||||
InputType(long translationId = 0);
|
||||
virtual ~InputType();
|
||||
|
||||
|
@ -81,7 +81,7 @@ class Manager
|
||||
void operator=(Manager const&);
|
||||
protected:
|
||||
// data
|
||||
InputType const& m_source; /**< source sentence to be translated */
|
||||
// InputType const& m_source; /**< source sentence to be translated */
|
||||
TranslationOptionCollection *m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */
|
||||
Search *m_search;
|
||||
|
||||
@ -99,6 +99,7 @@ protected:
|
||||
|
||||
|
||||
public:
|
||||
InputType const& m_source; /**< source sentence to be translated */
|
||||
Manager(InputType const& source, SearchAlgorithm searchAlgorithm);
|
||||
~Manager();
|
||||
|
||||
|
@ -41,6 +41,7 @@ Parameter::Parameter()
|
||||
{
|
||||
AddParam("beam-threshold", "b", "threshold for threshold pruning");
|
||||
AddParam("config", "f", "location of the configuration file");
|
||||
AddParam("continue-partial-translation", "cpt", "TODO - write info");
|
||||
AddParam("drop-unknown", "du", "drop unknown words instead of copying them");
|
||||
AddParam("disable-discarding", "dd", "disable hypothesis discarding");
|
||||
AddParam("factor-delimiter", "fd", "specify a different factor delimiter than the default");
|
||||
|
@ -47,7 +47,7 @@ SearchCubePruning::SearchCubePruning(Manager& manager, const InputType &source,
|
||||
:Search(manager)
|
||||
,m_source(source)
|
||||
,m_hypoStackColl(source.GetSize() + 1)
|
||||
,m_initialTargetPhrase(Output)
|
||||
,m_initialTargetPhrase(Output, source.translated_target)
|
||||
,m_start(clock())
|
||||
,m_transOptColl(transOptColl)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ SearchNormal::SearchNormal(Manager& manager, const InputType &source, const Tran
|
||||
:Search(manager)
|
||||
,m_source(source)
|
||||
,m_hypoStackColl(source.GetSize() + 1)
|
||||
,m_initialTargetPhrase(Output)
|
||||
,m_initialTargetPhrase(Output, source.translated_target)
|
||||
,m_start(clock())
|
||||
,interrupted_flag(0)
|
||||
,m_transOptColl(transOptColl)
|
||||
|
@ -49,6 +49,30 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)
|
||||
|
||||
if (getline(in, line, '\n').eof())
|
||||
return 0;
|
||||
|
||||
//get covered words
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
if (staticData.ContinuePartialTranslation()){
|
||||
string prev;
|
||||
string score;
|
||||
int loc1 = line.find( "|||", 0 );
|
||||
int loc2 = line.find( "|||", loc1 + 3 );
|
||||
if (loc1 > -1 && loc2 > -1){
|
||||
prev = line.substr(0, loc1);
|
||||
score = line.substr(loc1 + 3, loc2 - loc1 - 3);
|
||||
line = line.substr(loc2 + 3);
|
||||
score = Trim(score);
|
||||
prev = Trim(prev);
|
||||
translated_target = prev;
|
||||
int len = score.size();
|
||||
translated_words.resize(len);
|
||||
for (int i = 0; i < len; ++i){
|
||||
if (score.at(i) == '1') translated_words[i] = true;
|
||||
else translated_words[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove extra spaces
|
||||
line = Trim(line);
|
||||
|
||||
@ -57,7 +81,7 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)
|
||||
if (meta.find("id") != meta.end()) { this->SetTranslationId(atol(meta["id"].c_str())); }
|
||||
|
||||
// parse XML markup in translation line
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
//const StaticData &staticData = StaticData::Instance();
|
||||
std::vector<std::vector<XmlOption*> > xmlOptionsList(0);
|
||||
std::vector< size_t > xmlWalls;
|
||||
if (staticData.GetXmlInputType() != XmlPassThrough) {
|
||||
|
@ -128,6 +128,8 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
if (m_parameter->GetParam("factor-delimiter").size() > 0) {
|
||||
m_factorDelimiter = m_parameter->GetParam("factor-delimiter")[0];
|
||||
}
|
||||
|
||||
SetBooleanParameter( &m_continuePartialTranslation, "continue-partial-translation", false );
|
||||
|
||||
//word-to-word alignment
|
||||
SetBooleanParameter( &m_UseAlignmentInfo, "use-alignment-info", false );
|
||||
|
@ -221,7 +221,8 @@ protected:
|
||||
//! load decoding steps
|
||||
bool LoadLexicalReorderingModel();
|
||||
bool LoadGlobalLexicalModel();
|
||||
void ReduceTransOptCache() const;
|
||||
void ReduceTransOptCache() const;
|
||||
bool m_continuePartialTranslation;
|
||||
|
||||
public:
|
||||
|
||||
@ -545,7 +546,7 @@ public:
|
||||
|
||||
const TranslationOptionList* FindTransOptListInCache(const DecodeGraph &decodeGraph, const Phrase &sourcePhrase) const;
|
||||
|
||||
bool PrintAllDerivations() const { return m_printAllDerivations;}
|
||||
bool PrintAllDerivations() const { return m_printAllDerivations;}
|
||||
|
||||
const UnknownLHSList &GetUnknownLHS() const
|
||||
{ return m_unknownLHS; }
|
||||
@ -566,6 +567,7 @@ public:
|
||||
{ return 999999; /* TODO wtf! */ }
|
||||
|
||||
|
||||
bool ContinuePartialTranslation() const { return m_continuePartialTranslation; }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,18 @@ bool TargetPhrase::printalign=StaticData::Instance().PrintAlignmentInfo();
|
||||
//bool TargetPhrase::wordalignflag;
|
||||
//bool TargetPhrase::printalign;
|
||||
|
||||
TargetPhrase::TargetPhrase(FactorDirection direction, std::string out_string)
|
||||
:Phrase(direction),m_transScore(0.0), m_ngramScore(0.0), m_fullScore(0.0), m_sourcePhrase(0)
|
||||
{
|
||||
|
||||
//ACAT
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
CreateFromString(staticData.GetInputFactorOrder(), out_string, staticData.GetFactorDelimiter());
|
||||
wordalignflag=StaticData::Instance().UseAlignmentInfo();
|
||||
printalign=StaticData::Instance().PrintAlignmentInfo();
|
||||
}
|
||||
|
||||
|
||||
TargetPhrase::TargetPhrase(FactorDirection direction)
|
||||
:Phrase(direction)
|
||||
, m_transScore(0.0)
|
||||
|
@ -81,11 +81,7 @@ protected:
|
||||
|
||||
public:
|
||||
TargetPhrase(FactorDirection direction=Output);
|
||||
~TargetPhrase()
|
||||
{
|
||||
delete m_debugOutput;
|
||||
};
|
||||
|
||||
TargetPhrase(FactorDirection direction, std::string out_string);
|
||||
/** used by the unknown word handler.
|
||||
* Set alignment to 0
|
||||
*/
|
||||
|
@ -55,7 +55,25 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//sets elements by vector
|
||||
void Initialize(std::vector<bool> vector)
|
||||
{
|
||||
for (size_t pos = 0 ; pos < m_size ; pos++)
|
||||
{
|
||||
if (vector[pos] == true) m_bitmap[pos] = true;
|
||||
else m_bitmap[pos] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
//! create WordsBitmap of length size and initialise with vector
|
||||
WordsBitmap(size_t size, std::vector<bool> initialize_vector)
|
||||
:m_size (size)
|
||||
{
|
||||
m_bitmap = (bool*) malloc(sizeof(bool) * size);
|
||||
Initialize(initialize_vector);
|
||||
}
|
||||
//! create WordsBitmap of length size and initialise
|
||||
WordsBitmap(size_t size)
|
||||
:m_size (size)
|
||||
|
Loading…
Reference in New Issue
Block a user