Skip to content

Commit

Permalink
Code refactoring: All FF now get access to AllOptions at load time, s…
Browse files Browse the repository at this point in the history
…o they don't have to rely on StaticData.
  • Loading branch information
ugermann committed Dec 8, 2015
1 parent 9528b56 commit fdb5d9b
Show file tree
Hide file tree
Showing 98 changed files with 140 additions and 133 deletions.
2 changes: 1 addition & 1 deletion defer/ExternalFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ExternalFeatureState::ExternalFeatureState(int stateSize, void *data)
memcpy(m_data, data, stateSize);
}

void ExternalFeature::Load()
void ExternalFeature::Load(AllOptions const& opts)
{
string nparam = "testing";

Expand Down
2 changes: 1 addition & 1 deletion defer/ExternalFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ExternalFeature : public StatefulFeatureFunction
}
~ExternalFeature();

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const {
return true;
Expand Down
4 changes: 2 additions & 2 deletions defer/Joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LanguageModelJoint : public LanguageModelMultiFactor
delete m_lmImpl;
}

bool Load(const std::string &filePath
bool Load(AllOptions const& opts, const std::string &filePath
, const std::vector<FactorType> &factorTypes
, size_t nGramOrder) {
m_factorTypes = FactorMask(factorTypes);
Expand All @@ -77,7 +77,7 @@ class LanguageModelJoint : public LanguageModelMultiFactor
m_sentenceEndWord[factorType] = factorCollection.AddFactor(Output, factorType, EOS_);
}

m_lmImpl->Load();
m_lmImpl->Load(AllOptions const& opts);
}

