mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-24 04:12:47 +03:00
add oovpt
This commit is contained in:
parent
b526efea23
commit
1e0a2835bf
@ -1995,6 +1995,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/DynSuffixArray.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TranslationModel/OOVPT.cpp</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/OOVPT.cpp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TranslationModel/OOVPT.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/OOVPT.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TranslationModel/PhraseDictionary.cpp</name>
|
||||
<type>1</type>
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "moses/TranslationModel/PhraseDictionaryScope3.h"
|
||||
#include "moses/TranslationModel/PhraseDictionaryTransliteration.h"
|
||||
#include "moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h"
|
||||
#include "moses/TranslationModel/OOVPT.h"
|
||||
|
||||
#include "moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h"
|
||||
#include "moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h"
|
||||
@ -183,6 +184,7 @@ FeatureRegistry::FeatureRegistry()
|
||||
MOSES_FNAME(PhraseDictionaryDynamicCacheBased);
|
||||
MOSES_FNAME(PhraseDictionaryFuzzyMatch);
|
||||
MOSES_FNAME2("RuleTable", Syntax::RuleTableFF);
|
||||
MOSES_FNAME(OOVPT);
|
||||
|
||||
MOSES_FNAME(GlobalLexicalModel);
|
||||
//MOSES_FNAME(GlobalLexicalModelUnlimited); This was commented out in the original
|
||||
|
84
moses/TranslationModel/OOVPT.cpp
Normal file
84
moses/TranslationModel/OOVPT.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
// vim:tabstop=2
|
||||
#include "OOVPT.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
OOVPT::OOVPT(const std::string &line)
|
||||
: PhraseDictionary(line)
|
||||
{
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
void OOVPT::Load()
|
||||
{
|
||||
SetFeaturesToApply();
|
||||
}
|
||||
|
||||
void OOVPT::InitializeForInput(InputType const& source)
|
||||
{
|
||||
ReduceCache();
|
||||
}
|
||||
|
||||
void OOVPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const
|
||||
{
|
||||
CacheColl &cache = GetCache();
|
||||
|
||||
InputPathList::const_iterator iter;
|
||||
for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) {
|
||||
InputPath &inputPath = **iter;
|
||||
const Phrase &sourcePhrase = inputPath.GetPhrase();
|
||||
|
||||
TargetPhrase *tp = CreateTargetPhrase(sourcePhrase);
|
||||
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;
|
||||
|
||||
inputPath.SetTargetPhrases(*this, tpColl, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
TargetPhrase *OOVPT::CreateTargetPhrase(const Phrase &sourcePhrase) const
|
||||
{
|
||||
// create a target phrase from the 1st word of the source, prefix with 'OOVPT:'
|
||||
assert(sourcePhrase.GetSize());
|
||||
assert(m_output.size() == 1);
|
||||
|
||||
string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string();
|
||||
|
||||
TargetPhrase *tp = new TargetPhrase(this);
|
||||
Word &word = tp->AddWord();
|
||||
word.CreateFromString(Output, m_output, str, false);
|
||||
|
||||
// score for this phrase table
|
||||
vector<float> scores(m_numScoreComponents, 1.3);
|
||||
tp->GetScoreBreakdown().PlusEquals(this, scores);
|
||||
|
||||
// score of all other ff when this rule is being loaded
|
||||
tp->EvaluateInIsolation(sourcePhrase, GetFeaturesToApply());
|
||||
|
||||
return tp;
|
||||
}
|
||||
|
||||
ChartRuleLookupManager* OOVPT::CreateRuleLookupManager(const ChartParser &parser,
|
||||
const ChartCellCollectionBase &cellCollection,
|
||||
std::size_t /*maxChartSpan*/)
|
||||
{
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TO_STRING_BODY(OOVPT);
|
||||
|
||||
// friend
|
||||
ostream& operator<<(ostream& out, const OOVPT& phraseDict)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
36
moses/TranslationModel/OOVPT.h
Normal file
36
moses/TranslationModel/OOVPT.h
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PhraseDictionary.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
class ChartParser;
|
||||
class ChartCellCollectionBase;
|
||||
class ChartRuleLookupManager;
|
||||
|
||||
class OOVPT : public PhraseDictionary
|
||||
{
|
||||
friend std::ostream& operator<<(std::ostream&, const OOVPT&);
|
||||
|
||||
public:
|
||||
OOVPT(const std::string &line);
|
||||
|
||||
void Load();
|
||||
|
||||
void InitializeForInput(InputType const& source);
|
||||
|
||||
// for phrase-based model
|
||||
void GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const;
|
||||
|
||||
// for syntax/hiero model (CKY+ decoding)
|
||||
ChartRuleLookupManager* CreateRuleLookupManager(const ChartParser&, const ChartCellCollectionBase&, std::size_t);
|
||||
|
||||
TO_STRING();
|
||||
|
||||
|
||||
protected:
|
||||
TargetPhrase *CreateTargetPhrase(const Phrase &sourcePhrase) const;
|
||||
};
|
||||
|
||||
} // namespace Moses
|
Loading…
Reference in New Issue
Block a user