LMResult GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const {
Expand Down
4 changes: 3 additions & 1 deletion misc/queryPhraseTableMin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h"
#include "moses/Util.h"
#include "moses/Phrase.h"
#include "moses/parameters/AllOptions.h"

void usage();

Expand Down Expand Up @@ -50,7 +51,8 @@ int main(int argc, char **argv)
std::stringstream ss;
ss << nscores;
PhraseDictionaryCompact pdc("PhraseDictionaryCompact input-factor=0 output-factor=0 num-features=" + ss.str() + " path=" + ttable);
pdc.Load();
AllOptions opts;
pdc.Load(opts);

std::string line;
while(getline(std::cin, line)) {
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/CoveredReferenceFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void CoveredReferenceFeature::EvaluateWithSourceContext(const InputType &input
estimatedScores->Assign(this, scores);
}

void CoveredReferenceFeature::Load()
void CoveredReferenceFeature::Load(AllOptions const& opts)
{
InputFileStream refFile(m_path);
std::string line;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/CoveredReferenceFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CoveredReferenceFeature : public StatefulFeatureFunction
ReadParameters();
}

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const {
return true;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/DeleteRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DeleteRules::DeleteRules(const std::string &line)
ReadParameters();
}

void DeleteRules::Load()
void DeleteRules::Load(AllOptions const& opts)
{
std::vector<FactorType> factorOrder;
factorOrder.push_back(0); // unfactored for now
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/DeleteRules.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeleteRules : public StatelessFeatureFunction
public:
DeleteRules(const std::string &line);

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const {
return true;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/DynamicCacheBasedLanguageModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void DynamicCacheBasedLanguageModel::Clear()
m_cache.clear();
}

void DynamicCacheBasedLanguageModel::Load()
void DynamicCacheBasedLanguageModel::Load(AllOptions const& opts)
{
// SetPreComputedScores();
VERBOSE(2,"DynamicCacheBasedLanguageModel::Load()" << std::endl);
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/DynamicCacheBasedLanguageModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class DynamicCacheBasedLanguageModel : public StatelessFeatureFunction
return true;
}

void Load();
void Load(AllOptions const& opts);
void Load(const std::string filestr);
void Execute(std::string command);
void SetParameter(const std::string& key, const std::string& value);
Expand Down
5 changes: 3 additions & 2 deletions moses/FF/FeatureFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include <string>
#include "moses/FeatureVector.h"
#include "moses/TypeDef.h"

#include "moses/parameters/AllOptions.h"
#include <boost/shared_ptr.hpp>

namespace Moses
{

class AllOptions;
class Phrase;
class TargetPhrase;
class TranslationOptionList;
Expand Down Expand Up @@ -69,7 +70,7 @@ class FeatureFunction
virtual ~FeatureFunction();

//! override to load model files
virtual void Load() {
virtual void Load(AllOptions const& opts) {
}

static void ResetDescriptionCounts() {
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/GlobalLexicalModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GlobalLexicalModel::~GlobalLexicalModel()
}
}

void GlobalLexicalModel::Load()
void GlobalLexicalModel::Load(AllOptions const& opts)
{
FactorCollection &factorCollection = FactorCollection::Instance();
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/GlobalLexicalModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GlobalLexicalModel : public StatelessFeatureFunction
std::vector<FactorType> m_inputFactorsVec, m_outputFactorsVec;
std::string m_filePath;

void Load();
void Load(AllOptions const& opts);

float ScorePhrase( const TargetPhrase& targetPhrase ) const;
float GetFromCacheOrScorePhrase( const TargetPhrase& targetPhrase ) const;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/InputFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ InputFeature::InputFeature(const std::string &line)
s_instance = this;
}

void InputFeature::Load()
void InputFeature::Load(AllOptions const& opts)
{

const PhraseDictionary *pt = PhraseDictionary::GetColl()[0];
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/InputFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InputFeature : public StatelessFeatureFunction

InputFeature(const std::string &line);

void Load();
void Load(AllOptions const& opts);

void SetParameter(const std::string& key, const std::string& value);

Expand Down
2 changes: 1 addition & 1 deletion moses/FF/LexicalReordering/LexicalReordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ LexicalReordering::

void
LexicalReordering::
Load()
Load(AllOptions const& opts)
{
typedef LexicalReorderingTable LRTable;
if (m_filePath.size())
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/LexicalReordering/LexicalReordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LexicalReordering : public StatefulFeatureFunction
public:
LexicalReordering(const std::string &line);
virtual ~LexicalReordering();
void Load();
void Load(AllOptions const& opts);

virtual
bool
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/Model1Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void Model1Feature::SetParameter(const std::string& key, const std::string& valu
}
}

void Model1Feature::Load()
void Model1Feature::Load(AllOptions const& opts)
{
FEATUREVERBOSE(2, GetScoreProducerDescription() << ": Loading source vocabulary from file " << m_fileNameVcbS << " ...");
Model1Vocabulary vcbS;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/Model1Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Model1Feature : public StatelessFeatureFunction
Model1LexicalTable m_model1;
const Factor* m_emptyWord;

void Load();
void Load(AllOptions const& opts);

// cache
mutable boost::unordered_map<const InputType*, boost::unordered_map<const Factor*, float> > m_cache;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/OSM-Feature/OpSequenceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void OpSequenceModel :: readLanguageModel(const char *lmFile)
}


void OpSequenceModel::Load()
void OpSequenceModel::Load(AllOptions const& opts)
{
readLanguageModel(m_lmPath.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/OSM-Feature/OpSequenceModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OpSequenceModel : public StatefulFeatureFunction
~OpSequenceModel();

void readLanguageModel(const char *);
void Load();
void Load(AllOptions const& opts);

FFState* EvaluateWhenApplied(
const Hypothesis& cur_hypo,
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/PhraseOrientationFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void PhraseOrientationFeature::SetParameter(const std::string& key, const std::s
}


void PhraseOrientationFeature::Load()
void PhraseOrientationFeature::Load(AllOptions const& opts)
{
if ( !m_filenameTargetWordList.empty() ) {
LoadWordList(m_filenameTargetWordList,m_targetWordList);
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/PhraseOrientationFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class PhraseOrientationFeature : public StatefulFeatureFunction

void SetParameter(const std::string& key, const std::string& value);

void Load();
void Load(AllOptions const& opts);

void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/PhrasePairFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void PhrasePairFeature::SetParameter(const std::string& key, const std::string&
}
}

void PhrasePairFeature::Load()
void PhrasePairFeature::Load(AllOptions const& opts)
{
if (m_domainTrigger) {
// domain trigger terms for each input document
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/PhrasePairFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PhrasePairFeature: public StatelessFeatureFunction
public:
PhrasePairFeature(const std::string &line);

void Load();
void Load(AllOptions const& opts);
void SetParameter(const std::string& key, const std::string& value);

bool IsUseable(const FactorMask &mask) const;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/SoftSourceSyntacticConstraintsFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void SoftSourceSyntacticConstraintsFeature::SetParameter(const std::string& key,
}
}

void SoftSourceSyntacticConstraintsFeature::Load()
void SoftSourceSyntacticConstraintsFeature::Load(AllOptions const& opts)
{
// don't change the loading order!
LoadSourceLabelSet();
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/SoftSourceSyntacticConstraintsFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SoftSourceSyntacticConstraintsFeature : public StatelessFeatureFunction

void SetParameter(const std::string& key, const std::string& value);

void Load();
void Load(AllOptions const& opts);

void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/SourceWordDeletionFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void SourceWordDeletionFeature::SetParameter(const std::string& key, const std::
}
}

void SourceWordDeletionFeature::Load()
void SourceWordDeletionFeature::Load(AllOptions const& opts)
{
if (m_filename.empty())
return;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/SourceWordDeletionFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SourceWordDeletionFeature : public StatelessFeatureFunction
public:
SourceWordDeletionFeature(const std::string &line);

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const;

Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetBigramFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void TargetBigramFeature::SetParameter(const std::string& key, const std::string
}
}

void TargetBigramFeature::Load()
void TargetBigramFeature::Load(AllOptions const& opts)
{
if (m_filePath == "*")
return ; //allow all
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetBigramFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TargetBigramFeature : public StatefulFeatureFunction
public:
TargetBigramFeature(const std::string &line);

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const;

Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetNgramFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void TargetNgramFeature::SetParameter(const std::string& key, const std::string&
}
}

void TargetNgramFeature::Load()
void TargetNgramFeature::Load(AllOptions const& opts)
{
if (m_file == "") return; //allow all, for now

Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetNgramFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class TargetNgramFeature : public StatefulFeatureFunction
public:
TargetNgramFeature(const std::string &line);

void Load();
void Load(AllOptions const& opts);

bool IsUseable(const FactorMask &mask) const;

Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetWordInsertionFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TargetWordInsertionFeature::SetParameter(const std::string& key, const std:
}
}

void TargetWordInsertionFeature::Load()
void TargetWordInsertionFeature::Load(AllOptions const& opts)
{
if (m_filename.empty())
return;
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TargetWordInsertionFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TargetWordInsertionFeature : public StatelessFeatureFunction

bool IsUseable(const FactorMask &mask) const;

void Load();
void Load(AllOptions const& opts);

virtual void EvaluateInIsolation(const Phrase &source
, const TargetPhrase &targetPhrase
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TreeStructureFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Moses
{

void TreeStructureFeature::Load()
void TreeStructureFeature::Load(AllOptions const& opts)
{

// syntactic constraints can be hooked in here.
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/TreeStructureFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TreeStructureFeature : public StatefulFeatureFunction
int /* featureID - used to index the state in the previous hypotheses */,
ScoreComponentCollection* accumulator) const;

void Load();
void Load(AllOptions const& opts);
};


Expand Down
2 changes: 1 addition & 1 deletion moses/FF/WordTranslationFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void WordTranslationFeature::SetParameter(const std::string& key, const std::str
}
}

void WordTranslationFeature::Load()
void WordTranslationFeature::Load(AllOptions const& opts)
{
// load word list for restricted feature set
if (m_filePathSource.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion moses/FF/WordTranslationFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WordTranslationFeature : public StatelessFeatureFunction
void SetParameter(const std::string& key, const std::string& value);
bool IsUseable(const FactorMask &mask) const;

void Load();
void Load(AllOptions const& opts);

void EvaluateWithSourceContext(const InputType &input
, const InputPath &inputPath
Expand Down
2 changes: 1 addition & 1 deletion moses/GenerationDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ GenerationDictionary::GenerationDictionary(const std::string &line)
ReadParameters();
}

void GenerationDictionary::Load()
void GenerationDictionary::Load(AllOptions const& opts)
{
FactorCollection &factorCollection = FactorCollection::Instance();

Expand Down
Loading

0 comments on commit fdb5d9b

Please sign in to comment.