From 29694af6e43c1cec7a6fd0b157eb44faca706129 Mon Sep 17 00:00:00 2001 From: Ulrich Germann Date: Thu, 10 Dec 2015 03:17:36 +0000 Subject: [PATCH] Code cleanup and refactoring. --- misc/queryPhraseTableMin.cpp | 2 +- moses-cmd/LatticeMBRGrid.cpp | 7 +- moses-cmd/MainVW.cpp | 2 +- moses/BitmapContainer.cpp | 5 +- moses/ChartHypothesis.cpp | 6 +- moses/ChartHypothesis.h | 6 +- moses/ChartKBestExtractor.cpp | 2 +- moses/ChartParser.cpp | 50 ++++++---- moses/ChartParser.h | 3 + moses/ConfusionNet.cpp | 25 +++-- moses/ConfusionNet.h | 12 +-- moses/ExportInterface.cpp | 4 +- moses/FF/ConstrainedDecoding.cpp | 9 +- moses/FF/ConstrainedDecoding.h | 2 +- moses/FF/CountNonTerms.cpp | 14 ++- moses/FF/CountNonTerms.h | 3 + moses/FF/CoveredReferenceFeature.cpp | 3 +- moses/FF/CoveredReferenceFeature.h | 2 +- moses/FF/DeleteRules.cpp | 3 +- moses/FF/DeleteRules.h | 2 +- moses/FF/DynamicCacheBasedLanguageModel.cpp | 3 +- moses/FF/DynamicCacheBasedLanguageModel.h | 2 +- moses/FF/FeatureFunction.h | 9 +- moses/FF/GlobalLexicalModel.cpp | 3 +- moses/FF/GlobalLexicalModel.h | 2 +- moses/FF/HyperParameterAsWeight.cpp | 4 +- moses/FF/InputFeature.cpp | 4 +- moses/FF/InputFeature.h | 2 +- moses/FF/InternalTree.cpp | 10 +- .../LexicalReordering/LexicalReordering.cpp | 3 +- .../FF/LexicalReordering/LexicalReordering.h | 2 +- moses/FF/Model1Feature.cpp | 3 +- moses/FF/Model1Feature.h | 2 +- moses/FF/OSM-Feature/OpSequenceModel.cpp | 3 +- moses/FF/OSM-Feature/OpSequenceModel.h | 2 +- moses/FF/PhraseOrientationFeature.cpp | 3 +- moses/FF/PhraseOrientationFeature.h | 2 +- moses/FF/PhrasePairFeature.cpp | 3 +- moses/FF/PhrasePairFeature.h | 2 +- moses/FF/RuleScope.cpp | 10 +- moses/FF/SoftMatchingFeature.cpp | 6 +- .../SoftSourceSyntacticConstraintsFeature.cpp | 16 ++-- .../SoftSourceSyntacticConstraintsFeature.h | 3 +- moses/FF/SourceGHKMTreeInputMatchFeature.cpp | 14 ++- moses/FF/SourceGHKMTreeInputMatchFeature.h | 3 + moses/FF/SourceWordDeletionFeature.cpp | 3 +- moses/FF/SourceWordDeletionFeature.h | 2 +- moses/FF/TargetBigramFeature.cpp | 3 +- moses/FF/TargetBigramFeature.h | 2 +- moses/FF/TargetNgramFeature.cpp | 3 +- moses/FF/TargetNgramFeature.h | 2 +- moses/FF/TargetWordInsertionFeature.cpp | 3 +- moses/FF/TargetWordInsertionFeature.h | 2 +- moses/FF/TreeStructureFeature.cpp | 3 +- moses/FF/TreeStructureFeature.h | 2 +- moses/FF/WordTranslationFeature.cpp | 3 +- moses/FF/WordTranslationFeature.h | 2 +- moses/ForestInput.cpp | 31 +++--- moses/ForestInput.h | 10 +- moses/GenerationDictionary.cpp | 3 +- moses/GenerationDictionary.h | 2 +- moses/HypergraphOutput.cpp | 4 +- moses/IOWrapper.cpp | 17 ++-- moses/IOWrapper.h | 5 +- moses/Incremental.cpp | 8 +- moses/InputType.cpp | 3 +- moses/InputType.h | 7 +- moses/LM/BilingualLM.cpp | 3 +- moses/LM/BilingualLM.h | 2 +- moses/LM/DALMWrapper.h | 2 +- moses/LM/IRST.cpp | 2 +- moses/LM/IRST.h | 2 +- moses/LM/MaxEntSRI.h | 2 +- moses/LM/NeuralLMWrapper.h | 2 +- moses/LM/RDLM.h | 2 +- moses/LM/Rand.h | 2 +- moses/LM/SRI.h | 2 +- moses/LM/oxlm/OxLM.h | 2 +- moses/MockHypothesis.cpp | 15 ++- moses/Phrase.cpp | 2 +- moses/ReorderingConstraint.cpp | 4 +- moses/ReorderingConstraint.h | 9 +- moses/RuleCube.cpp | 4 +- moses/RuleCubeQueue.cpp | 2 +- moses/Sentence.cpp | 61 +++++------- moses/Sentence.h | 16 ++-- moses/StaticData.cpp | 44 +-------- moses/StaticData.h | 94 ++++--------------- moses/Syntax/F2S/GlueRuleSynthesizer.cpp | 24 +++-- moses/Syntax/F2S/GlueRuleSynthesizer.h | 7 +- moses/Syntax/F2S/Manager-inl.h | 9 +- moses/Syntax/KBestExtractor.cpp | 2 +- moses/Syntax/RuleTableFF.cpp | 19 ++-- moses/Syntax/RuleTableFF.h | 2 +- moses/Syntax/S2T/Manager-inl.h | 6 +- moses/Syntax/S2T/OovHandler-inl.h | 6 +- moses/Syntax/SHyperedge.cpp | 2 +- moses/Syntax/T2S/GlueRuleSynthesizer.cpp | 21 +++-- moses/Syntax/T2S/GlueRuleSynthesizer.h | 8 +- moses/Syntax/T2S/Manager-inl.h | 5 +- moses/TabbedSentence.cpp | 15 +-- moses/TabbedSentence.h | 3 +- moses/TargetPhrase.cpp | 2 +- .../ChartRuleLookupManagerOnDisk.cpp | 5 +- .../ChartRuleLookupManagerOnDisk.h | 1 + .../CompactPT/PhraseDictionaryCompact.cpp | 3 +- .../CompactPT/PhraseDictionaryCompact.h | 2 +- .../PhraseDictionaryDynamicCacheBased.cpp | 13 +-- .../PhraseDictionaryDynamicCacheBased.h | 2 +- .../PhraseDictionaryGroup.cpp | 3 +- .../TranslationModel/PhraseDictionaryGroup.h | 2 +- .../PhraseDictionaryMultiModel.cpp | 3 +- .../PhraseDictionaryMultiModel.h | 2 +- .../PhraseDictionaryMultiModelCounts.cpp | 3 +- .../PhraseDictionaryMultiModelCounts.h | 2 +- .../PhraseDictionaryTransliteration.cpp | 3 +- .../PhraseDictionaryTransliteration.h | 2 +- .../PhraseDictionaryTreeAdaptor.cpp | 3 +- .../PhraseDictionaryTreeAdaptor.h | 2 +- .../TranslationModel/ProbingPT/ProbingPT.cpp | 5 +- moses/TranslationModel/ProbingPT/ProbingPT.h | 2 +- .../RuleTable/LoaderStandard.cpp | 4 +- .../PhraseDictionaryALSuffixArray.cpp | 3 +- .../RuleTable/PhraseDictionaryALSuffixArray.h | 2 +- .../RuleTable/PhraseDictionaryFuzzyMatch.cpp | 5 +- .../RuleTable/PhraseDictionaryFuzzyMatch.h | 2 +- .../RuleTable/PhraseDictionaryOnDisk.cpp | 3 +- .../RuleTable/PhraseDictionaryOnDisk.h | 2 +- moses/TranslationModel/RuleTable/Trie.cpp | 5 +- moses/TranslationModel/RuleTable/Trie.h | 2 +- moses/TranslationModel/SkeletonPT.cpp | 3 +- moses/TranslationModel/SkeletonPT.h | 2 +- moses/TranslationModel/UG/mmsapt.cpp | 5 +- moses/TranslationModel/UG/mmsapt.h | 4 +- ...ranslationOptionCollectionConfusionNet.cpp | 2 +- moses/TreeInput.cpp | 44 ++++----- moses/TreeInput.h | 11 +-- moses/WordLattice.cpp | 27 ++---- moses/WordLattice.h | 9 +- moses/XmlOption.cpp | 17 ++-- moses/XmlOption.h | 8 +- moses/parameters/ReportingOptions.cpp | 5 +- moses/parameters/ReportingOptions.h | 2 + moses/server/TranslationRequest.cpp | 4 +- 144 files changed, 502 insertions(+), 530 deletions(-) diff --git a/misc/queryPhraseTableMin.cpp b/misc/queryPhraseTableMin.cpp index c9ccbdf91..caca838ee 100644 --- a/misc/queryPhraseTableMin.cpp +++ b/misc/queryPhraseTableMin.cpp @@ -51,7 +51,7 @@ 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); - AllOptions opts; + AllOptions::ptr opts(new AllOptions); pdc.Load(opts); std::string line; diff --git a/moses-cmd/LatticeMBRGrid.cpp b/moses-cmd/LatticeMBRGrid.cpp index f1dfd5b26..3cb801342 100644 --- a/moses-cmd/LatticeMBRGrid.cpp +++ b/moses-cmd/LatticeMBRGrid.cpp @@ -163,11 +163,12 @@ int main(int argc, char const* argv[]) } StaticData& SD = const_cast(StaticData::Instance()); - LMBR_Options& lmbr = SD.options().lmbr; - MBR_Options& mbr = SD.options().mbr; + boost::shared_ptr opts(new AllOptions(*SD.options())); + LMBR_Options& lmbr = opts->lmbr; + MBR_Options& mbr = opts->mbr; lmbr.enabled = true; - boost::shared_ptr ioWrapper(new IOWrapper(SD.options())); + boost::shared_ptr ioWrapper(new IOWrapper(*opts)); if (!ioWrapper) { throw runtime_error("Failed to initialise IOWrapper"); } diff --git a/moses-cmd/MainVW.cpp b/moses-cmd/MainVW.cpp index 396a1c1d4..2f313df01 100644 --- a/moses-cmd/MainVW.cpp +++ b/moses-cmd/MainVW.cpp @@ -125,7 +125,7 @@ int main(int argc, char const** argv) IFVERBOSE(1) { PrintUserTime("Created input-output object"); } - AllOptions::ptr opts(new AllOptions(StaticData::Instance().options())); + AllOptions::ptr opts(new AllOptions(*StaticData::Instance().options())); boost::shared_ptr ioWrapper(new IOWrapper(*opts)); if (ioWrapper == NULL) { cerr << "Error; Failed to create IO object" << endl; diff --git a/moses/BitmapContainer.cpp b/moses/BitmapContainer.cpp index c1823b33d..e8d095e3b 100644 --- a/moses/BitmapContainer.cpp +++ b/moses/BitmapContainer.cpp @@ -61,7 +61,7 @@ public: , m_transOptRange(transOptRange) { m_totalWeightDistortion = 0; const StaticData &staticData = StaticData::Instance(); - + const std::vector &ffs = DistortionScoreProducer::GetDistortionFeatureFunctions(); std::vector::const_iterator iter; for (iter = ffs.begin(); iter != ffs.end(); ++iter) { @@ -139,7 +139,8 @@ BackwardsEdge::BackwardsEdge(const BitmapContainer &prevBitmapContainer } // Fetch the things we need for distortion cost computation. - int maxDistortion = StaticData::Instance().GetMaxDistortion(); + // int maxDistortion = StaticData::Instance().GetMaxDistortion(); + int maxDistortion = itype.options()->reordering.max_distortion; if (maxDistortion == -1) { for (HypothesisSet::const_iterator iter = m_prevBitmapContainer.GetHypotheses().begin(); iter != m_prevBitmapContainer.GetHypotheses().end(); ++iter) { diff --git a/moses/ChartHypothesis.cpp b/moses/ChartHypothesis.cpp index c99aec45e..40aaecd46 100644 --- a/moses/ChartHypothesis.cpp +++ b/moses/ChartHypothesis.cpp @@ -102,7 +102,7 @@ ChartHypothesis::~ChartHypothesis() */ void ChartHypothesis::GetOutputPhrase(Phrase &outPhrase) const { - FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor; + FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor; for (size_t pos = 0; pos < GetCurrTargetPhrase().GetSize(); ++pos) { const Word &word = GetCurrTargetPhrase().GetWord(pos); @@ -256,7 +256,7 @@ void ChartHypothesis::CleanupArcList() * However, may not be enough if only unique candidates are needed, * so we'll keep all of arc list if nedd distinct n-best list */ - AllOptions const& opts = StaticData::Instance().options(); + AllOptions const& opts = *StaticData::Instance().options(); size_t nBestSize = opts.nbest.nbest_size; bool distinctNBest = (opts.nbest.only_distinct || opts.mbr.enabled @@ -336,7 +336,7 @@ std::ostream& operator<<(std::ostream& out, const ChartHypothesis& hypo) out << "->" << hypo.GetWinningHypothesis()->GetId(); } - if (StaticData::Instance().GetIncludeLHSInSearchGraph()) { + if (hypo.GetManager().options()->output.include_lhs_in_search_graph) { out << " " << hypo.GetTargetLHS() << "=>"; } out << " " << hypo.GetCurrTargetPhrase() diff --git a/moses/ChartHypothesis.h b/moses/ChartHypothesis.h index 6f8a578f7..9ed4f2f12 100644 --- a/moses/ChartHypothesis.h +++ b/moses/ChartHypothesis.h @@ -52,7 +52,7 @@ protected: boost::shared_ptr m_transOpt; - Range m_currSourceWordsRange; + Range m_currSourceWordsRange; std::vector m_ffStates; /*! stateful feature function states */ /*! sum of scores of this hypothesis, and previous hypotheses. Lazily initialised. */ mutable boost::scoped_ptr m_scoreBreakdown; @@ -62,8 +62,8 @@ protected: ,m_lmPrefix; float m_totalScore; - ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */ - const ChartHypothesis *m_winningHypo; + ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */ + const ChartHypothesis *m_winningHypo; std::vector m_prevHypos; // always sorted by source position? diff --git a/moses/ChartKBestExtractor.cpp b/moses/ChartKBestExtractor.cpp index 8d5997f21..ff766d6e1 100644 --- a/moses/ChartKBestExtractor.cpp +++ b/moses/ChartKBestExtractor.cpp @@ -82,7 +82,7 @@ void ChartKBestExtractor::Extract( // Generate the target-side yield of the derivation d. Phrase ChartKBestExtractor::GetOutputPhrase(const Derivation &d) { - FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor; + FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor; Phrase ret(ARRAY_SIZE_INCR); diff --git a/moses/ChartParser.cpp b/moses/ChartParser.cpp index 2b49c9508..e0c84e199 100644 --- a/moses/ChartParser.cpp +++ b/moses/ChartParser.cpp @@ -44,17 +44,26 @@ ChartParserUnknown ChartParserUnknown::~ChartParserUnknown() { RemoveAllInColl(m_unksrcs); - // RemoveAllInColl(m_cacheTargetPhraseCollection); } -void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, ChartParserCallback &to) +AllOptions::ptr const& +ChartParserUnknown:: +options() const +{ + return m_ttask.lock()->options(); +} + +void +ChartParserUnknown:: +Process(const Word &sourceWord, const Range &range, ChartParserCallback &to) { // unknown word, add as trans opt const StaticData &staticData = StaticData::Instance(); - const UnknownWordPenaltyProducer &unknownWordPenaltyProducer = UnknownWordPenaltyProducer::Instance(); + const UnknownWordPenaltyProducer &unknownWordPenaltyProducer + = UnknownWordPenaltyProducer::Instance(); size_t isDigit = 0; - if (staticData.options().unk.drop) { + if (options()->unk.drop) { const Factor *f = sourceWord[0]; // TODO hack. shouldn't know which factor is surface const StringPiece s = f->GetString(); isDigit = s.find_first_of("0123456789"); @@ -79,9 +88,9 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha } //TranslationOption *transOpt; - if (! staticData.options().unk.drop || isDigit) { + if (! options()->unk.drop || isDigit) { // loop - const UnknownLHSList &lhsList = staticData.GetUnknownLHS(); + const UnknownLHSList &lhsList = options()->syntax.unknown_lhs; // staticData.GetUnknownLHS(); UnknownLHSList::const_iterator iterLHS; for (iterLHS = lhsList.begin(); iterLHS != lhsList.end(); ++iterLHS) { const string &targetLHSStr = iterLHS->first; @@ -91,8 +100,8 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha //const Word &sourceLHS = staticData.GetInputDefaultNonTerminal(); Word *targetLHS = new Word(true); - targetLHS->CreateFromString(Output, staticData.options().output.factor_order, - targetLHSStr, true); + targetLHS->CreateFromString(Output, options()->output.factor_order, + targetLHSStr, true); UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS"); // add to dictionary @@ -108,9 +117,8 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha targetPhrase->SetAlignmentInfo("0-0"); targetPhrase->EvaluateInIsolation(*unksrc); - AllOptions const& opts = staticData.options(); - if (!opts.output.detailed_tree_transrep_filepath.empty() || - opts.nbest.print_trees || staticData.GetTreeStructure() != NULL) { + if (!options()->output.detailed_tree_transrep_filepath.empty() || + options()->nbest.print_trees || staticData.GetTreeStructure() != NULL) { std::string prop = "[ "; prop += (*targetLHS)[0]->GetString().as_string() + " "; prop += sourceWord[0]->GetString().as_string() + " ]"; @@ -126,15 +134,15 @@ void ChartParserUnknown::Process(const Word &sourceWord, const Range &range, Cha TargetPhrase *targetPhrase = new TargetPhrase(firstPt); // loop - const UnknownLHSList &lhsList = staticData.GetUnknownLHS(); + const UnknownLHSList &lhsList = options()->syntax.unknown_lhs;//staticData.GetUnknownLHS(); UnknownLHSList::const_iterator iterLHS; for (iterLHS = lhsList.begin(); iterLHS != lhsList.end(); ++iterLHS) { const string &targetLHSStr = iterLHS->first; //float prob = iterLHS->second; Word *targetLHS = new Word(true); - targetLHS->CreateFromString(Output, staticData.options().output.factor_order, - targetLHSStr, true); + targetLHS->CreateFromString(Output, staticData.options()->output.factor_order, + targetLHSStr, true); UTIL_THROW_IF2(targetLHS->GetFactor(0) == NULL, "Null factor for target LHS"); targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, unknownScore); @@ -214,9 +222,7 @@ void ChartParser::Create(const Range &range, ChartParserCallback &to) if (range.GetNumWordsCovered() == 1 && range.GetStartPos() != 0 && range.GetStartPos() != m_source.GetSize()-1) { - bool always = m_ttask.lock()->options()->unk.always_create_direct_transopt; - // bool alwaysCreateDirectTranslationOption - // = StaticData::Instance().IsAlwaysCreateDirectTranslationOption(); + bool always = options()->unk.always_create_direct_transopt; if (to.Empty() || always) { // create unknown words for 1 word coverage where we don't have any trans options const Word &sourceWord = m_source.GetWord(range.GetStartPos()); @@ -291,4 +297,14 @@ long ChartParser::GetTranslationId() const { return m_source.GetTranslationId(); } + + +AllOptions::ptr const& +ChartParser:: +options() const +{ + return m_ttask.lock()->options(); +} + + } // namespace Moses diff --git a/moses/ChartParser.h b/moses/ChartParser.h index d6f20b6d6..3229e296b 100644 --- a/moses/ChartParser.h +++ b/moses/ChartParser.h @@ -57,6 +57,7 @@ public: private: std::vector m_unksrcs; std::list m_cacheTargetPhraseCollection; + AllOptions::ptr const& options() const; }; class ChartParser @@ -78,6 +79,8 @@ public: return m_unknown.GetUnknownSources(); } + AllOptions::ptr const& options() const; + private: ChartParserUnknown m_unknown; std::vector m_decodeGraphList; diff --git a/moses/ConfusionNet.cpp b/moses/ConfusionNet.cpp index f71c798f7..f60b7907f 100644 --- a/moses/ConfusionNet.cpp +++ b/moses/ConfusionNet.cpp @@ -66,9 +66,8 @@ ConfusionNet(AllOptions::ptr const& opts) : InputType(opts) { stats.createOne(); - const StaticData& SD = StaticData::Instance(); - if (SD.IsSyntax()) { - m_defaultLabelSet.insert(SD.GetInputDefaultNonTerminal()); + if (is_syntax(opts->search.algo)) { + m_defaultLabelSet.insert(opts->syntax.input_default_non_terminal); } UTIL_THROW_IF2(InputFeature::InstancePtr() == NULL, "Input feature must be specified"); } @@ -92,14 +91,14 @@ ConfusionNet(Sentence const& s) : InputType(s.options()) bool ConfusionNet:: -ReadF(std::istream& in, const std::vector& factorOrder, int format) +ReadF(std::istream& in, int format) { VERBOSE(2, "read confusion net with format "<& factorOrder, int format) int ConfusionNet:: -Read(std::istream& in, - const std::vector& factorOrder, - AllOptions const& opts) +Read(std::istream& in) { - int rv=ReadF(in,factorOrder,0); + int rv=ReadF(in,0); if(rv) stats.collect(*this); return rv; } bool ConfusionNet:: -ReadFormat0(std::istream& in, const std::vector& factorOrder) +ReadFormat0(std::istream& in) { Clear(); + const std::vector& factorOrder = m_options->input.factor_order; - // const StaticData &staticData = StaticData::Instance(); const InputFeature *inputFeature = InputFeature::InstancePtr(); size_t numInputScores = inputFeature->GetNumInputScores(); size_t numRealWordCount = inputFeature->GetNumRealWordsInInput(); @@ -140,7 +137,6 @@ ReadFormat0(std::istream& in, const std::vector& factorOrder) Column col; while(is>>word) { Word w; - // String2Word(word,w,factorOrder); w.CreateFromString(Input,factorOrder,StringPiece(word),false,false); std::vector probs(totalCount, 0.0); for(size_t i=0; i < numInputScores; i++) { @@ -179,9 +175,10 @@ ReadFormat0(std::istream& in, const std::vector& factorOrder) bool ConfusionNet:: -ReadFormat1(std::istream& in, const std::vector& factorOrder) +ReadFormat1(std::istream& in) { Clear(); + const std::vector& factorOrder = m_options->input.factor_order; std::string line; if(!getline(in,line)) return 0; size_t s; diff --git a/moses/ConfusionNet.h b/moses/ConfusionNet.h index f298fb18e..f16493b23 100644 --- a/moses/ConfusionNet.h +++ b/moses/ConfusionNet.h @@ -30,8 +30,8 @@ protected: std::vector data; NonTerminalSet m_defaultLabelSet; - bool ReadFormat0(std::istream&,const std::vector& factorOrder); - bool ReadFormat1(std::istream&,const std::vector& factorOrder); + bool ReadFormat0(std::istream&); + bool ReadFormat1(std::istream&); void String2Word(const std::string& s,Word& w,const std::vector& factorOrder); public: @@ -46,7 +46,8 @@ public: const Column& GetColumn(size_t i) const { UTIL_THROW_IF2(i >= data.size(), - "Out of bounds. Trying to access " << i << " when vector only contains " << data.size()); + "Out of bounds. Trying to access " << i + << " when vector only contains " << data.size()); return data[i]; } const Column& operator[](size_t i) const { @@ -64,11 +65,10 @@ public: data.clear(); } - bool ReadF(std::istream&,const std::vector& factorOrder,int format=0); + bool ReadF(std::istream&, int format=0); virtual void Print(std::ostream&) const; - int Read(std::istream& in,const std::vector& factorOrder, - AllOptions const& opts); + int Read(std::istream& in); Phrase GetSubString(const Range&) const; //TODO not defined std::string GetStringRep(const std::vector factorsToPrint) const; //TODO not defined diff --git a/moses/ExportInterface.cpp b/moses/ExportInterface.cpp index 2fccf3c48..ee5c8a70d 100644 --- a/moses/ExportInterface.cpp +++ b/moses/ExportInterface.cpp @@ -101,7 +101,7 @@ SimpleTranslationInterface::~SimpleTranslationInterface() //the simplified version of string input/output translation string SimpleTranslationInterface::translate(const string &inputString) { - boost::shared_ptr ioWrapper(new IOWrapper(StaticData::Instance().options())); + boost::shared_ptr ioWrapper(new IOWrapper(*StaticData::Instance().options())); // main loop over set of input sentences size_t sentEnd = inputString.rfind('\n'); //find the last \n, the input stream has to be appended with \n to be translated const string &newString = sentEnd != string::npos ? inputString : inputString + '\n'; @@ -180,7 +180,7 @@ batch_run() IFVERBOSE(1) PrintUserTime("Created input-output object"); // set up read/writing class: - boost::shared_ptr ioWrapper(new IOWrapper(staticData.options())); + boost::shared_ptr ioWrapper(new IOWrapper(*staticData.options())); UTIL_THROW_IF2(ioWrapper == NULL, "Error; Failed to create IO object" << " [" << HERE << "]"); diff --git a/moses/FF/ConstrainedDecoding.cpp b/moses/FF/ConstrainedDecoding.cpp index 3c13ed1d3..08feb0876 100644 --- a/moses/FF/ConstrainedDecoding.cpp +++ b/moses/FF/ConstrainedDecoding.cpp @@ -46,11 +46,12 @@ ConstrainedDecoding::ConstrainedDecoding(const std::string &line) ReadParameters(); } -void ConstrainedDecoding::Load(AllOptions const& opts) +void ConstrainedDecoding::Load(AllOptions::ptr const& opts) { + m_options = opts; const StaticData &staticData = StaticData::Instance(); bool addBeginEndWord - = ((opts.search.algo == CYKPlus) || (opts.search.algo == ChartIncremental)); + = ((opts->search.algo == CYKPlus) || (opts->search.algo == ChartIncremental)); for(size_t i = 0; i < m_paths.size(); ++i) { InputFileStream constraintFile(m_paths[i]); @@ -62,10 +63,10 @@ void ConstrainedDecoding::Load(AllOptions const& opts) Phrase phrase(0); if (vecStr.size() == 1) { sentenceID++; - phrase.CreateFromString(Output, opts.output.factor_order, vecStr[0], NULL); + phrase.CreateFromString(Output, opts->output.factor_order, vecStr[0], NULL); } else if (vecStr.size() == 2) { sentenceID = Scan(vecStr[0]); - phrase.CreateFromString(Output, opts.output.factor_order, vecStr[1], NULL); + phrase.CreateFromString(Output, opts->output.factor_order, vecStr[1], NULL); } else { UTIL_THROW(util::Exception, "Reference file not loaded"); } diff --git a/moses/FF/ConstrainedDecoding.h b/moses/FF/ConstrainedDecoding.h index 955bc06df..a695e3ce8 100644 --- a/moses/FF/ConstrainedDecoding.h +++ b/moses/FF/ConstrainedDecoding.h @@ -36,7 +36,7 @@ class ConstrainedDecoding : public StatefulFeatureFunction public: ConstrainedDecoding(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/CountNonTerms.cpp b/moses/FF/CountNonTerms.cpp index f49aecfc8..cab05de92 100644 --- a/moses/FF/CountNonTerms.cpp +++ b/moses/FF/CountNonTerms.cpp @@ -1,7 +1,6 @@ #include "CountNonTerms.h" #include "moses/Util.h" #include "moses/TargetPhrase.h" -#include "moses/StaticData.h" using namespace std; @@ -21,8 +20,6 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedScores) const { - const StaticData &staticData = StaticData::Instance(); - vector scores(m_numScoreComponents, 0); size_t indScore = 0; @@ -39,7 +36,7 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase if (m_targetSyntax) { for (size_t i = 0; i < targetPhrase.GetSize(); ++i) { const Word &word = targetPhrase.GetWord(i); - if (word.IsNonTerminal() && word != staticData.GetOutputDefaultNonTerminal()) { + if (word.IsNonTerminal() && word != m_options->syntax.output_default_non_terminal) { ++scores[indScore]; } } @@ -49,7 +46,7 @@ void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase if (m_sourceSyntax) { for (size_t i = 0; i < sourcePhrase.GetSize(); ++i) { const Word &word = sourcePhrase.GetWord(i); - if (word.IsNonTerminal() && word != staticData.GetInputDefaultNonTerminal()) { + if (word.IsNonTerminal() && word != m_options->syntax.input_default_non_terminal) { ++scores[indScore]; } } @@ -72,5 +69,12 @@ void CountNonTerms::SetParameter(const std::string& key, const std::string& valu } } +void +CountNonTerms:: +Load(AllOptions::ptr const& opts) +{ + m_options = opts; +} + } diff --git a/moses/FF/CountNonTerms.h b/moses/FF/CountNonTerms.h index a9f6e884b..dbe8158a2 100644 --- a/moses/FF/CountNonTerms.h +++ b/moses/FF/CountNonTerms.h @@ -7,6 +7,8 @@ namespace Moses class CountNonTerms : public StatelessFeatureFunction { + Word m_input_default_nonterminal; + Word m_output_default_nonterminal; public: CountNonTerms(const std::string &line); bool IsUseable(const FactorMask &mask) const { @@ -41,6 +43,7 @@ public: void SetParameter(const std::string& key, const std::string& value); + void Load(AllOptions::ptr const& opts); protected: bool m_all, m_sourceSyntax, m_targetSyntax; }; diff --git a/moses/FF/CoveredReferenceFeature.cpp b/moses/FF/CoveredReferenceFeature.cpp index 903f74e8c..4d058c863 100644 --- a/moses/FF/CoveredReferenceFeature.cpp +++ b/moses/FF/CoveredReferenceFeature.cpp @@ -52,8 +52,9 @@ void CoveredReferenceFeature::EvaluateWithSourceContext(const InputType &input estimatedScores->Assign(this, scores); } -void CoveredReferenceFeature::Load(AllOptions const& opts) +void CoveredReferenceFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; InputFileStream refFile(m_path); std::string line; const StaticData &staticData = StaticData::Instance(); diff --git a/moses/FF/CoveredReferenceFeature.h b/moses/FF/CoveredReferenceFeature.h index 6ca1a55f2..bb21b719f 100644 --- a/moses/FF/CoveredReferenceFeature.h +++ b/moses/FF/CoveredReferenceFeature.h @@ -44,7 +44,7 @@ public: ReadParameters(); } - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/DeleteRules.cpp b/moses/FF/DeleteRules.cpp index 928806960..32473b2cf 100644 --- a/moses/FF/DeleteRules.cpp +++ b/moses/FF/DeleteRules.cpp @@ -16,8 +16,9 @@ DeleteRules::DeleteRules(const std::string &line) ReadParameters(); } -void DeleteRules::Load(AllOptions const& opts) +void DeleteRules::Load(AllOptions::ptr const& opts) { + m_options = opts; std::vector factorOrder; factorOrder.push_back(0); // unfactored for now diff --git a/moses/FF/DeleteRules.h b/moses/FF/DeleteRules.h index 5250b9968..2decce4b3 100644 --- a/moses/FF/DeleteRules.h +++ b/moses/FF/DeleteRules.h @@ -15,7 +15,7 @@ protected: public: DeleteRules(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const { return true; diff --git a/moses/FF/DynamicCacheBasedLanguageModel.cpp b/moses/FF/DynamicCacheBasedLanguageModel.cpp index 2c41e37a7..f45e02bc1 100644 --- a/moses/FF/DynamicCacheBasedLanguageModel.cpp +++ b/moses/FF/DynamicCacheBasedLanguageModel.cpp @@ -323,8 +323,9 @@ void DynamicCacheBasedLanguageModel::Clear() m_cache.clear(); } -void DynamicCacheBasedLanguageModel::Load(AllOptions const& opts) +void DynamicCacheBasedLanguageModel::Load(AllOptions::ptr const& opts) { + m_options = opts; // SetPreComputedScores(); VERBOSE(2,"DynamicCacheBasedLanguageModel::Load()" << std::endl); Load(m_initfiles); diff --git a/moses/FF/DynamicCacheBasedLanguageModel.h b/moses/FF/DynamicCacheBasedLanguageModel.h index d32e55bd4..be3d07269 100644 --- a/moses/FF/DynamicCacheBasedLanguageModel.h +++ b/moses/FF/DynamicCacheBasedLanguageModel.h @@ -119,7 +119,7 @@ public: return true; } - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void Load(const std::string filestr); void Execute(std::string command); void SetParameter(const std::string& key, const std::string& value); diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h index 1b0f9ab6c..9d6aa6597 100644 --- a/moses/FF/FeatureFunction.h +++ b/moses/FF/FeatureFunction.h @@ -47,6 +47,7 @@ protected: size_t m_index; // index into vector covering ALL feature function values std::vector m_tuneableComponents; size_t m_numTuneableComponents; + AllOptions::ptr m_options; //In case there's multiple producers with the same description static std::multiset description_counts; @@ -70,7 +71,13 @@ public: virtual ~FeatureFunction(); //! override to load model files - virtual void Load(AllOptions const& opts) { + virtual void Load(AllOptions::ptr const& opts) { + m_options = opts; + } + + AllOptions::ptr const& + options() const { + return m_options; } static void ResetDescriptionCounts() { diff --git a/moses/FF/GlobalLexicalModel.cpp b/moses/FF/GlobalLexicalModel.cpp index c1178a269..89f27f4a1 100644 --- a/moses/FF/GlobalLexicalModel.cpp +++ b/moses/FF/GlobalLexicalModel.cpp @@ -51,8 +51,9 @@ GlobalLexicalModel::~GlobalLexicalModel() } } -void GlobalLexicalModel::Load(AllOptions const& opts) +void GlobalLexicalModel::Load(AllOptions::ptr const& opts) { + m_options = opts; FactorCollection &factorCollection = FactorCollection::Instance(); const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); diff --git a/moses/FF/GlobalLexicalModel.h b/moses/FF/GlobalLexicalModel.h index 7096b292d..1701195f7 100644 --- a/moses/FF/GlobalLexicalModel.h +++ b/moses/FF/GlobalLexicalModel.h @@ -57,7 +57,7 @@ private: std::vector m_inputFactorsVec, m_outputFactorsVec; std::string m_filePath; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); float ScorePhrase( const TargetPhrase& targetPhrase ) const; float GetFromCacheOrScorePhrase( const TargetPhrase& targetPhrase ) const; diff --git a/moses/FF/HyperParameterAsWeight.cpp b/moses/FF/HyperParameterAsWeight.cpp index 37516af52..043631356 100644 --- a/moses/FF/HyperParameterAsWeight.cpp +++ b/moses/FF/HyperParameterAsWeight.cpp @@ -19,8 +19,8 @@ HyperParameterAsWeight::HyperParameterAsWeight(const std::string &line) vector weights = staticData.GetWeights(this); - staticData.m_options.search.stack_size = weights[0] * 1000; - staticData.m_options.search.beam_width = weights[1] * 10; + staticData.m_options->search.stack_size = weights[0] * 1000; + staticData.m_options->search.beam_width = weights[1] * 10; } diff --git a/moses/FF/InputFeature.cpp b/moses/FF/InputFeature.cpp index a3edb578e..790c8cc61 100644 --- a/moses/FF/InputFeature.cpp +++ b/moses/FF/InputFeature.cpp @@ -23,9 +23,9 @@ InputFeature::InputFeature(const std::string &line) s_instance = this; } -void InputFeature::Load(AllOptions const& opts) +void InputFeature::Load(AllOptions::ptr const& opts) { - + m_options = opts; const PhraseDictionary *pt = PhraseDictionary::GetColl()[0]; const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast(pt); diff --git a/moses/FF/InputFeature.h b/moses/FF/InputFeature.h index 53e80eeb1..b2b3b4ff4 100644 --- a/moses/FF/InputFeature.h +++ b/moses/FF/InputFeature.h @@ -23,7 +23,7 @@ public: InputFeature(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void SetParameter(const std::string& key, const std::string& value); diff --git a/moses/FF/InternalTree.cpp b/moses/FF/InternalTree.cpp index f2b146bb9..dde0ad268 100644 --- a/moses/FF/InternalTree.cpp +++ b/moses/FF/InternalTree.cpp @@ -8,7 +8,7 @@ InternalTree::InternalTree(const std::string & line, size_t start, size_t len, c { std::vector const& oFactors - = StaticData::Instance().options().output.factor_order; + = StaticData::Instance().options()->output.factor_order; if (len > 0) { m_value.CreateFromString(Output, oFactors, StringPiece(line).substr(start, len), nonterminal); @@ -22,7 +22,7 @@ InternalTree::InternalTree(const std::string & line, const bool nonterminal) if (found == line.npos) { m_value.CreateFromString(Output, - StaticData::Instance().options().output.factor_order, + StaticData::Instance().options()->output.factor_order, line, nonterminal); } else { AddSubTree(line, 0); @@ -50,7 +50,7 @@ size_t InternalTree::AddSubTree(const std::string & line, size_t pos) } else { if (len > 0) { m_value.CreateFromString(Output, - StaticData::Instance().options().output.factor_order, + StaticData::Instance().options()->output.factor_order, StringPiece(line).substr(oldpos, len), false); has_value = true; } @@ -59,7 +59,7 @@ size_t InternalTree::AddSubTree(const std::string & line, size_t pos) } else if (token == ' ' || token == ']') { if (len > 0 && !has_value) { m_value.CreateFromString(Output, - StaticData::Instance().options().output.factor_order, + StaticData::Instance().options()->output.factor_order, StringPiece(line).substr(oldpos, len), true); has_value = true; } else if (len > 0) { @@ -90,7 +90,7 @@ std::string InternalTree::GetString(bool start) const ret += "["; } - ret += m_value.GetString(StaticData::Instance().options().output.factor_order, false); + ret += m_value.GetString(StaticData::Instance().options()->output.factor_order, false); for (std::vector::const_iterator it = m_children.begin(); it != m_children.end(); ++it) { ret += (*it)->GetString(false); } diff --git a/moses/FF/LexicalReordering/LexicalReordering.cpp b/moses/FF/LexicalReordering/LexicalReordering.cpp index bbfcb1eef..a3fc2c1d6 100644 --- a/moses/FF/LexicalReordering/LexicalReordering.cpp +++ b/moses/FF/LexicalReordering/LexicalReordering.cpp @@ -84,8 +84,9 @@ LexicalReordering:: void LexicalReordering:: -Load(AllOptions const& opts) +Load(AllOptions::ptr const& opts) { + m_options = opts; typedef LexicalReorderingTable LRTable; if (m_filePath.size()) m_table.reset(LRTable::LoadAvailable(m_filePath, m_factorsF, diff --git a/moses/FF/LexicalReordering/LexicalReordering.h b/moses/FF/LexicalReordering/LexicalReordering.h index 21a9791f0..bc21e6f32 100644 --- a/moses/FF/LexicalReordering/LexicalReordering.h +++ b/moses/FF/LexicalReordering/LexicalReordering.h @@ -33,7 +33,7 @@ class LexicalReordering : public StatefulFeatureFunction public: LexicalReordering(const std::string &line); virtual ~LexicalReordering(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual bool diff --git a/moses/FF/Model1Feature.cpp b/moses/FF/Model1Feature.cpp index 835c8de32..b5d23bd73 100644 --- a/moses/FF/Model1Feature.cpp +++ b/moses/FF/Model1Feature.cpp @@ -159,8 +159,9 @@ void Model1Feature::SetParameter(const std::string& key, const std::string& valu } } -void Model1Feature::Load(AllOptions const& opts) +void Model1Feature::Load(AllOptions::ptr const& opts) { + m_options = opts; FEATUREVERBOSE(2, GetScoreProducerDescription() << ": Loading source vocabulary from file " << m_fileNameVcbS << " ..."); Model1Vocabulary vcbS; vcbS.Load(m_fileNameVcbS); diff --git a/moses/FF/Model1Feature.h b/moses/FF/Model1Feature.h index 5a55df1f0..df7db4e2f 100644 --- a/moses/FF/Model1Feature.h +++ b/moses/FF/Model1Feature.h @@ -99,7 +99,7 @@ private: Model1LexicalTable m_model1; const Factor* m_emptyWord; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); // cache mutable boost::unordered_map > m_cache; diff --git a/moses/FF/OSM-Feature/OpSequenceModel.cpp b/moses/FF/OSM-Feature/OpSequenceModel.cpp index d0e539cef..4df2cbba6 100644 --- a/moses/FF/OSM-Feature/OpSequenceModel.cpp +++ b/moses/FF/OSM-Feature/OpSequenceModel.cpp @@ -35,8 +35,9 @@ void OpSequenceModel :: readLanguageModel(const char *lmFile) } -void OpSequenceModel::Load(AllOptions const& opts) +void OpSequenceModel::Load(AllOptions::ptr const& opts) { + m_options = opts; readLanguageModel(m_lmPath.c_str()); } diff --git a/moses/FF/OSM-Feature/OpSequenceModel.h b/moses/FF/OSM-Feature/OpSequenceModel.h index f6f8e8973..925f9c83a 100644 --- a/moses/FF/OSM-Feature/OpSequenceModel.h +++ b/moses/FF/OSM-Feature/OpSequenceModel.h @@ -25,7 +25,7 @@ public: ~OpSequenceModel(); void readLanguageModel(const char *); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); FFState* EvaluateWhenApplied( const Hypothesis& cur_hypo, diff --git a/moses/FF/PhraseOrientationFeature.cpp b/moses/FF/PhraseOrientationFeature.cpp index ca75eded0..9cac75ccb 100644 --- a/moses/FF/PhraseOrientationFeature.cpp +++ b/moses/FF/PhraseOrientationFeature.cpp @@ -75,8 +75,9 @@ void PhraseOrientationFeature::SetParameter(const std::string& key, const std::s } -void PhraseOrientationFeature::Load(AllOptions const& opts) +void PhraseOrientationFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if ( !m_filenameTargetWordList.empty() ) { LoadWordList(m_filenameTargetWordList,m_targetWordList); m_useTargetWordList = true; diff --git a/moses/FF/PhraseOrientationFeature.h b/moses/FF/PhraseOrientationFeature.h index fd86aa92e..e24a37810 100644 --- a/moses/FF/PhraseOrientationFeature.h +++ b/moses/FF/PhraseOrientationFeature.h @@ -289,7 +289,7 @@ public: void SetParameter(const std::string& key, const std::string& value); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void EvaluateInIsolation(const Phrase &source , const TargetPhrase &targetPhrase diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp index e761a87a8..04878e2c6 100644 --- a/moses/FF/PhrasePairFeature.cpp +++ b/moses/FF/PhrasePairFeature.cpp @@ -65,8 +65,9 @@ void PhrasePairFeature::SetParameter(const std::string& key, const std::string& } } -void PhrasePairFeature::Load(AllOptions const& opts) +void PhrasePairFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if (m_domainTrigger) { // domain trigger terms for each input document ifstream inFileSource(m_filePathSource.c_str()); diff --git a/moses/FF/PhrasePairFeature.h b/moses/FF/PhrasePairFeature.h index 2f5ce39a7..53bf27628 100644 --- a/moses/FF/PhrasePairFeature.h +++ b/moses/FF/PhrasePairFeature.h @@ -44,7 +44,7 @@ class PhrasePairFeature: public StatelessFeatureFunction public: PhrasePairFeature(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void SetParameter(const std::string& key, const std::string& value); bool IsUseable(const FactorMask &mask) const; diff --git a/moses/FF/RuleScope.cpp b/moses/FF/RuleScope.cpp index 8a18e0a28..38583e0ff 100644 --- a/moses/FF/RuleScope.cpp +++ b/moses/FF/RuleScope.cpp @@ -14,11 +14,11 @@ RuleScope::RuleScope(const std::string &line) { } -bool IsAmbiguous(const Word &word, bool sourceSyntax) -{ - const Word &inputDefaultNonTerminal = StaticData::Instance().GetInputDefaultNonTerminal(); - return word.IsNonTerminal() && (!sourceSyntax || word == inputDefaultNonTerminal); -} +// bool IsAmbiguous(const Word &word, bool sourceSyntax) +// { +// const Word &inputDefaultNonTerminal = StaticData::Instance().GetInputDefaultNonTerminal(); +// return word.IsNonTerminal() && (!sourceSyntax || word == inputDefaultNonTerminal); +// } void RuleScope::EvaluateInIsolation(const Phrase &source , const TargetPhrase &targetPhrase diff --git a/moses/FF/SoftMatchingFeature.cpp b/moses/FF/SoftMatchingFeature.cpp index e3b36fa74..e1eed9df2 100644 --- a/moses/FF/SoftMatchingFeature.cpp +++ b/moses/FF/SoftMatchingFeature.cpp @@ -52,8 +52,8 @@ bool SoftMatchingFeature::Load(const std::string& filePath) } Word LHS, RHS; - LHS.CreateFromString(Output, SD.options().output.factor_order, tokens[0], true); - RHS.CreateFromString(Output, SD.options().output.factor_order, tokens[1], true); + LHS.CreateFromString(Output, SD.options()->output.factor_order, tokens[0], true); + RHS.CreateFromString(Output, SD.options()->output.factor_order, tokens[1], true); m_softMatches[RHS[0]->GetId()].push_back(LHS); GetOrSetFeatureName(RHS, LHS); @@ -125,7 +125,7 @@ const std::string& SoftMatchingFeature::GetOrSetFeatureName(const Word& RHS, con #endif std::string &name = m_nameCache[RHS[0]->GetId()][LHS[0]->GetId()]; const std::vector & oFactors - = StaticData::Instance().options().output.factor_order; + = StaticData::Instance().options()->output.factor_order; std::string LHS_string = LHS.GetString(oFactors, false); std::string RHS_string = RHS.GetString(oFactors, false); name = LHS_string + "->" + RHS_string; diff --git a/moses/FF/SoftSourceSyntacticConstraintsFeature.cpp b/moses/FF/SoftSourceSyntacticConstraintsFeature.cpp index 133e14326..dc58350b3 100644 --- a/moses/FF/SoftSourceSyntacticConstraintsFeature.cpp +++ b/moses/FF/SoftSourceSyntacticConstraintsFeature.cpp @@ -88,8 +88,9 @@ void SoftSourceSyntacticConstraintsFeature::SetParameter(const std::string& key, } } -void SoftSourceSyntacticConstraintsFeature::Load(AllOptions const& opts) +void SoftSourceSyntacticConstraintsFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; // don't change the loading order! LoadSourceLabelSet(); if (!m_coreSourceLabelSetFile.empty()) { @@ -98,6 +99,7 @@ void SoftSourceSyntacticConstraintsFeature::Load(AllOptions const& opts) if (!m_targetSourceLHSJointCountFile.empty()) { LoadTargetSourceLeftHandSideJointCountFile(); } + // m_output_default_nonterminal = opts->syntax.output_default_non_terminal; } void SoftSourceSyntacticConstraintsFeature::LoadSourceLabelSet() @@ -311,8 +313,8 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu std::vector newScores(m_numScoreComponents,0); const TreeInput& treeInput = static_cast(input); - const StaticData& staticData = StaticData::Instance(); - const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal(); + // const StaticData& staticData = StaticData::Instance(); + // const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal(); size_t nNTs = 1; bool treeInputMismatchLHSBinary = true; @@ -365,7 +367,7 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu for (NonTerminalSet::const_iterator treeInputLabelsIt = treeInputLabels.begin(); treeInputLabelsIt != treeInputLabels.end(); ++treeInputLabelsIt) { - if (*treeInputLabelsIt != outputDefaultNonTerminal) { + if (*treeInputLabelsIt != m_options->syntax.output_default_non_terminal) { boost::unordered_map::const_iterator foundTreeInputLabel = m_sourceLabelIndexesByFactor.find((*treeInputLabelsIt)[0]); if (foundTreeInputLabel != m_sourceLabelIndexesByFactor.end()) { @@ -387,7 +389,7 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu for (NonTerminalSet::const_iterator treeInputLabelsIt = treeInputLabels.begin(); treeInputLabelsIt != treeInputLabels.end(); ++treeInputLabelsIt) { - if (*treeInputLabelsIt != outputDefaultNonTerminal) { + if (*treeInputLabelsIt != m_options->syntax.output_default_non_terminal) { boost::unordered_map::const_iterator foundTreeInputLabel = m_sourceLabelIndexesByFactor.find((*treeInputLabelsIt)[0]); if (foundTreeInputLabel != m_sourceLabelIndexesByFactor.end()) { @@ -568,7 +570,9 @@ void SoftSourceSyntacticConstraintsFeature::EvaluateWithSourceContext(const Inpu } if ( treeInputLabelsLHS.size() == 0 ) { scoreBreakdown.PlusEquals(this, - "LHSPAIR_" + targetLHS->GetString().as_string() + "_" + outputDefaultNonTerminal[0]->GetString().as_string(), + "LHSPAIR_" + targetLHS->GetString().as_string() + "_" + + m_options->syntax.output_default_non_terminal[0] + ->GetString().as_string(), 1); if (!m_targetSourceLHSJointCountFile.empty()) { t2sLabelsScore = TransformScore(m_floor); diff --git a/moses/FF/SoftSourceSyntacticConstraintsFeature.h b/moses/FF/SoftSourceSyntacticConstraintsFeature.h index 410940076..459e38521 100644 --- a/moses/FF/SoftSourceSyntacticConstraintsFeature.h +++ b/moses/FF/SoftSourceSyntacticConstraintsFeature.h @@ -31,7 +31,7 @@ public: void SetParameter(const std::string& key, const std::string& value); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void EvaluateInIsolation(const Phrase &source , const TargetPhrase &targetPhrase @@ -101,6 +101,7 @@ protected: std::pair GetLabelPairProbabilities(const Factor* target, const size_t source) const; + // Word m_output_default_nonterminal; }; diff --git a/moses/FF/SourceGHKMTreeInputMatchFeature.cpp b/moses/FF/SourceGHKMTreeInputMatchFeature.cpp index 148eb3013..22b160989 100644 --- a/moses/FF/SourceGHKMTreeInputMatchFeature.cpp +++ b/moses/FF/SourceGHKMTreeInputMatchFeature.cpp @@ -47,11 +47,12 @@ void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType const Word& lhsLabel = targetPhrase.GetTargetLHS(); const StaticData& staticData = StaticData::Instance(); - const Word& outputDefaultNonTerminal = staticData.GetOutputDefaultNonTerminal(); - std::vector newScores(m_numScoreComponents,0.0); // m_numScoreComponents == 2 // first fires for matches, second for mismatches + std::vector newScores(m_numScoreComponents,0.0); + // m_numScoreComponents == 2 // first fires for matches, second for mismatches - if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end()) && (lhsLabel != outputDefaultNonTerminal) ) { + if ( (treeInputLabels.find(lhsLabel) != treeInputLabels.end()) + && (lhsLabel != m_options->syntax.output_default_non_terminal) ) { // match newScores[0] = 1.0; } else { @@ -62,6 +63,13 @@ void SourceGHKMTreeInputMatchFeature::EvaluateWithSourceContext(const InputType scoreBreakdown.PlusEquals(this, newScores); } +void +SourceGHKMTreeInputMatchFeature:: +Load(AllOptions::ptr const& opts) +{ + m_options = opts; + // m_output_default_nonterminal = opts->syntax.output_default_non_terminal; +} } diff --git a/moses/FF/SourceGHKMTreeInputMatchFeature.h b/moses/FF/SourceGHKMTreeInputMatchFeature.h index b67649b26..6c1cc8c59 100644 --- a/moses/FF/SourceGHKMTreeInputMatchFeature.h +++ b/moses/FF/SourceGHKMTreeInputMatchFeature.h @@ -1,6 +1,7 @@ #pragma once #include "StatelessFeatureFunction.h" +#include "moses/parameters/AllOptions.h" namespace Moses { @@ -8,6 +9,7 @@ namespace Moses // assumes that source-side syntax labels are stored in the target non-terminal field of the rules class SourceGHKMTreeInputMatchFeature : public StatelessFeatureFunction { + // Word m_output_default_nonterminal; public: SourceGHKMTreeInputMatchFeature(const std::string &line); @@ -40,6 +42,7 @@ public: void EvaluateWhenApplied(const ChartHypothesis &hypo, ScoreComponentCollection* accumulator) const {}; + void Load(AllOptions::ptr const& opts); }; diff --git a/moses/FF/SourceWordDeletionFeature.cpp b/moses/FF/SourceWordDeletionFeature.cpp index 423dca230..e4b1babec 100644 --- a/moses/FF/SourceWordDeletionFeature.cpp +++ b/moses/FF/SourceWordDeletionFeature.cpp @@ -36,8 +36,9 @@ void SourceWordDeletionFeature::SetParameter(const std::string& key, const std:: } } -void SourceWordDeletionFeature::Load(AllOptions const& opts) +void SourceWordDeletionFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if (m_filename.empty()) return; diff --git a/moses/FF/SourceWordDeletionFeature.h b/moses/FF/SourceWordDeletionFeature.h index 5f25e8061..0257621ea 100644 --- a/moses/FF/SourceWordDeletionFeature.h +++ b/moses/FF/SourceWordDeletionFeature.h @@ -23,7 +23,7 @@ private: public: SourceWordDeletionFeature(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const; diff --git a/moses/FF/TargetBigramFeature.cpp b/moses/FF/TargetBigramFeature.cpp index 021e702a6..a6f3249e6 100644 --- a/moses/FF/TargetBigramFeature.cpp +++ b/moses/FF/TargetBigramFeature.cpp @@ -48,8 +48,9 @@ void TargetBigramFeature::SetParameter(const std::string& key, const std::string } } -void TargetBigramFeature::Load(AllOptions const& opts) +void TargetBigramFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if (m_filePath == "*") return ; //allow all ifstream inFile(m_filePath.c_str()); diff --git a/moses/FF/TargetBigramFeature.h b/moses/FF/TargetBigramFeature.h index 5bb3950ee..a12f3d25d 100644 --- a/moses/FF/TargetBigramFeature.h +++ b/moses/FF/TargetBigramFeature.h @@ -34,7 +34,7 @@ class TargetBigramFeature : public StatefulFeatureFunction public: TargetBigramFeature(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const; diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp index d545ebfca..42d014f85 100644 --- a/moses/FF/TargetNgramFeature.cpp +++ b/moses/FF/TargetNgramFeature.cpp @@ -74,8 +74,9 @@ void TargetNgramFeature::SetParameter(const std::string& key, const std::string& } } -void TargetNgramFeature::Load(AllOptions const& opts) +void TargetNgramFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if (m_file == "") return; //allow all, for now if (m_file == "*") return; //allow all diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h index 10a7447e4..830a73657 100644 --- a/moses/FF/TargetNgramFeature.h +++ b/moses/FF/TargetNgramFeature.h @@ -203,7 +203,7 @@ class TargetNgramFeature : public StatefulFeatureFunction public: TargetNgramFeature(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); bool IsUseable(const FactorMask &mask) const; diff --git a/moses/FF/TargetWordInsertionFeature.cpp b/moses/FF/TargetWordInsertionFeature.cpp index 0b723a27d..dd097f8e3 100644 --- a/moses/FF/TargetWordInsertionFeature.cpp +++ b/moses/FF/TargetWordInsertionFeature.cpp @@ -34,8 +34,9 @@ void TargetWordInsertionFeature::SetParameter(const std::string& key, const std: } } -void TargetWordInsertionFeature::Load(AllOptions const& opts) +void TargetWordInsertionFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; if (m_filename.empty()) return; diff --git a/moses/FF/TargetWordInsertionFeature.h b/moses/FF/TargetWordInsertionFeature.h index e26a53077..d06f32481 100644 --- a/moses/FF/TargetWordInsertionFeature.h +++ b/moses/FF/TargetWordInsertionFeature.h @@ -25,7 +25,7 @@ public: bool IsUseable(const FactorMask &mask) const; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual void EvaluateInIsolation(const Phrase &source , const TargetPhrase &targetPhrase diff --git a/moses/FF/TreeStructureFeature.cpp b/moses/FF/TreeStructureFeature.cpp index c46dbb901..b83ef81ea 100644 --- a/moses/FF/TreeStructureFeature.cpp +++ b/moses/FF/TreeStructureFeature.cpp @@ -8,8 +8,9 @@ namespace Moses { -void TreeStructureFeature::Load(AllOptions const& opts) +void TreeStructureFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; // syntactic constraints can be hooked in here. m_constraints = NULL; diff --git a/moses/FF/TreeStructureFeature.h b/moses/FF/TreeStructureFeature.h index 7f6cfdbb8..366b84fd2 100644 --- a/moses/FF/TreeStructureFeature.h +++ b/moses/FF/TreeStructureFeature.h @@ -74,7 +74,7 @@ public: int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); }; diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp index 580483ad6..6fcffff1a 100644 --- a/moses/FF/WordTranslationFeature.cpp +++ b/moses/FF/WordTranslationFeature.cpp @@ -87,8 +87,9 @@ void WordTranslationFeature::SetParameter(const std::string& key, const std::str } } -void WordTranslationFeature::Load(AllOptions const& opts) +void WordTranslationFeature::Load(AllOptions::ptr const& opts) { + m_options = opts; // load word list for restricted feature set if (m_filePathSource.empty()) { return; diff --git a/moses/FF/WordTranslationFeature.h b/moses/FF/WordTranslationFeature.h index a5d92ab32..b3c3c18e2 100644 --- a/moses/FF/WordTranslationFeature.h +++ b/moses/FF/WordTranslationFeature.h @@ -40,7 +40,7 @@ public: void SetParameter(const std::string& key, const std::string& value); bool IsUseable(const FactorMask &mask) const; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void EvaluateWithSourceContext(const InputType &input , const InputPath &inputPath diff --git a/moses/ForestInput.cpp b/moses/ForestInput.cpp index 57b8fa472..108012518 100644 --- a/moses/ForestInput.cpp +++ b/moses/ForestInput.cpp @@ -18,9 +18,7 @@ namespace Moses //! populate this InputType with data from in stream int ForestInput:: -Read(std::istream &in, - std::vector const& factorOrder, - AllOptions const& opts) +Read(std::istream &in) { using Syntax::F2S::Forest; @@ -48,7 +46,7 @@ Read(std::istream &in, std::getline(in, line); } else { do { - ParseHyperedgeLine(line, factorOrder); + ParseHyperedgeLine(line); std::getline(in, line); } while (line != ""); } @@ -58,7 +56,7 @@ Read(std::istream &in, // not sure ForestInput needs to. std::stringstream strme; strme << " " << sentence << " " << std::endl; - Sentence::Read(strme, factorOrder, opts); + Sentence::Read(strme); // Find the maximum end position of any vertex (0 if forest is empty). std::size_t maxEnd = FindMaxEnd(*m_forest); @@ -70,6 +68,9 @@ Read(std::istream &in, assert(topVertices.size() >= 1); } + + const std::vector& factorOrder = m_options->input.factor_order; + // Add vertex. Forest::Vertex *startSymbol = NULL; { @@ -122,7 +123,9 @@ Read(std::istream &in, return 1; } -Syntax::F2S::Forest::Vertex *ForestInput::AddOrDeleteVertex(Forest::Vertex *v) +Syntax::F2S::Forest::Vertex* +ForestInput:: +AddOrDeleteVertex(Forest::Vertex *v) { std::pair ret = m_vertexSet.insert(v); if (ret.second) { @@ -172,14 +175,16 @@ void ForestInput::FindTopVertices(Forest &forest, std::back_inserter(topVertices)); } -void ForestInput::ParseHyperedgeLine( - const std::string &line, const std::vector& factorOrder) +void +ForestInput:: +ParseHyperedgeLine(const std::string &line) { + const std::vector& factorOrder = m_options->input.factor_order; using Syntax::F2S::Forest; const util::AnyCharacter delimiter(" \t"); util::TokenIter p(line, delimiter); - Forest::Vertex *v = AddOrDeleteVertex(ParseVertex(*p, factorOrder)); + Forest::Vertex *v = AddOrDeleteVertex(ParseVertex(*p)); Forest::Hyperedge *e = new Forest::Hyperedge(); e->head = v; ++p; @@ -188,7 +193,7 @@ void ForestInput::ParseHyperedgeLine( //throw Exception(""); } for (++p; *p != "|||"; ++p) { - v = ParseVertex(*p, factorOrder); + v = ParseVertex(*p); if (!v->pvertex.symbol.IsNonTerminal()) { // Egret does not give start/end for terminals. v->pvertex.span = Range(e->head->pvertex.span.GetStartPos(), @@ -203,11 +208,11 @@ void ForestInput::ParseHyperedgeLine( e->head->incoming.push_back(e); } -Syntax::F2S::Forest::Vertex *ForestInput::ParseVertex( - const StringPiece &s, const std::vector& factorOrder) +Syntax::F2S::Forest::Vertex* +ForestInput::ParseVertex(const StringPiece &s) { using Syntax::F2S::Forest; - + const std::vector& factorOrder = m_options->input.factor_order; Word symbol; std::size_t pos = s.rfind('['); if (pos == std::string::npos) { diff --git a/moses/ForestInput.h b/moses/ForestInput.h index b9c8a7026..88d2ecbbd 100644 --- a/moses/ForestInput.h +++ b/moses/ForestInput.h @@ -29,9 +29,7 @@ public: //! populate this InputType with data from in stream virtual int - Read(std::istream& in, - std::vector const& factorOrder, - AllOptions const& opts); + Read(std::istream& in); //! Output debugging info to stream out virtual void Print(std::ostream&) const; @@ -76,11 +74,9 @@ private: void FindTopVertices(Forest &, std::vector &); - void ParseHyperedgeLine(const std::string &, - const std::vector &); + void ParseHyperedgeLine(const std::string &); - Forest::Vertex *ParseVertex(const StringPiece &, - const std::vector &); + Forest::Vertex *ParseVertex(const StringPiece &); boost::shared_ptr m_forest; Forest::Vertex *m_rootVertex; diff --git a/moses/GenerationDictionary.cpp b/moses/GenerationDictionary.cpp index 6cffd2da9..29a4fa2b3 100644 --- a/moses/GenerationDictionary.cpp +++ b/moses/GenerationDictionary.cpp @@ -44,8 +44,9 @@ GenerationDictionary::GenerationDictionary(const std::string &line) ReadParameters(); } -void GenerationDictionary::Load(AllOptions const& opts) +void GenerationDictionary::Load(AllOptions::ptr const& opts) { + m_options = opts; FactorCollection &factorCollection = FactorCollection::Instance(); const size_t numFeatureValuesInConfig = this->GetNumScoreComponents(); diff --git a/moses/GenerationDictionary.h b/moses/GenerationDictionary.h index bda09e579..11ebd5e27 100644 --- a/moses/GenerationDictionary.h +++ b/moses/GenerationDictionary.h @@ -62,7 +62,7 @@ public: virtual ~GenerationDictionary(); //! load data file - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); /** number of unique input entries in the generation table. * NOT the number of lines in the generation table diff --git a/moses/HypergraphOutput.cpp b/moses/HypergraphOutput.cpp index 373c2109f..9f94a6cf3 100644 --- a/moses/HypergraphOutput.cpp +++ b/moses/HypergraphOutput.cpp @@ -56,7 +56,7 @@ WriteHypos(const ChartHypothesisCollection& hypos, ChartHypothesisCollection::const_iterator iter; for (iter = hypos.begin() ; iter != hypos.end() ; ++iter) { ChartHypothesis &mainHypo = **iter; - if (StaticData::Instance().options().output.DontPruneSearchGraph || + if (StaticData::Instance().options()->output.DontPruneSearchGraph || reachable.find(mainHypo.GetId()) != reachable.end()) { (*m_out) << m_lineNumber << " " << mainHypo << endl; } @@ -90,7 +90,7 @@ WriteHypos(const ChartHypothesisCollection& hypos, ChartHypothesisCollection::const_iterator iter; for (iter = hypos.begin() ; iter != hypos.end() ; ++iter) { const ChartHypothesis* mainHypo = *iter; - if (!StaticData::Instance().options().output.DontPruneSearchGraph && + if (!StaticData::Instance().options()->output.DontPruneSearchGraph && reachable.find(mainHypo->GetId()) == reachable.end()) { //Ignore non reachable nodes continue; diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index f9eb24dc6..8049a2893 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -78,20 +78,19 @@ IOWrapper::IOWrapper(AllOptions const& opts) Parameter const& P = staticData.GetParameter(); // context buffering for context-sensitive decoding - m_look_ahead = staticData.options().context.look_ahead; - m_look_back = staticData.options().context.look_back; - - m_inputType = staticData.options().input.input_type; + m_look_ahead = staticData.options()->context.look_ahead; + m_look_back = staticData.options()->context.look_back; + m_inputType = staticData.options()->input.input_type; UTIL_THROW_IF2((m_look_ahead || m_look_back) && m_inputType != SentenceInput, "Context-sensitive decoding currently works only with sentence input."); m_currentLine = staticData.GetStartTranslationId(); - m_inputFactorOrder = &staticData.options().input.factor_order; + m_inputFactorOrder = &staticData.options()->input.factor_order; - size_t nBestSize = staticData.options().nbest.nbest_size; - string nBestFilePath = staticData.options().nbest.output_file_path; + size_t nBestSize = staticData.options()->nbest.nbest_size; + string nBestFilePath = staticData.options()->nbest.output_file_path; staticData.GetParameter().SetParameter(m_inputFilePath, "input-file", ""); if (m_inputFilePath.empty()) { @@ -130,8 +129,8 @@ IOWrapper::IOWrapper(AllOptions const& opts) P.SetParameter(path, "output-word-graph", ""); if (path.size()) m_wordGraphCollector.reset(new OutputCollector(path)); - size_t latticeSamplesSize = staticData.options().output.lattice_sample_size; - string latticeSamplesFile = staticData.options().output.lattice_sample_filepath; + size_t latticeSamplesSize = staticData.options()->output.lattice_sample_size; + string latticeSamplesFile = staticData.options()->output.lattice_sample_filepath; if (latticeSamplesSize) { m_latticeSamplesCollector.reset(new OutputCollector(latticeSamplesFile)); if (m_latticeSamplesCollector->OutputIsCout()) { diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index 71c76c5e8..1301bc087 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -219,7 +219,6 @@ boost::shared_ptr IOWrapper:: BufferInput() { - AllOptions const& opts = StaticData::Instance().options(); boost::shared_ptr source; boost::shared_ptr ret; if (m_future_input.size()) { @@ -228,13 +227,13 @@ BufferInput() m_buffered_ahead -= ret->GetSize(); } else { source.reset(new itype(m_options)); - if (!source->Read(*m_inputStream, *m_inputFactorOrder, opts)) + if (!source->Read(*m_inputStream)) return ret; ret = source; } while (m_buffered_ahead < m_look_ahead) { source.reset(new itype(m_options)); - if (!source->Read(*m_inputStream, *m_inputFactorOrder, opts)) + if (!source->Read(*m_inputStream)) break; m_future_input.push_back(source); m_buffered_ahead += source->GetSize(); diff --git a/moses/Incremental.cpp b/moses/Incremental.cpp index e67550548..d6f589b15 100644 --- a/moses/Incremental.cpp +++ b/moses/Incremental.cpp @@ -208,7 +208,7 @@ Manager::Manager(ttasksptr const& ttask) : BaseManager(ttask) , cells_(m_source, ChartCellBaseFactory(), parser_) , parser_(ttask, cells_) - , n_best_(search::NBestConfig(StaticData::Instance().options().nbest.nbest_size)) + , n_best_(search::NBestConfig(StaticData::Instance().options()->nbest.nbest_size)) { } Manager::~Manager() @@ -232,8 +232,8 @@ PopulateBest(const Model &model, const std::vector &words, Best & const StaticData &data = StaticData::Instance(); const float lm_weight = data.GetWeights(&abstract)[0]; const float oov_weight = abstract.OOVFeatureEnabled() ? data.GetWeights(&abstract)[1] : 0.0; - size_t cpl = data.options().cube.pop_limit; - size_t nbs = data.options().nbest.nbest_size; + size_t cpl = data.options()->cube.pop_limit; + size_t nbs = data.options()->nbest.nbest_size; search::Config config(lm_weight * log_10, cpl, search::NBestConfig(nbs)); search::Context context(config, model); @@ -261,7 +261,7 @@ PopulateBest(const Model &model, const std::vector &words, Best & template void Manager::LMCallback(const Model &model, const std::vector &words) { - std::size_t nbest = StaticData::Instance().options().nbest.nbest_size; + std::size_t nbest = StaticData::Instance().options()->nbest.nbest_size; if (nbest <= 1) { search::History ret = PopulateBest(model, words, single_best_); if (ret) { diff --git a/moses/InputType.cpp b/moses/InputType.cpp index a47c03ff7..34894523f 100644 --- a/moses/InputType.cpp +++ b/moses/InputType.cpp @@ -29,9 +29,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA namespace Moses { - InputType::InputType(AllOptions::ptr const& opts, long translationId) +InputType::InputType(AllOptions::ptr const& opts, long translationId) : m_options(opts) , m_translationId(translationId) + , m_reorderingConstraint(opts->reordering.max_distortion) { m_frontSpanCoveredLength = 0; m_sourceCompleted.resize(0); diff --git a/moses/InputType.h b/moses/InputType.h index b320396e0..1e40c158e 100644 --- a/moses/InputType.h +++ b/moses/InputType.h @@ -190,9 +190,10 @@ public: //! populate this InputType with data from in stream virtual int - Read(std::istream& in, - std::vector const& factorOrder, - AllOptions const& opts) =0; + Read(std::istream& in) = 0; + // , + // std::vector const& factorOrder, + // AllOptions const& opts) =0; //! Output debugging info to stream out virtual void Print(std::ostream&) const =0; diff --git a/moses/LM/BilingualLM.cpp b/moses/LM/BilingualLM.cpp index bcc4580a6..8fc88c597 100644 --- a/moses/LM/BilingualLM.cpp +++ b/moses/LM/BilingualLM.cpp @@ -20,8 +20,9 @@ BilingualLM::BilingualLM(const std::string &line) } -void BilingualLM::Load(AllOptions const& opts) +void BilingualLM::Load(AllOptions::ptr const& opts) { + m_options = opts; ReadParameters(); loadModel(); } diff --git a/moses/LM/BilingualLM.h b/moses/LM/BilingualLM.h index dd824a643..ed9d99489 100644 --- a/moses/LM/BilingualLM.h +++ b/moses/LM/BilingualLM.h @@ -117,7 +117,7 @@ public: return new BilingualLMState(0); } - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); FFState* EvaluateWhenApplied( const Hypothesis& cur_hypo, diff --git a/moses/LM/DALMWrapper.h b/moses/LM/DALMWrapper.h index b296d17d4..4898dd66c 100644 --- a/moses/LM/DALMWrapper.h +++ b/moses/LM/DALMWrapper.h @@ -28,7 +28,7 @@ public: LanguageModelDALM(const std::string &line); virtual ~LanguageModelDALM(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual const FFState *EmptyHypothesisState(const InputType &/*input*/) const; diff --git a/moses/LM/IRST.cpp b/moses/LM/IRST.cpp index 9823b4039..10fcdcd9f 100644 --- a/moses/LM/IRST.cpp +++ b/moses/LM/IRST.cpp @@ -96,7 +96,7 @@ bool LanguageModelIRST::IsUseable(const FactorMask &mask) const return ret; } -void LanguageModelIRST::Load(AllOptions const& opts) + void LanguageModelIRST::Load(AllOptions::ptr const& opts) { FactorCollection &factorCollection = FactorCollection::Instance(); diff --git a/moses/LM/IRST.h b/moses/LM/IRST.h index f066a91d2..b4c080378 100644 --- a/moses/LM/IRST.h +++ b/moses/LM/IRST.h @@ -88,7 +88,7 @@ public: bool IsUseable(const FactorMask &mask) const; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); const FFState *EmptyHypothesisState(const InputType &/*input*/) const; virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = NULL) const; diff --git a/moses/LM/MaxEntSRI.h b/moses/LM/MaxEntSRI.h index 5f80029ca..1f3004e0f 100644 --- a/moses/LM/MaxEntSRI.h +++ b/moses/LM/MaxEntSRI.h @@ -54,7 +54,7 @@ protected: public: LanguageModelMaxEntSRI(const std::string &line); ~LanguageModelMaxEntSRI(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = 0) const; }; diff --git a/moses/LM/NeuralLMWrapper.h b/moses/LM/NeuralLMWrapper.h index 2114e87fc..66a0278a9 100644 --- a/moses/LM/NeuralLMWrapper.h +++ b/moses/LM/NeuralLMWrapper.h @@ -27,7 +27,7 @@ public: virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = 0) const; - virtual void Load(AllOptions const& opts); + virtual void Load(AllOptions::ptr const& opts); }; diff --git a/moses/LM/RDLM.h b/moses/LM/RDLM.h index 40f0344f1..8fdc9d641 100644 --- a/moses/LM/RDLM.h +++ b/moses/LM/RDLM.h @@ -208,7 +208,7 @@ public: int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const; - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); // Iterator-class that yields all children of a node; if child is virtual node of binarized tree, its children are yielded instead. class UnbinarizedChildren diff --git a/moses/LM/Rand.h b/moses/LM/Rand.h index 25d7896bf..54b5738b6 100644 --- a/moses/LM/Rand.h +++ b/moses/LM/Rand.h @@ -39,7 +39,7 @@ public: LanguageModelRandLM(const std::string &line); ~LanguageModelRandLM(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = NULL) const; void InitializeForInput(ttasksptr const& ttask); void CleanUpAfterSentenceProcessing(const InputType& source); diff --git a/moses/LM/SRI.h b/moses/LM/SRI.h index 76f34eedc..0a6139832 100644 --- a/moses/LM/SRI.h +++ b/moses/LM/SRI.h @@ -54,7 +54,7 @@ protected: public: LanguageModelSRI(const std::string &line); ~LanguageModelSRI(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = 0) const; }; diff --git a/moses/LM/oxlm/OxLM.h b/moses/LM/oxlm/OxLM.h index 11a86a4a4..5c73cd6c7 100644 --- a/moses/LM/oxlm/OxLM.h +++ b/moses/LM/oxlm/OxLM.h @@ -24,7 +24,7 @@ public: void SetParameter(const std::string& key, const std::string& value); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual LMResult GetValue( const std::vector &contextFactor, diff --git a/moses/MockHypothesis.cpp b/moses/MockHypothesis.cpp index 4e7503eaa..de74dae5e 100644 --- a/moses/MockHypothesis.cpp +++ b/moses/MockHypothesis.cpp @@ -38,9 +38,8 @@ MockHypothesisGuard m_uwp("UnknownWordPenalty"), m_dist("Distortion") { BOOST_CHECK_EQUAL(alignments.size(), targetSegments.size()); - std::vector factors(1,0); - AllOptions::ptr opts(new AllOptions(StaticData::Instance().options())); - m_sentence.reset(new Sentence(opts,0, sourceSentence, &factors)); + AllOptions::ptr opts(new AllOptions(*StaticData::Instance().options())); + m_sentence.reset(new Sentence(opts, 0, sourceSentence)); m_ttask = TranslationTask::create(m_sentence); m_manager.reset(new Manager(m_ttask)); @@ -59,16 +58,14 @@ MockHypothesisGuard for (; ti != targetSegments.end() && ai != alignments.end(); ++ti,++ai) { Hypothesis* prevHypo = m_hypothesis; Range range(ai->first,ai->second); - const Bitmap &newBitmap = bitmaps.GetBitmap(prevHypo->GetWordsBitmap(), - range); - + const Bitmap &newBitmap = bitmaps.GetBitmap(prevHypo->GetWordsBitmap(), range); m_targetPhrases.push_back(TargetPhrase(NULL)); - // m_targetPhrases.back().CreateFromString(Input, factors, *ti, "|", NULL); + vector const& factors = opts->output.factor_order; m_targetPhrases.back().CreateFromString(Input, factors, *ti, NULL); m_toptions.push_back(new TranslationOption (range,m_targetPhrases.back())); - m_hypothesis = new Hypothesis(*prevHypo, *m_toptions.back(), newBitmap, m_manager->GetNextHypoId()); - + m_hypothesis = new Hypothesis(*prevHypo, *m_toptions.back(), newBitmap, + m_manager->GetNextHypoId()); } diff --git a/moses/Phrase.cpp b/moses/Phrase.cpp index 052918295..eba0ed9c5 100644 --- a/moses/Phrase.cpp +++ b/moses/Phrase.cpp @@ -119,7 +119,7 @@ Phrase:: GetStringRep(vector const& factorsToPrint, AllOptions const* opts) const { - if (!opts) opts = &StaticData::Instance().options(); + if (!opts) opts = StaticData::Instance().options().get(); bool markUnk = opts->unk.mark; util::StringStream strme; for (size_t pos = 0 ; pos < GetSize() ; pos++) { diff --git a/moses/ReorderingConstraint.cpp b/moses/ReorderingConstraint.cpp index 7e3831efa..82899260e 100644 --- a/moses/ReorderingConstraint.cpp +++ b/moses/ReorderingConstraint.cpp @@ -187,7 +187,9 @@ bool ReorderingConstraint::Check( const Bitmap &bitmap, size_t startPos, size_t // check, if we are setting us up for a dead end due to distortion limits - size_t distortionLimit = (size_t)StaticData::Instance().GetMaxDistortion(); + + // size_t distortionLimit = (size_t)StaticData::Instance().GetMaxDistortion(); + size_t distortionLimit = m_max_distortion; if (startPos != firstGapPos && endZone-firstGapPos >= distortionLimit) { VERBOSE(3," dead end due to distortion limit" << std::endl); return false; diff --git a/moses/ReorderingConstraint.h b/moses/ReorderingConstraint.h index 575e64789..ea7458a33 100644 --- a/moses/ReorderingConstraint.h +++ b/moses/ReorderingConstraint.h @@ -53,11 +53,16 @@ protected: size_t *m_localWall; /**< flag for each word if it is a local wall */ std::vector< std::vector< size_t > > m_zone; /** zones that limit reordering */ bool m_active; /**< flag indicating, if there are any active constraints */ - + int m_max_distortion; public: //! create ReorderingConstraint of length size and initialise to zero - ReorderingConstraint() :m_wall(NULL),m_localWall(NULL),m_active(false) {} + ReorderingConstraint(int max_distortion) + : m_wall(NULL) + , m_localWall(NULL) + , m_active(false) + , m_max_distortion(max_distortion) + {} //! destructer ~ReorderingConstraint() { diff --git a/moses/RuleCube.cpp b/moses/RuleCube.cpp index c085ce6d8..3808cf2cd 100644 --- a/moses/RuleCube.cpp +++ b/moses/RuleCube.cpp @@ -43,7 +43,7 @@ RuleCube::RuleCube(const ChartTranslationOptions &transOpt, { RuleCubeItem *item = new RuleCubeItem(transOpt, allChartCells); m_covered.insert(item); - if (StaticData::Instance().options().cube.lazy_scoring) { + if (StaticData::Instance().options()->cube.lazy_scoring) { item->EstimateScore(); } else { item->CreateHypothesis(transOpt, manager); @@ -91,7 +91,7 @@ void RuleCube::CreateNeighbor(const RuleCubeItem &item, int dimensionIndex, if (!result.second) { delete newItem; // already seen it } else { - if (StaticData::Instance().options().cube.lazy_scoring) { + if (StaticData::Instance().options()->cube.lazy_scoring) { newItem->EstimateScore(); } else { newItem->CreateHypothesis(m_transOpt, manager); diff --git a/moses/RuleCubeQueue.cpp b/moses/RuleCubeQueue.cpp index e4a13c528..1942a29f7 100644 --- a/moses/RuleCubeQueue.cpp +++ b/moses/RuleCubeQueue.cpp @@ -50,7 +50,7 @@ ChartHypothesis *RuleCubeQueue::Pop() // pop the most promising item from the cube and get the corresponding // hypothesis RuleCubeItem *item = cube->Pop(m_manager); - if (StaticData::Instance().options().cube.lazy_scoring) { + if (StaticData::Instance().options()->cube.lazy_scoring) { item->CreateHypothesis(cube->GetTranslationOption(), m_manager); } ChartHypothesis *hypo = item->ReleaseHypothesis(); diff --git a/moses/Sentence.cpp b/moses/Sentence.cpp index f04cd7778..4faeb3889 100644 --- a/moses/Sentence.cpp +++ b/moses/Sentence.cpp @@ -43,9 +43,8 @@ namespace Moses Sentence:: Sentence(AllOptions::ptr const& opts) : Phrase(0) , InputType(opts) { - const StaticData& SD = StaticData::Instance(); - if (SD.IsSyntax()) - m_defaultLabelSet.insert(SD.GetInputDefaultNonTerminal()); + if (is_syntax(opts->search.algo)) + m_defaultLabelSet.insert(opts->syntax.input_default_non_terminal); } Sentence:: @@ -146,65 +145,59 @@ aux_interpret_dlt(string& line) // whatever DLT means ... --- UG void Sentence:: -aux_interpret_xml(AllOptions const& opts, std::string& line, std::vector & xmlWalls, +aux_interpret_xml(std::string& line, std::vector & xmlWalls, std::vector >& placeholders) { // parse XML markup in translation line - - const StaticData &SD = StaticData::Instance(); - using namespace std; - if (opts.input.xml_policy != XmlPassThrough) { - int offset = SD.IsSyntax() ? 1 : 0; - bool OK = ProcessAndStripXMLTags(opts, line, m_xmlOptions, + if (m_options->input.xml_policy != XmlPassThrough) { + bool OK = ProcessAndStripXMLTags(*m_options, line, + m_xmlOptions, m_reorderingConstraint, - xmlWalls, placeholders, offset, - SD.GetXmlBrackets().first, - SD.GetXmlBrackets().second); - UTIL_THROW_IF2(!OK, "Unable to parse XML in line: " << line); + xmlWalls, placeholders); + UTIL_THROW_IF2(!OK, "Unable to parse XML in line: " << line); } } void Sentence:: -init(AllOptions::ptr const& opts, string line, std::vector const& factorOrder) +init(string line) { using namespace std; - const StaticData &SD = StaticData::Instance(); m_frontSpanCoveredLength = 0; m_sourceCompleted.resize(0); - if (SD.ContinuePartialTranslation()) + if (m_options->input.continue_partial_translation) aux_init_partial_translation(line); - + line = Trim(line); aux_interpret_sgml_markup(line); // for "" - if (SD.options().output.PrintPassThrough || - SD.options().nbest.include_passthrough) { + if (m_options->output.PrintPassThrough ||m_options->nbest.include_passthrough) { string pthru = PassthroughSGML(line,"passthrough"); this->SetPassthroughInformation(pthru); } vector xmlWalls; vector >placeholders; - aux_interpret_xml(*opts, line, xmlWalls, placeholders); + aux_interpret_xml(line, xmlWalls, placeholders); - Phrase::CreateFromString(Input, factorOrder, line, NULL); + Phrase::CreateFromString(Input, m_options->input.factor_order, line, NULL); ProcessPlaceholders(placeholders); - if (SD.IsSyntax()) InitStartEndWord(); + if (is_syntax(m_options->search.algo)) + InitStartEndWord(); // now that we have final word positions in phrase (from // CreateFromString), we can make input phrase objects to go with // our XmlOptions and create TranslationOptions // only fill the vector if we are parsing XML - if (opts->input.xml_policy != XmlPassThrough) { + if (m_options->input.xml_policy != XmlPassThrough) { m_xmlCoverageMap.assign(GetSize(), false); BOOST_FOREACH(XmlOption const* o, m_xmlOptions) { Range const& r = o->range; @@ -217,7 +210,7 @@ init(AllOptions::ptr const& opts, string line, std::vector const& fa m_reorderingConstraint.InitializeWalls(GetSize()); // set reordering walls, if "-monotone-at-punction" is set - if (SD.UseReorderingConstraint() && GetSize()) { + if (m_options->reordering.monotone_at_punct && GetSize()) { Range r(0, GetSize()-1); m_reorderingConstraint.SetMonotoneAtPunctuation(GetSubString(r)); } @@ -232,14 +225,12 @@ init(AllOptions::ptr const& opts, string line, std::vector const& fa int Sentence:: -Read(std::istream& in, - const std::vector& factorOrder, - AllOptions const& opts) +Read(std::istream& in) { std::string line; if (getline(in, line, '\n').eof()) return 0; - init(m_options, line, factorOrder); + init(line); return 1; } @@ -247,7 +238,7 @@ void Sentence:: ProcessPlaceholders(const std::vector< std::pair > &placeholders) { - FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor; + FactorType placeholderFactor = m_options->input.placeholder_factor; if (placeholderFactor == NOT_FOUND) { return; } @@ -325,7 +316,7 @@ void Sentence::GetXmlTranslationOptions(std::vector &list, std::vector Sentence:: -GetXmlChartTranslationOptions(AllOptions const& opts) const +GetXmlChartTranslationOptions() const { std::vector ret; @@ -333,7 +324,7 @@ GetXmlChartTranslationOptions(AllOptions const& opts) const // this code is a copy of the 1 in Sentence. //only fill the vector if we are parsing XML - if (opts.input.xml_policy != XmlPassThrough ) { + if (m_options->input.xml_policy != XmlPassThrough ) { //TODO: needed to handle exclusive //for (size_t i=0; i const& FOrder, string const& phraseString) } Sentence:: -Sentence(AllOptions::ptr const& opts, size_t const transId, - string stext, vector const* IFO) +Sentence(AllOptions::ptr const& opts, size_t const transId, string stext) : InputType(opts, transId) { - if (IFO) init(opts,stext, *IFO); - else init(opts, stext, opts->input.factor_order); + init(stext); } } diff --git a/moses/Sentence.h b/moses/Sentence.h index 147cf43a2..219307218 100644 --- a/moses/Sentence.h +++ b/moses/Sentence.h @@ -64,8 +64,8 @@ protected: public: Sentence(AllOptions::ptr const& opts); - Sentence(AllOptions::ptr const& opts, size_t const transId, std::string stext, - std::vector const* IFO = NULL); + Sentence(AllOptions::ptr const& opts, size_t const transId, std::string stext); + // std::vector const* IFO = NULL); // Sentence(size_t const transId, std::string const& stext); ~Sentence(); @@ -94,11 +94,11 @@ public: //! populates vector argument with XML force translation options for the specific range passed void GetXmlTranslationOptions(std::vector &list) const; void GetXmlTranslationOptions(std::vector &list, size_t startPos, size_t endPos) const; - std::vector GetXmlChartTranslationOptions(AllOptions const& opts) const; + std::vector GetXmlChartTranslationOptions() const; virtual int - Read(std::istream& in, const std::vector& factorOrder, - AllOptions const& opts); + Read(std::istream& in); + // , const std::vector& factorOrder, AllOptions const& opts); void Print(std::ostream& out) const; @@ -115,9 +115,7 @@ public: } - void - init(AllOptions::ptr const& opts, std::string line, - std::vector const& factorOrder); + void init(std::string line); std::vector > const& GetDltMeta() const { @@ -139,7 +137,7 @@ private: void aux_interpret_xml - (AllOptions const& opts, std::string& line, std::vector & xmlWalls, + (std::string& line, std::vector & xmlWalls, std::vector >& placeholders); void diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 8cc304f15..c433a1de5 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -61,16 +61,11 @@ bool g_mosesDebug = false; StaticData StaticData::s_instance; StaticData::StaticData() - : m_sourceStartPosMattersForRecombination(false) + : m_options(new AllOptions) , m_requireSortingAfterSourceContext(false) - // , m_isAlwaysCreateDirectTranslationOption(false) , m_currentWeightSetting("default") , m_treeStructure(NULL) { - m_xmlBrackets.first="<"; - m_xmlBrackets.second=">"; - - // memory pools Phrase::InitializeMemPool(); } @@ -123,34 +118,6 @@ StaticData } -void -StaticData -::ini_input_options() -{ - const PARAM_VEC *params; - - m_parameter->SetParameter(m_continuePartialTranslation, - "continue-partial-translation", false ); - - // specify XML tags opening and closing brackets for XML option - params = m_parameter->GetParam("xml-brackets"); - if (params && params->size()) { - std::vector brackets = Tokenize(params->at(0)); - if(brackets.size()!=2) { - cerr << "invalid xml-brackets value, must specify exactly 2 blank-delimited strings for XML tags opening and closing brackets" << endl; - exit(1); - } - m_xmlBrackets.first= brackets[0]; - m_xmlBrackets.second=brackets[1]; - VERBOSE(1,"XML tags opening and closing brackets for XML input are: " - << m_xmlBrackets.first << " and " << m_xmlBrackets.second << endl); - } - - m_parameter->SetParameter(m_defaultNonTermOnlyForEmptyRange, - "default-non-term-for-empty-range-only", false ); - -} - bool StaticData ::ini_output_options() @@ -161,8 +128,6 @@ StaticData m_parameter->SetParameter(m_verboseLevel, "verbose", (size_t) 1); - m_parameter->SetParameter(m_includeLHSInSearchGraph, - "include-lhs-in-search-graph", false ); m_parameter->SetParameter(m_outputUnknownsFile, "output-unknowns", ""); @@ -218,7 +183,9 @@ bool StaticData::LoadData(Parameter *parameter) const PARAM_VEC *params; - m_options.init(*parameter); + m_options->init(*parameter); + if (is_syntax(m_options->search.algo)) + m_options->syntax.LoadNonTerminals(*parameter, FactorCollection::Instance()); if (IsSyntax()) LoadChartDecodingParameters(); @@ -229,7 +196,6 @@ bool StaticData::LoadData(Parameter *parameter) m_parameter->SetParameter(m_factorDelimiter, "factor-delimiter", "|"); m_parameter->SetParameter(m_lmcache_cleanup_threshold, "clean-lm-cache", 1); - ini_input_options(); m_bookkeeping_options.init(*parameter); if (!ini_output_options()) return false; @@ -876,7 +842,7 @@ StaticData // FIXME Does this make sense for F2S? Perhaps it should be changed once // FIXME the pipeline uses RuleTable consistently. - SearchAlgorithm algo = m_options.search.algo; + SearchAlgorithm algo = m_options->search.algo; if (algo == SyntaxS2T || algo == SyntaxT2S || algo == SyntaxT2S_SCFG || algo == SyntaxF2S) { // Automatically override PhraseDictionary{Memory,Scope3}. This will diff --git a/moses/StaticData.h b/moses/StaticData.h index b3786f321..d648b53bc 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -72,7 +72,7 @@ private: static StaticData s_instance; protected: Parameter *m_parameter; - AllOptions m_options; + boost::shared_ptr m_options; mutable ScoreComponentCollection m_allWeights; @@ -95,31 +95,22 @@ protected: size_t m_latticeSamplesSize; std::string m_latticeSamplesFilePath; - // bool m_dropUnknown; //! false = treat unknown words as unknowns, and translate them as themselves; true = drop (ignore) them - // bool m_markUnknown; //! false = treat unknown words as unknowns, and translate them as themselves; true = mark and (ignore) them - // std::string m_unknownWordPrefix; - // std::string m_unknownWordSuffix; - bool m_wordDeletionEnabled; + // bool m_wordDeletionEnabled; - // bool m_disableDiscarding; bool m_printAllDerivations; bool m_printTranslationOptions; - bool m_sourceStartPosMattersForRecombination; + // bool m_sourceStartPosMattersForRecombination; bool m_requireSortingAfterSourceContext; mutable size_t m_verboseLevel; std::string m_factorDelimiter; //! by default, |, but it can be changed - // XmlInputType m_xmlInputType; //! method for handling sentence XML input std::pair m_xmlBrackets; //! strings to use as XML tags' opening and closing brackets. Default are "<" and ">" size_t m_lmcache_cleanup_threshold; //! number of translations after which LM claenup is performed (0=never, N=after N translations; default is 1) - // bool m_isAlwaysCreateDirectTranslationOption; - //! constructor. only the 1 static variable can be created - bool m_includeLHSInSearchGraph; //! include LHS of rules in search graph std::string m_outputUnknownsFile; //! output unknowns in this file @@ -144,7 +135,6 @@ protected: std::map< std::string, std::set< std::string > > m_weightSettingIgnoreFF; // feature function std::map< std::string, std::set< size_t > > m_weightSettingIgnoreDP; // decoding path - // FactorType m_placeHolderFactor; bool m_useLegacyPT; bool m_defaultNonTermOnlyForEmptyRange; S2TParsingAlgorithm m_s2tParsingAlgorithm; @@ -174,7 +164,6 @@ protected: const StatefulFeatureFunction* m_treeStructure; - void ini_input_options(); void ini_oov_options(); bool ini_output_options(); bool ini_performance_options(); @@ -182,9 +171,6 @@ protected: void initialize_features(); public: - // bool IsAlwaysCreateDirectTranslationOption() const { - // return m_isAlwaysCreateDirectTranslationOption; - // } //! destructor ~StaticData(); @@ -219,51 +205,35 @@ public: return *m_parameter; } - AllOptions const& + AllOptions::ptr const options() const { return m_options; } - AllOptions& - options() { - return m_options; - } + // AllOptions& + // options() { + // return m_options; + // } - inline bool - GetSourceStartPosMattersForRecombination() const { - return m_sourceStartPosMattersForRecombination; - } - - bool - IsWordDeletionEnabled() const { - // return m_wordDeletionEnabled; - return m_options.unk.word_deletion_enabled; - } - - int - GetMaxDistortion() const { - return m_options.reordering.max_distortion; - } - - bool - UseReorderingConstraint() const { - return m_reorderingConstraint; - } + // inline bool + // GetSourceStartPosMattersForRecombination() const { + // return m_sourceStartPosMattersForRecombination; + // } bool UseEarlyDiscarding() const { - return m_options.search.early_discarding_threshold + return m_options->search.early_discarding_threshold != -std::numeric_limits::infinity(); } bool UseEarlyDistortionCost() const { - return m_options.reordering.use_early_distortion_cost; + return m_options->reordering.use_early_distortion_cost; } float GetTranslationOptionThreshold() const { - return m_options.search.trans_opt_threshold; + return m_options->search.trans_opt_threshold; } size_t @@ -288,7 +258,7 @@ public: bool IsSyntax(SearchAlgorithm algo = DefaultSearchAlgorithm) const { if (algo == DefaultSearchAlgorithm) - algo = m_options.search.algo; + algo = m_options->search.algo; return (algo == CYKPlus || algo == ChartIncremental || algo == SyntaxS2T || algo == SyntaxT2S || @@ -333,37 +303,14 @@ public: return m_outputUnknownsFile; } - bool GetIncludeLHSInSearchGraph() const { - return m_includeLHSInSearchGraph; - } - - std::pair GetXmlBrackets() const { - return m_xmlBrackets; - } - - // bool PrintTranslationOptions() const { - // return m_printTranslationOptions; - // } - - // bool PrintAllDerivations() const { - // return m_printAllDerivations; + // bool GetIncludeLHSInSearchGraph() const { + // return m_includeLHSInSearchGraph; // } const UnknownLHSList &GetUnknownLHS() const { return m_unknownLHS; } - const Word &GetInputDefaultNonTerminal() const { - return m_inputDefaultNonTerminal; - } - const Word &GetOutputDefaultNonTerminal() const { - return m_outputDefaultNonTerminal; - } - - SourceLabelOverlap GetSourceLabelOverlap() const { - return m_sourceLabelOverlap; - } - size_t GetRuleLimit() const { return m_ruleLimit; } @@ -473,7 +420,6 @@ public: } //sentence (and thread) specific initialisationn and cleanup - // void InitializeForInput(const InputType& source, ttaskptr const& ttask) const; void InitializeForInput(ttasksptr const& ttask) const; void CleanUpAfterSentenceProcessing(ttasksptr const& ttask) const; @@ -525,10 +471,6 @@ public: return m_defaultNonTermOnlyForEmptyRange; } - // S2TParsingAlgorithm GetS2TParsingAlgorithm() const { - // return m_s2tParsingAlgorithm; - // } - bool RequireSortingAfterSourceContext() const { return m_requireSortingAfterSourceContext; } diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp index c8d867650..930138750 100644 --- a/moses/Syntax/F2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/F2S/GlueRuleSynthesizer.cpp @@ -3,9 +3,8 @@ #include #include "moses/FF/UnknownWordPenaltyProducer.h" -#include "moses/StaticData.h" #include "util/string_stream.hh" - +#include "moses/parameters/AllOptions.h" namespace Moses { namespace Syntax @@ -14,13 +13,13 @@ namespace F2S { GlueRuleSynthesizer:: -GlueRuleSynthesizer(HyperTree &trie, const std::vector &iFactors) - : m_hyperTree(trie) +GlueRuleSynthesizer(Moses::AllOptions const& opts, HyperTree &trie) + : m_input_default_nonterminal(opts.syntax.input_default_non_terminal) + , m_output_default_nonterminal(opts.syntax.output_default_non_terminal) + , m_hyperTree(trie) { - // const std::vector &inputFactorOrder = - // StaticData::Instance().GetInputFactorOrder(); Word *lhs = NULL; - m_dummySourcePhrase.CreateFromString(Input, iFactors, "hello", &lhs); + m_dummySourcePhrase.CreateFromString(Input, opts.input.factor_order, "hello", &lhs); delete lhs; } @@ -47,11 +46,10 @@ void GlueRuleSynthesizer::SynthesizeHyperPath(const Forest::Hyperedge &e, } } -TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( - const Forest::Hyperedge &e) +TargetPhrase* +GlueRuleSynthesizer:: +SynthesizeTargetPhrase(const Forest::Hyperedge &e) { - const StaticData &staticData = StaticData::Instance(); - const UnknownWordPenaltyProducer &unknownWordPenaltyProducer = UnknownWordPenaltyProducer::Instance(); @@ -61,7 +59,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( for (std::size_t i = 0; i < e.tail.size(); ++i) { const Word &symbol = e.tail[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { - targetPhrase->AddWord(staticData.GetOutputDefaultNonTerminal()); + targetPhrase->AddWord(m_output_default_nonterminal); } else { // TODO Check this Word &targetWord = targetPhrase->AddWord(); @@ -75,7 +73,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( float score = LOWEST_SCORE; targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, score); targetPhrase->EvaluateInIsolation(m_dummySourcePhrase); - Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); + Word *targetLhs = new Word(m_output_default_nonterminal); targetPhrase->SetTargetLHS(targetLhs); targetPhrase->SetAlignmentInfo(alignmentSS.str()); diff --git a/moses/Syntax/F2S/GlueRuleSynthesizer.h b/moses/Syntax/F2S/GlueRuleSynthesizer.h index c66fb0ff8..b4128c5d7 100644 --- a/moses/Syntax/F2S/GlueRuleSynthesizer.h +++ b/moses/Syntax/F2S/GlueRuleSynthesizer.h @@ -9,6 +9,7 @@ namespace Moses { + class AllOptions; namespace Syntax { namespace F2S @@ -16,9 +17,11 @@ namespace F2S class GlueRuleSynthesizer : public HyperTreeCreator { + Word m_input_default_nonterminal; + Word m_output_default_nonterminal; public: - GlueRuleSynthesizer(HyperTree &, std::vector const& iFactors); - + GlueRuleSynthesizer(Moses::AllOptions const& opts, HyperTree &); + // Synthesize the minimal, monotone rule that can be applied to the given // hyperedge and add it to the rule trie. void SynthesizeRule(const Forest::Hyperedge &); diff --git a/moses/Syntax/F2S/Manager-inl.h b/moses/Syntax/F2S/Manager-inl.h index 77d4e0d58..29b1f2ba9 100644 --- a/moses/Syntax/F2S/Manager-inl.h +++ b/moses/Syntax/F2S/Manager-inl.h @@ -60,9 +60,9 @@ void Manager::Decode() const StaticData &staticData = StaticData::Instance(); // Get various pruning-related constants. - const std::size_t popLimit = staticData.options().cube.pop_limit; + const std::size_t popLimit = staticData.options()->cube.pop_limit; const std::size_t ruleLimit = staticData.GetRuleLimit(); - const std::size_t stackLimit = staticData.options().search.stack_size; + const std::size_t stackLimit = staticData.options()->search.stack_size; // Initialize the stacks. InitializeStacks(); @@ -74,8 +74,7 @@ void Manager::Decode() RuleMatcherCallback callback(m_stackMap, ruleLimit); // Create a glue rule synthesizer. - GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie, - options()->input.factor_order); + GlueRuleSynthesizer glueRuleSynthesizer(*options(), *m_glueRuleTrie); // Sort the input forest's vertices into bottom-up topological order. std::vector sortedVertices; @@ -256,7 +255,7 @@ void Manager::ExtractKBest( // with 0 being 'unlimited.' This actually sets a large-ish limit in case // too many translations are identical. const StaticData &staticData = StaticData::Instance(); - const std::size_t nBestFactor = staticData.options().nbest.factor; + const std::size_t nBestFactor = staticData.options()->nbest.factor; std::size_t numDerivations = (nBestFactor == 0) ? k*1000 : k*nBestFactor; // Extract the derivations. diff --git a/moses/Syntax/KBestExtractor.cpp b/moses/Syntax/KBestExtractor.cpp index 741d8ce82..21d15cd78 100644 --- a/moses/Syntax/KBestExtractor.cpp +++ b/moses/Syntax/KBestExtractor.cpp @@ -75,7 +75,7 @@ void KBestExtractor::Extract( // Generate the target-side yield of the derivation d. Phrase KBestExtractor::GetOutputPhrase(const Derivation &d) { - FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor; + FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor; Phrase ret(ARRAY_SIZE_INCR); diff --git a/moses/Syntax/RuleTableFF.cpp b/moses/Syntax/RuleTableFF.cpp index a44a95f5e..beee34a41 100644 --- a/moses/Syntax/RuleTableFF.cpp +++ b/moses/Syntax/RuleTableFF.cpp @@ -24,34 +24,35 @@ RuleTableFF::RuleTableFF(const std::string &line) s_instances.push_back(this); } -void RuleTableFF::Load(Moses::AllOptions const& opts) +void RuleTableFF::Load(Moses::AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); - if (opts.search.algo == SyntaxF2S || opts.search.algo == SyntaxT2S) { + if (opts->search.algo == SyntaxF2S || opts->search.algo == SyntaxT2S) { F2S::HyperTree *trie = new F2S::HyperTree(this); F2S::HyperTreeLoader loader; - loader.Load(opts, m_input, m_output, m_filePath, *this, *trie, m_sourceTerminalSet); + loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie, m_sourceTerminalSet); m_table = trie; - } else if (opts.search.algo == SyntaxS2T) { - S2TParsingAlgorithm algorithm = opts.syntax.s2t_parsing_algo; // staticData.GetS2TParsingAlgorithm(); + } else if (opts->search.algo == SyntaxS2T) { + S2TParsingAlgorithm algorithm = opts->syntax.s2t_parsing_algo; // staticData.GetS2TParsingAlgorithm(); if (algorithm == RecursiveCYKPlus) { S2T::RuleTrieCYKPlus *trie = new S2T::RuleTrieCYKPlus(this); S2T::RuleTrieLoader loader; - loader.Load(opts,m_input, m_output, m_filePath, *this, *trie); + loader.Load(*opts,m_input, m_output, m_filePath, *this, *trie); m_table = trie; } else if (algorithm == Scope3) { S2T::RuleTrieScope3 *trie = new S2T::RuleTrieScope3(this); S2T::RuleTrieLoader loader; - loader.Load(opts, m_input, m_output, m_filePath, *this, *trie); + loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie); m_table = trie; } else { UTIL_THROW2("ERROR: unhandled S2T parsing algorithm"); } - } else if (opts.search.algo == SyntaxT2S_SCFG) { + } else if (opts->search.algo == SyntaxT2S_SCFG) { T2S::RuleTrie *trie = new T2S::RuleTrie(this); T2S::RuleTrieLoader loader; - loader.Load(opts, m_input, m_output, m_filePath, *this, *trie); + loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie); m_table = trie; } else { UTIL_THROW2( diff --git a/moses/Syntax/RuleTableFF.h b/moses/Syntax/RuleTableFF.h index d1f87b2f0..9f394373a 100644 --- a/moses/Syntax/RuleTableFF.h +++ b/moses/Syntax/RuleTableFF.h @@ -27,7 +27,7 @@ public: // FIXME Delete m_table? ~RuleTableFF() {} - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); const RuleTable *GetTable() const { return m_table; diff --git a/moses/Syntax/S2T/Manager-inl.h b/moses/Syntax/S2T/Manager-inl.h index afb1f04c6..6bfc4a61c 100644 --- a/moses/Syntax/S2T/Manager-inl.h +++ b/moses/Syntax/S2T/Manager-inl.h @@ -163,9 +163,9 @@ void Manager::Decode() const StaticData &staticData = StaticData::Instance(); // Get various pruning-related constants. - const std::size_t popLimit = staticData.options().cube.pop_limit; + const std::size_t popLimit = staticData.options()->cube.pop_limit; const std::size_t ruleLimit = staticData.GetRuleLimit(); - const std::size_t stackLimit = staticData.options().search.stack_size; + const std::size_t stackLimit = staticData.options()->search.stack_size; // Initialise the PChart and SChart. InitializeCharts(); @@ -303,7 +303,7 @@ void Manager::ExtractKBest( // with 0 being 'unlimited.' This actually sets a large-ish limit in case // too many translations are identical. const StaticData &staticData = StaticData::Instance(); - const std::size_t nBestFactor = staticData.options().nbest.factor; + const std::size_t nBestFactor = staticData.options()->nbest.factor; std::size_t numDerivations = (nBestFactor == 0) ? k*1000 : k*nBestFactor; // Extract the derivations. diff --git a/moses/Syntax/S2T/OovHandler-inl.h b/moses/Syntax/S2T/OovHandler-inl.h index 773cc7a91..5b67080ec 100644 --- a/moses/Syntax/S2T/OovHandler-inl.h +++ b/moses/Syntax/S2T/OovHandler-inl.h @@ -57,7 +57,7 @@ OovHandler::SynthesizeTargetLhs(const std::string &lhsStr) { Word *targetLhs = new Word(true); targetLhs->CreateFromString(Output, - StaticData::Instance().options().output.factor_order, + StaticData::Instance().options()->output.factor_order, lhsStr, true); UTIL_THROW_IF2(targetLhs->GetFactor(0) == NULL, "Null factor for target LHS"); return targetLhs; @@ -83,7 +83,7 @@ TargetPhrase *OovHandler::SynthesizeTargetPhrase( targetPhrase->EvaluateInIsolation(srcPhrase); targetPhrase->SetTargetLHS(&targetLhs); targetPhrase->SetAlignmentInfo("0-0"); - if (!SD.options().output.detailed_tree_transrep_filepath.empty() || + if (!SD.options()->output.detailed_tree_transrep_filepath.empty() || SD.GetTreeStructure() != NULL) { std::string value = "[ " + targetLhs[0]->GetString().as_string() + " " + oov[0]->GetString().as_string() + " ]"; @@ -96,7 +96,7 @@ TargetPhrase *OovHandler::SynthesizeTargetPhrase( template bool OovHandler::ShouldDrop(const Word &oov) { - if (!StaticData::Instance().options().unk.drop) { + if (!StaticData::Instance().options()->unk.drop) { return false; } const Factor *f = oov[0]; // TODO hack. shouldn't know which factor is surface diff --git a/moses/Syntax/SHyperedge.cpp b/moses/Syntax/SHyperedge.cpp index 976b0f0e3..d554af231 100644 --- a/moses/Syntax/SHyperedge.cpp +++ b/moses/Syntax/SHyperedge.cpp @@ -11,7 +11,7 @@ namespace Syntax Phrase GetOneBestTargetYield(const SHyperedge &h) { - FactorType placeholderFactor = StaticData::Instance().options().input.placeholder_factor; + FactorType placeholderFactor = StaticData::Instance().options()->input.placeholder_factor; Phrase ret(ARRAY_SIZE_INCR); diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp index f50f84629..04b5da4e7 100644 --- a/moses/Syntax/T2S/GlueRuleSynthesizer.cpp +++ b/moses/Syntax/T2S/GlueRuleSynthesizer.cpp @@ -3,7 +3,7 @@ #include #include "moses/FF/UnknownWordPenaltyProducer.h" -#include "moses/StaticData.h" +#include namespace Moses { @@ -12,7 +12,9 @@ namespace Syntax namespace T2S { -void GlueRuleSynthesizer::SynthesizeRule(const InputTree::Node &node) +void +GlueRuleSynthesizer:: +SynthesizeRule(const InputTree::Node &node) { const Word &sourceLhs = node.pvertex.symbol; boost::scoped_ptr sourceRhs(SynthesizeSourcePhrase(node)); @@ -22,7 +24,9 @@ void GlueRuleSynthesizer::SynthesizeRule(const InputTree::Node &node) tpc->Add(tp); } -Phrase *GlueRuleSynthesizer::SynthesizeSourcePhrase(const InputTree::Node &node) +Phrase* +GlueRuleSynthesizer:: +SynthesizeSourcePhrase(const InputTree::Node &node) { Phrase *phrase = new Phrase(node.children.size()); for (std::vector::const_iterator p = node.children.begin(); @@ -37,11 +41,10 @@ Phrase *GlueRuleSynthesizer::SynthesizeSourcePhrase(const InputTree::Node &node) return phrase; } -TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( - const InputTree::Node &node, const Phrase &sourceRhs) +TargetPhrase* +GlueRuleSynthesizer:: +SynthesizeTargetPhrase(const InputTree::Node &node, const Phrase &sourceRhs) { - const StaticData &staticData = StaticData::Instance(); - const UnknownWordPenaltyProducer &unknownWordPenaltyProducer = UnknownWordPenaltyProducer::Instance(); @@ -51,7 +54,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( for (std::size_t i = 0; i < node.children.size(); ++i) { const Word &symbol = node.children[i]->pvertex.symbol; if (symbol.IsNonTerminal()) { - targetPhrase->AddWord(staticData.GetOutputDefaultNonTerminal()); + targetPhrase->AddWord(m_output_default_nonterminal); } else { // TODO Check this Word &targetWord = targetPhrase->AddWord(); @@ -65,7 +68,7 @@ TargetPhrase *GlueRuleSynthesizer::SynthesizeTargetPhrase( float score = LOWEST_SCORE; targetPhrase->GetScoreBreakdown().Assign(&unknownWordPenaltyProducer, score); targetPhrase->EvaluateInIsolation(sourceRhs); - Word *targetLhs = new Word(staticData.GetOutputDefaultNonTerminal()); + Word *targetLhs = new Word(m_output_default_nonterminal); targetPhrase->SetTargetLHS(targetLhs); targetPhrase->SetAlignmentInfo(alignmentSS.str()); diff --git a/moses/Syntax/T2S/GlueRuleSynthesizer.h b/moses/Syntax/T2S/GlueRuleSynthesizer.h index 3e51c08a4..3d9e4f8f9 100644 --- a/moses/Syntax/T2S/GlueRuleSynthesizer.h +++ b/moses/Syntax/T2S/GlueRuleSynthesizer.h @@ -16,9 +16,13 @@ namespace T2S class GlueRuleSynthesizer : public RuleTrieCreator { + Word m_output_default_nonterminal; public: - GlueRuleSynthesizer(RuleTrie &trie) : m_ruleTrie(trie) {} - + GlueRuleSynthesizer(RuleTrie &trie, Word dflt_nonterm) + : m_ruleTrie(trie) + , m_output_default_nonterminal(dflt_nonterm) + {} + // Synthesize the minimal, montone rule that can be applied to the given node // and add it to the rule trie. void SynthesizeRule(const InputTree::Node &); diff --git a/moses/Syntax/T2S/Manager-inl.h b/moses/Syntax/T2S/Manager-inl.h index 76aae54a8..ec97e76de 100644 --- a/moses/Syntax/T2S/Manager-inl.h +++ b/moses/Syntax/T2S/Manager-inl.h @@ -111,7 +111,8 @@ void Manager::Decode() F2S::RuleMatcherCallback callback(m_stackMap, ruleLimit); // Create a glue rule synthesizer. - GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie); + Word dflt_nonterm = options()->syntax.output_default_non_terminal; + GlueRuleSynthesizer glueRuleSynthesizer(*m_glueRuleTrie, dflt_nonterm); // Visit each node of the input tree in post-order. for (std::vector::const_iterator p = @@ -215,7 +216,7 @@ void Manager::ExtractKBest( // with 0 being 'unlimited.' This actually sets a large-ish limit in case // too many translations are identical. const StaticData &staticData = StaticData::Instance(); - const std::size_t nBestFactor = staticData.options().nbest.factor; + const std::size_t nBestFactor = staticData.options()->nbest.factor; std::size_t numDerivations = (nBestFactor == 0) ? k*1000 : k*nBestFactor; // Extract the derivations. diff --git a/moses/TabbedSentence.cpp b/moses/TabbedSentence.cpp index a94674cef..6339ad596 100644 --- a/moses/TabbedSentence.cpp +++ b/moses/TabbedSentence.cpp @@ -47,9 +47,7 @@ void TabbedSentence::CreateFromString(const std::vector &factorOrder int TabbedSentence:: -Read(std::istream& in, - std::vector const& factorOrder, - AllOptions const& opts) +Read(std::istream& in) { TabbedColumns allColumns; @@ -60,17 +58,14 @@ Read(std::istream& in, boost::split(allColumns, line, boost::is_any_of("\t")); if(allColumns.size() < 2) { - std::stringstream dummyStream; - dummyStream << line << std::endl; - return Sentence::Read(dummyStream, factorOrder, opts); + Sentence::init(line); } else { m_columns.resize(allColumns.size() - 1); std::copy(allColumns.begin() + 1, allColumns.end(), m_columns.begin()); - - std::stringstream dummyStream; - dummyStream << allColumns[0] << std::endl; - return Sentence::Read(dummyStream, factorOrder, opts); + Sentence::init(allColumns[0]); } + return 1; + } } diff --git a/moses/TabbedSentence.h b/moses/TabbedSentence.h index 020f3d6e4..973fa4563 100644 --- a/moses/TabbedSentence.h +++ b/moses/TabbedSentence.h @@ -68,8 +68,7 @@ public: , const std::string &tabbedString); virtual int - Read(std::istream& in,const std::vector& factorOrder, - AllOptions const& opts); + Read(std::istream& in); const TabbedColumns& GetColumns() const { return m_columns; diff --git a/moses/TargetPhrase.cpp b/moses/TargetPhrase.cpp index 58fada5e5..7cd3afc3b 100644 --- a/moses/TargetPhrase.cpp +++ b/moses/TargetPhrase.cpp @@ -52,7 +52,7 @@ TargetPhrase::TargetPhrase( std::string out_string, const PhraseDictionary *pt) //ACAT const StaticData &staticData = StaticData::Instance(); // XXX should this really be InputFactorOrder??? - CreateFromString(Output, staticData.options().input.factor_order, out_string, + CreateFromString(Output, staticData.options()->input.factor_order, out_string, // staticData.GetFactorDelimiter(), // eliminated [UG] NULL); } diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp index e640ea6d3..04f8db219 100644 --- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp +++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp @@ -51,6 +51,7 @@ ChartRuleLookupManagerOnDisk::ChartRuleLookupManagerOnDisk( size_t sourceSize = parser.GetSize(); m_expandableDottedRuleListVec.resize(sourceSize); + m_input_default_nonterminal = parser.options()->syntax.input_default_non_terminal; for (size_t ind = 0; ind < m_expandableDottedRuleListVec.size(); ++ind) { DottedRuleOnDisk *initDottedRule = new DottedRuleOnDisk(m_dbWrapper.GetRootSourceNode()); @@ -81,7 +82,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( ChartParserCallback &outColl) { const StaticData &staticData = StaticData::Instance(); - const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal(); + // const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal(); const Range &range = inputPath.GetWordsRange(); size_t relEndPos = range.GetEndPos() - range.GetStartPos(); @@ -178,7 +179,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( if (m_dictionary.m_maxSpanDefault != NOT_FOUND) { // for Hieu's source syntax - bool isSourceSyntaxNonTerm = sourceLHS != defaultSourceNonTerm; + bool isSourceSyntaxNonTerm = sourceLHS != m_input_default_nonterminal; // defaultSourceNonTerm; size_t nonTermNumWordsCovered = endPos - startPos + 1; doSearch = isSourceSyntaxNonTerm ? diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.h b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.h index dee9cc202..5402d5a54 100644 --- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.h +++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerOnDisk.h @@ -57,6 +57,7 @@ private: std::vector m_expandableDottedRuleListVec; std::map m_cache; std::list m_sourcePhraseNode; + Word m_input_default_nonterminal; }; } // namespace Moses diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index 80bd2bcf5..e30f5760f 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -57,8 +57,9 @@ PhraseDictionaryCompact::PhraseDictionaryCompact(const std::string &line) ReadParameters(); } -void PhraseDictionaryCompact::Load(AllOptions const& opts) +void PhraseDictionaryCompact::Load(AllOptions::ptr const& opts) { + m_options = opts; const StaticData &staticData = StaticData::Instance(); SetFeaturesToApply(); diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h index e6918cda5..ec11a1a4a 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.h @@ -67,7 +67,7 @@ public: ~PhraseDictionaryCompact(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); TargetPhraseCollection::shared_ptr GetTargetPhraseCollectionNonCacheLEGACY(const Phrase &source) const; TargetPhraseVectorPtr GetTargetPhraseCollectionRaw(const Phrase &source) const; diff --git a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp index a442de10c..cf051ff36 100644 --- a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp +++ b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.cpp @@ -60,8 +60,9 @@ PhraseDictionaryDynamicCacheBased::~PhraseDictionaryDynamicCacheBased() Clear(); } -void PhraseDictionaryDynamicCacheBased::Load(AllOptions const& opts) +void PhraseDictionaryDynamicCacheBased::Load(AllOptions::ptr const& opts) { + m_options = opts; VERBOSE(2,"PhraseDictionaryDynamicCacheBased::Load()" << std::endl); SetFeaturesToApply(); @@ -336,7 +337,7 @@ void PhraseDictionaryDynamicCacheBased::ClearEntries(std::string sourcePhraseStr //target targetPhrase.Clear(); VERBOSE(3, "targetPhraseString:|" << targetPhraseString << "|" << std::endl); - targetPhrase.CreateFromString(Output, staticData.options().output.factor_order, + targetPhrase.CreateFromString(Output, staticData.options()->output.factor_order, targetPhraseString, /*factorDelimiter,*/ NULL); VERBOSE(2, "targetPhrase:|" << targetPhrase << "|" << std::endl); @@ -344,7 +345,7 @@ void PhraseDictionaryDynamicCacheBased::ClearEntries(std::string sourcePhraseStr //consistent across phrase table implementations sourcePhrase.Clear(); VERBOSE(3, "sourcePhraseString:|" << sourcePhraseString << "|" << std::endl); - sourcePhrase.CreateFromString(Input, staticData.options().input.factor_order, + sourcePhrase.CreateFromString(Input, staticData.options()->input.factor_order, sourcePhraseString, /*factorDelimiter,*/ NULL); VERBOSE(3, "sourcePhrase:|" << sourcePhrase << "|" << std::endl); ClearEntries(sourcePhrase, targetPhrase); @@ -435,7 +436,7 @@ void PhraseDictionaryDynamicCacheBased::ClearSource(std::vector ent sourcePhrase.Clear(); VERBOSE(3, "sourcePhraseString:|" << (*it) << "|" << std::endl); - sourcePhrase.CreateFromString(Input, staticData.options().input.factor_order, + sourcePhrase.CreateFromString(Input, staticData.options()->input.factor_order, *it, /*factorDelimiter,*/ NULL); VERBOSE(3, "sourcePhrase:|" << sourcePhrase << "|" << std::endl); @@ -529,7 +530,7 @@ void PhraseDictionaryDynamicCacheBased::Update(std::string sourcePhraseString, s //target targetPhrase.Clear(); VERBOSE(3, "targetPhraseString:|" << targetPhraseString << "|" << std::endl); - targetPhrase.CreateFromString(Output, staticData.options().output.factor_order, + targetPhrase.CreateFromString(Output, staticData.options()->output.factor_order, targetPhraseString, /*factorDelimiter,*/ NULL); VERBOSE(3, "targetPhrase:|" << targetPhrase << "|" << std::endl); @@ -537,7 +538,7 @@ void PhraseDictionaryDynamicCacheBased::Update(std::string sourcePhraseString, s //consistent across phrase table implementations sourcePhrase.Clear(); VERBOSE(3, "sourcePhraseString:|" << sourcePhraseString << "|" << std::endl); - sourcePhrase.CreateFromString(Input, staticData.options().input.factor_order, sourcePhraseString, /*factorDelimiter,*/ NULL); + sourcePhrase.CreateFromString(Input, staticData.options()->input.factor_order, sourcePhraseString, /*factorDelimiter,*/ NULL); VERBOSE(3, "sourcePhrase:|" << sourcePhrase << "|" << std::endl); if (!waString.empty()) VERBOSE(3, "waString:|" << waString << "|" << std::endl); diff --git a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h index 2cd9f173d..09527debc 100644 --- a/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h +++ b/moses/TranslationModel/PhraseDictionaryDynamicCacheBased.h @@ -108,7 +108,7 @@ public: return *s_instance; } - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void Load(const std::string files); TargetPhraseCollection::shared_ptr diff --git a/moses/TranslationModel/PhraseDictionaryGroup.cpp b/moses/TranslationModel/PhraseDictionaryGroup.cpp index fbf256257..125ddaa64 100644 --- a/moses/TranslationModel/PhraseDictionaryGroup.cpp +++ b/moses/TranslationModel/PhraseDictionaryGroup.cpp @@ -73,8 +73,9 @@ void PhraseDictionaryGroup::SetParameter(const string& key, const string& value) } } -void PhraseDictionaryGroup::Load(AllOptions const& opts) +void PhraseDictionaryGroup::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); m_pdFeature.push_back(const_cast(this)); size_t numScoreComponents = 0; diff --git a/moses/TranslationModel/PhraseDictionaryGroup.h b/moses/TranslationModel/PhraseDictionaryGroup.h index 5d7fc29d1..b4909fc72 100644 --- a/moses/TranslationModel/PhraseDictionaryGroup.h +++ b/moses/TranslationModel/PhraseDictionaryGroup.h @@ -63,7 +63,7 @@ class PhraseDictionaryGroup: public PhraseDictionary public: PhraseDictionaryGroup(const std::string& line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); TargetPhraseCollection::shared_ptr CreateTargetPhraseCollection(const ttasksptr& ttask, const Phrase& src) const; diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp index b3b2cb669..4100f9b07 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.cpp @@ -79,8 +79,9 @@ PhraseDictionaryMultiModel:: ~PhraseDictionaryMultiModel() { } -void PhraseDictionaryMultiModel::Load(AllOptions const& opts) +void PhraseDictionaryMultiModel::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); for(size_t i = 0; i < m_numModels; ++i) { diff --git a/moses/TranslationModel/PhraseDictionaryMultiModel.h b/moses/TranslationModel/PhraseDictionaryMultiModel.h index 3eebea259..4a516ef6e 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModel.h +++ b/moses/TranslationModel/PhraseDictionaryMultiModel.h @@ -70,7 +70,7 @@ public: PhraseDictionaryMultiModel(const std::string &line); PhraseDictionaryMultiModel(int type, const std::string &line); ~PhraseDictionaryMultiModel(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual void CollectSufficientStatistics diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index 55868fdae..dbc99cbbf 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -83,8 +83,9 @@ PhraseDictionaryMultiModelCounts::~PhraseDictionaryMultiModelCounts() } -void PhraseDictionaryMultiModelCounts::Load(AllOptions const& opts) +void PhraseDictionaryMultiModelCounts::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); for(size_t i = 0; i < m_numModels; ++i) { diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.h b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.h index 0a2bb2e14..65a09fa81 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.h +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.h @@ -79,7 +79,7 @@ class PhraseDictionaryMultiModelCounts: public PhraseDictionaryMultiModel public: PhraseDictionaryMultiModelCounts(const std::string &line); ~PhraseDictionaryMultiModelCounts(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); TargetPhraseCollection::shared_ptr CreateTargetPhraseCollectionCounts(const Phrase &src, std::vector &fs, std::map* allStats, std::vector > &multimodelweights) const; void CollectSufficientStats(const Phrase &src, std::vector &fs, std::map* allStats) const; float GetTargetCount(const Phrase& target, size_t modelIndex) const; diff --git a/moses/TranslationModel/PhraseDictionaryTransliteration.cpp b/moses/TranslationModel/PhraseDictionaryTransliteration.cpp index adbc9a552..3d1664822 100644 --- a/moses/TranslationModel/PhraseDictionaryTransliteration.cpp +++ b/moses/TranslationModel/PhraseDictionaryTransliteration.cpp @@ -22,8 +22,9 @@ PhraseDictionaryTransliteration::PhraseDictionaryTransliteration(const std::stri m_outputLang.empty(), "Must specify all arguments"); } -void PhraseDictionaryTransliteration::Load(AllOptions const& opts) +void PhraseDictionaryTransliteration::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); } diff --git a/moses/TranslationModel/PhraseDictionaryTransliteration.h b/moses/TranslationModel/PhraseDictionaryTransliteration.h index c1ee7b7ff..d4a5d0919 100644 --- a/moses/TranslationModel/PhraseDictionaryTransliteration.h +++ b/moses/TranslationModel/PhraseDictionaryTransliteration.h @@ -18,7 +18,7 @@ class PhraseDictionaryTransliteration : public PhraseDictionary public: PhraseDictionaryTransliteration(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); virtual void CleanUpAfterSentenceProcessing(const InputType& source); diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index f35ea34ab..c375a2fcf 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -37,8 +37,9 @@ PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor() { } -void PhraseDictionaryTreeAdaptor::Load(AllOptions const& opts) +void PhraseDictionaryTreeAdaptor::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); } diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h index 3934baa6a..f3b91a553 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h @@ -46,7 +46,7 @@ class PhraseDictionaryTreeAdaptor : public PhraseDictionary public: PhraseDictionaryTreeAdaptor(const std::string &line); virtual ~PhraseDictionaryTreeAdaptor(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); // enable/disable caching // you enable caching if you request the target candidates for a source phrase multiple times diff --git a/moses/TranslationModel/ProbingPT/ProbingPT.cpp b/moses/TranslationModel/ProbingPT/ProbingPT.cpp index d033aaf0b..aa7cc1efe 100644 --- a/moses/TranslationModel/ProbingPT/ProbingPT.cpp +++ b/moses/TranslationModel/ProbingPT/ProbingPT.cpp @@ -25,8 +25,9 @@ ProbingPT::~ProbingPT() delete m_engine; } -void ProbingPT::Load(AllOptions const& opts) +void ProbingPT::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); m_engine = new QueryEngine(m_filePath.c_str()); @@ -76,7 +77,7 @@ void ProbingPT::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQue InputPath &inputPath = **iter; const Phrase &sourcePhrase = inputPath.GetPhrase(); - if (sourcePhrase.GetSize() > StaticData::Instance().options().search.max_phrase_length) { + if (sourcePhrase.GetSize() > StaticData::Instance().options()->search.max_phrase_length) { continue; } diff --git a/moses/TranslationModel/ProbingPT/ProbingPT.h b/moses/TranslationModel/ProbingPT/ProbingPT.h index 09c1c4a60..4e7ab02c6 100644 --- a/moses/TranslationModel/ProbingPT/ProbingPT.h +++ b/moses/TranslationModel/ProbingPT/ProbingPT.h @@ -21,7 +21,7 @@ public: ProbingPT(const std::string &line); ~ProbingPT(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void InitializeForInput(ttasksptr const& ttask); diff --git a/moses/TranslationModel/RuleTable/LoaderStandard.cpp b/moses/TranslationModel/RuleTable/LoaderStandard.cpp index 78a05a7d4..c84286588 100644 --- a/moses/TranslationModel/RuleTable/LoaderStandard.cpp +++ b/moses/TranslationModel/RuleTable/LoaderStandard.cpp @@ -149,7 +149,7 @@ bool RuleTableLoaderStandard::Load(AllOptions const& opts, FormatType format { PrintUserTime(string("Start loading text phrase table. ") + (format==MosesFormat?"Moses":"Hiero") + " format"); - const StaticData &staticData = StaticData::Instance(); + // const StaticData &staticData = StaticData::Instance(); string lineOrig; size_t count = 0; @@ -190,7 +190,7 @@ bool RuleTableLoaderStandard::Load(AllOptions const& opts, FormatType format } bool isLHSEmpty = (sourcePhraseString.find_first_not_of(" \t", 0) == string::npos); - if (isLHSEmpty && !staticData.IsWordDeletionEnabled()) { + if (isLHSEmpty && !opts.unk.word_deletion_enabled) { TRACE_ERR( ruleTable.GetFilePath() << ":" << count << ": pt entry contains empty target, skipping\n"); continue; } diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.cpp index 66e95b384..cb322a830 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.cpp @@ -32,8 +32,9 @@ PhraseDictionaryALSuffixArray::PhraseDictionaryALSuffixArray(const std::string & ReadParameters(); } -void PhraseDictionaryALSuffixArray::Load(AllOptions const& opts) +void PhraseDictionaryALSuffixArray::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); } diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.h b/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.h index f66b031db..ae4abfeaf 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.h +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.h @@ -23,7 +23,7 @@ class PhraseDictionaryALSuffixArray : public PhraseDictionaryMemory { public: PhraseDictionaryALSuffixArray(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void InitializeForInput(ttasksptr const& ttask); void CleanUpAfterSentenceProcessing(const InputType& source); diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp index f754ead01..50dd4bb8a 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp @@ -93,8 +93,9 @@ PhraseDictionaryFuzzyMatch::~PhraseDictionaryFuzzyMatch() delete m_FuzzyMatchWrapper; } -void PhraseDictionaryFuzzyMatch::Load(AllOptions const& opts) +void PhraseDictionaryFuzzyMatch::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); m_FuzzyMatchWrapper = new tmmt::FuzzyMatchWrapper(m_config[0], m_config[1], m_config[2]); @@ -241,7 +242,7 @@ void PhraseDictionaryFuzzyMatch::InitializeForInput(ttasksptr const& ttask) , &alignString = tokens[3]; bool isLHSEmpty = (sourcePhraseString.find_first_not_of(" \t", 0) == string::npos); - if (isLHSEmpty && !staticData.IsWordDeletionEnabled()) { + if (isLHSEmpty && !ttask->options()->unk.word_deletion_enabled) { TRACE_ERR( ptFileName << ":" << count << ": pt entry contains empty target, skipping\n"); continue; } diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h index 47348d561..e5a5f0704 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.h @@ -44,7 +44,7 @@ class PhraseDictionaryFuzzyMatch : public PhraseDictionary public: PhraseDictionaryFuzzyMatch(const std::string &line); ~PhraseDictionaryFuzzyMatch(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); const PhraseDictionaryNodeMemory &GetRootNode(long translationId) const; diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index 740b4c985..adb3f36c1 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -47,8 +47,9 @@ PhraseDictionaryOnDisk::~PhraseDictionaryOnDisk() { } -void PhraseDictionaryOnDisk::Load(AllOptions const& opts) +void PhraseDictionaryOnDisk::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); } diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h index 5a06493f0..1bd357d05 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.h @@ -67,7 +67,7 @@ protected: public: PhraseDictionaryOnDisk(const std::string &line); ~PhraseDictionaryOnDisk(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); // PhraseDictionary impl virtual ChartRuleLookupManager *CreateRuleLookupManager( diff --git a/moses/TranslationModel/RuleTable/Trie.cpp b/moses/TranslationModel/RuleTable/Trie.cpp index e0f0d7da8..5f1bf99b4 100644 --- a/moses/TranslationModel/RuleTable/Trie.cpp +++ b/moses/TranslationModel/RuleTable/Trie.cpp @@ -34,8 +34,9 @@ RuleTableTrie::~RuleTableTrie() { } -void RuleTableTrie::Load(AllOptions const& opts) +void RuleTableTrie::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); std::auto_ptr loader = @@ -44,7 +45,7 @@ void RuleTableTrie::Load(AllOptions const& opts) throw runtime_error("Error: Loading " + m_filePath); } - bool ret = loader->Load(opts, m_input, m_output, m_filePath, m_tableLimit, *this); + bool ret = loader->Load(*opts, m_input, m_output, m_filePath, m_tableLimit, *this); if (!ret) { throw runtime_error("Error: Loading " + m_filePath); } diff --git a/moses/TranslationModel/RuleTable/Trie.h b/moses/TranslationModel/RuleTable/Trie.h index 8b7d19a8f..7a9e12e8d 100644 --- a/moses/TranslationModel/RuleTable/Trie.h +++ b/moses/TranslationModel/RuleTable/Trie.h @@ -46,7 +46,7 @@ public: virtual ~RuleTableTrie(); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); private: friend class RuleTableLoader; diff --git a/moses/TranslationModel/SkeletonPT.cpp b/moses/TranslationModel/SkeletonPT.cpp index d9d3cf93b..6b42212f9 100644 --- a/moses/TranslationModel/SkeletonPT.cpp +++ b/moses/TranslationModel/SkeletonPT.cpp @@ -12,8 +12,9 @@ SkeletonPT::SkeletonPT(const std::string &line) ReadParameters(); } -void SkeletonPT::Load(AllOptions const& opts) +void SkeletonPT::Load(AllOptions::ptr const& opts) { + m_options = opts; SetFeaturesToApply(); } diff --git a/moses/TranslationModel/SkeletonPT.h b/moses/TranslationModel/SkeletonPT.h index 01660b353..443f1cc8e 100644 --- a/moses/TranslationModel/SkeletonPT.h +++ b/moses/TranslationModel/SkeletonPT.h @@ -16,7 +16,7 @@ class SkeletonPT : public PhraseDictionary public: SkeletonPT(const std::string &line); - void Load(AllOptions const& opts); + void Load(AllOptions::ptr const& opts); void InitializeForInput(ttasksptr const& ttask); diff --git a/moses/TranslationModel/UG/mmsapt.cpp b/moses/TranslationModel/UG/mmsapt.cpp index bec1fd1e2..ed60771ae 100644 --- a/moses/TranslationModel/UG/mmsapt.cpp +++ b/moses/TranslationModel/UG/mmsapt.cpp @@ -417,7 +417,7 @@ namespace Moses void Mmsapt:: - Load(AllOptions const& opts) + Load(AllOptions::ptr const& opts) { Load(opts, true); } @@ -474,8 +474,9 @@ namespace Moses void Mmsapt:: - Load(AllOptions const& opts, bool with_checks) + Load(AllOptions::ptr const& opts, bool with_checks) { + m_options = opts; boost::unique_lock lock(m_lock); // load feature functions (i.e., load underlying data bases, if any) BOOST_FOREACH(SPTR& ff, m_active_ff_fix) ff->load(); diff --git a/moses/TranslationModel/UG/mmsapt.h b/moses/TranslationModel/UG/mmsapt.h index d6de6737c..4a8393c11 100644 --- a/moses/TranslationModel/UG/mmsapt.h +++ b/moses/TranslationModel/UG/mmsapt.h @@ -211,8 +211,8 @@ namespace Moses // Mmsapt(std::string const& description, std::string const& line); Mmsapt(std::string const& line); - void Load(AllOptions const& opts); - void Load(AllOptions const& opts, bool with_checks); + void Load(AllOptions::ptr const& opts); + void Load(AllOptions::ptr const& opts, bool with_checks); size_t SetTableLimit(size_t limit); // returns the prior table limit std::string const& GetName() const; diff --git a/moses/TranslationOptionCollectionConfusionNet.cpp b/moses/TranslationOptionCollectionConfusionNet.cpp index e108b72e2..2fac458ac 100644 --- a/moses/TranslationOptionCollectionConfusionNet.cpp +++ b/moses/TranslationOptionCollectionConfusionNet.cpp @@ -224,7 +224,7 @@ CreateTranslationOptionsForRangeLEGACY(const DecodeGraph &decodeGraph, { bool retval = true; size_t const max_phrase_length - = StaticData::Instance().options().search.max_phrase_length; + = StaticData::Instance().options()->search.max_phrase_length; XmlInputType intype = m_ttask.lock()->options()->input.xml_policy; if ((intype != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) { InputPathList &inputPathList = GetInputPathList(startPos, endPos); diff --git a/moses/TreeInput.cpp b/moses/TreeInput.cpp index 9593473d8..1c898ea51 100644 --- a/moses/TreeInput.cpp +++ b/moses/TreeInput.cpp @@ -240,25 +240,20 @@ ProcessAndStripXMLTags(AllOptions const& opts, string &line, //! populate this InputType with data from in stream int TreeInput:: -Read(std::istream& in, const std::vector& factorOrder, - AllOptions const& opts) +Read(std::istream& in) { - const StaticData &staticData = StaticData::Instance(); - string line; if (getline(in, line, '\n').eof()) return 0; - // remove extra spaces - //line = Trim(line); - + m_labelledSpans.clear(); - ProcessAndStripXMLTags(opts, line, m_labelledSpans, m_xmlOptions); + ProcessAndStripXMLTags(*m_options, line, m_labelledSpans, m_xmlOptions); // do words 1st - hack stringstream strme; strme << line << endl; - Sentence::Read(strme, factorOrder, opts); + Sentence::Read(strme); // size input chart size_t sourceSize = GetSize(); @@ -270,19 +265,21 @@ Read(std::istream& in, const std::vector& factorOrder, // do source labels vector::const_iterator iterLabel; - for (iterLabel = m_labelledSpans.begin(); iterLabel != m_labelledSpans.end(); ++iterLabel) { + for (iterLabel = m_labelledSpans.begin(); + iterLabel != m_labelledSpans.end(); ++iterLabel) { const XMLParseOutput &labelItem = *iterLabel; const Range &range = labelItem.m_range; const string &label = labelItem.m_label; - AddChartLabel(range.GetStartPos() + 1, range.GetEndPos() + 1, label, factorOrder); + AddChartLabel(range.GetStartPos() + 1, range.GetEndPos() + 1, label); } // default label + bool only4empty = m_options->syntax.default_non_term_only_for_empty_range; for (size_t startPos = 0; startPos < sourceSize; ++startPos) { for (size_t endPos = startPos; endPos < sourceSize; ++endPos) { NonTerminalSet &list = GetLabelSet(startPos, endPos); - if (list.size() == 0 || !staticData.GetDefaultNonTermOnlyForEmptyRange()) { - AddChartLabel(startPos, endPos, staticData.GetInputDefaultNonTerminal(), factorOrder); + if (list.size() == 0 || ! only4empty ) { + AddChartLabel(startPos, endPos, m_options->syntax.input_default_non_terminal); } } } @@ -303,13 +300,13 @@ TranslationOptionCollection* TreeInput::CreateTranslationOptionCollection() cons return NULL; } -void TreeInput::AddChartLabel(size_t startPos, size_t endPos, const Word &label - , const std::vector& /* factorOrder */) +void +TreeInput:: +AddChartLabel(size_t startPos, size_t endPos, const Word &label) { UTIL_THROW_IF2(!label.IsNonTerminal(), "Label must be a non-terminal"); - - SourceLabelOverlap overlapType = StaticData::Instance().GetSourceLabelOverlap(); + SourceLabelOverlap overlapType = m_options->syntax.source_label_overlap; NonTerminalSet &list = GetLabelSet(startPos, endPos); switch (overlapType) { case SourceLabelOverlapAdd: @@ -327,14 +324,17 @@ void TreeInput::AddChartLabel(size_t startPos, size_t endPos, const Word &label } } -void TreeInput::AddChartLabel(size_t startPos, size_t endPos, const string &label - , const std::vector& factorOrder) +void +TreeInput:: +AddChartLabel(size_t startPos, size_t endPos, const string &label) { + const std::vector& fOrder = m_options->input.factor_order; Word word(true); - const Factor *factor = FactorCollection::Instance().AddFactor(Input, factorOrder[0], label, true); // TODO - no factors + const Factor *factor + = FactorCollection::Instance().AddFactor(Input, fOrder[0], label, true); + // TODO - no factors word.SetFactor(0, factor); - - AddChartLabel(startPos, endPos, word, factorOrder); + AddChartLabel(startPos, endPos, word); } std::ostream& operator<<(std::ostream &out, const TreeInput &input) diff --git a/moses/TreeInput.h b/moses/TreeInput.h index 9e698c117..0d79516ab 100644 --- a/moses/TreeInput.h +++ b/moses/TreeInput.h @@ -35,10 +35,9 @@ protected: std::vector > m_sourceChart; std::vector m_labelledSpans; - void AddChartLabel(size_t startPos, size_t endPos, const std::string &label - ,const std::vector& factorOrder); - void AddChartLabel(size_t startPos, size_t endPos, const Word &label - ,const std::vector& factorOrder); + void AddChartLabel(size_t startPos, size_t endPos, const std::string &label); + void AddChartLabel(size_t startPos, size_t endPos, const Word &label); + NonTerminalSet &GetLabelSet(size_t startPos, size_t endPos) { return m_sourceChart[startPos][endPos - startPos]; } @@ -56,9 +55,7 @@ public: //! populate this InputType with data from in stream virtual int - Read(std::istream& in, - const std::vector& factorOrder, - AllOptions const& opts); + Read(std::istream& in); //! Output debugging info to stream out virtual void Print(std::ostream&) const; diff --git a/moses/WordLattice.cpp b/moses/WordLattice.cpp index c4d4808e3..01f8eac9f 100644 --- a/moses/WordLattice.cpp +++ b/moses/WordLattice.cpp @@ -52,18 +52,15 @@ void WordLattice::Print(std::ostream& out) const int WordLattice:: -InitializeFromPCNDataType -(const PCN::CN& cn, size_t const maxPhraseLength, - const std::vector& factorOrder, - const std::string& debug_line) +InitializeFromPCNDataType(const PCN::CN& cn, const std::string& debug_line) { - // const StaticData &staticData = StaticData::Instance(); + const std::vector& factorOrder = m_options->input.factor_order; + size_t const maxPhraseLength = m_options->search.max_phrase_length; + const InputFeature *inputFeature = InputFeature::InstancePtr(); size_t numInputScores = inputFeature->GetNumInputScores(); size_t numRealWordCount = inputFeature->GetNumRealWordsInInput(); - // size_t maxSizePhrase = StaticData::Instance().GetMaxPhraseLength(); - bool addRealWordCount = (numRealWordCount > 0); //when we have one more weight than params, we add a word count feature @@ -150,9 +147,7 @@ InitializeFromPCNDataType int WordLattice:: -Read(std::istream& in, - std::vector const& factorOrder, - AllOptions const& opts) +Read(std::istream& in) { Clear(); std::string line; @@ -163,8 +158,7 @@ Read(std::istream& in, } PCN::CN cn = PCN::parsePCN(line); - return InitializeFromPCNDataType(cn, opts.search.max_phrase_length, - factorOrder, line); + return InitializeFromPCNDataType(cn, line); } void WordLattice::GetAsEdgeMatrix(std::vector >& edges) const @@ -228,17 +222,10 @@ TranslationOptionCollection* WordLattice ::CreateTranslationOptionCollection(ttasksptr const& ttask) const { - // size_t maxNoTransOptPerCoverage = StaticData::Instance().GetMaxNoTransOptPerCoverage(); - // float translationOptionThreshold = StaticData::Instance().GetTranslationOptionThreshold(); - - size_t maxNoTransOptPerCoverage = ttask->options()->search.max_trans_opt_per_cov; - // StaticData::Instance().GetMaxNoTransOptPerCoverage(); + size_t maxNoTransOptPerCoverage = ttask->options()->search.max_trans_opt_per_cov; float translationOptionThreshold = ttask->options()->search.trans_opt_threshold; - // StaticData::Instance().GetTranslationOptionThreshold(); - TranslationOptionCollection *rv = NULL; - //rv = new TranslationOptionCollectionConfusionNet(*this, maxNoTransOptPerCoverage, translationOptionThreshold); if (StaticData::Instance().GetUseLegacyPT()) { rv = new TranslationOptionCollectionConfusionNet(ttask, *this, maxNoTransOptPerCoverage, translationOptionThreshold); diff --git a/moses/WordLattice.h b/moses/WordLattice.h index c764a4840..f36569e78 100644 --- a/moses/WordLattice.h +++ b/moses/WordLattice.h @@ -40,14 +40,11 @@ public: /** Given a lattice represented using the PCN::CN data type (topologically sorted agency list * representation), initialize the WordLattice object */ - int InitializeFromPCNDataType(const PCN::CN& cn, size_t const maxPhraseLength, - const std::vector& factorOrder, - const std::string& debug_line = ""); + int InitializeFromPCNDataType(const PCN::CN& cn, const std::string& debug_line = ""); + /** Read from PLF format (1 lattice per line) */ - int Read(std::istream& in, - std::vector const& factorOrder, - AllOptions const& opts); + int Read(std::istream& in); /** Convert internal representation into an edge matrix * @note edges[1][2] means there is an edge from 1 to 2 diff --git a/moses/XmlOption.cpp b/moses/XmlOption.cpp index 342b08172..da1339b95 100644 --- a/moses/XmlOption.cpp +++ b/moses/XmlOption.cpp @@ -159,16 +159,19 @@ vector TokenizeXml(const string& str, const std::string& lbrackStr, cons * \param rbrackStr xml tag's right bracket string, typically ">" */ bool -ProcessAndStripXMLTags(AllOptions const& opts, string &line, vector &res, +ProcessAndStripXMLTags(AllOptions const& opts, string &line, + vector &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls, - std::vector< std::pair > &placeholders, - int offset, const std::string& lbrackStr, - const std::string& rbrackStr) + std::vector< std::pair > &placeholders) { //parse XML markup in translation line - const StaticData &staticData = StaticData::Instance(); + const std::string& lbrackStr = opts.input.xml_brackets.first; + const std::string& rbrackStr = opts.input.xml_brackets.second; + int offset = is_syntax(opts.search.algo) ? 1 : 0; + + // const StaticData &staticData = StaticData::Instance(); // hack. What pt should XML trans opt be assigned to? PhraseDictionary *firstPt = NULL; @@ -177,7 +180,6 @@ ProcessAndStripXMLTags(AllOptions const& opts, string &line, vector &outputFactorOrder = opts.output.factor_order; - // const string &factorDelimiter = staticData.GetFactorDelimiter(); // loop through the tokens for (size_t xmlTokenPos = 0 ; xmlTokenPos < xmlTokens.size() ; xmlTokenPos++) { @@ -459,7 +460,7 @@ ProcessAndStripXMLTags(AllOptions const& opts, string &line, vector TokenizeXml(const std::string& str, const std::string& bool ProcessAndStripXMLTags(AllOptions const& opts, std::string &line, std::vector &res, - ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls, - std::vector< std::pair > &placeholders, - int offset, - const std::string& lbrackStr="<", const std::string& rbrackStr=">"); + ReorderingConstraint &reorderingConstraint, + std::vector< size_t > &walls, + std::vector< std::pair > &placeholders); + } diff --git a/moses/parameters/ReportingOptions.cpp b/moses/parameters/ReportingOptions.cpp index 2aac3a76c..f1cb89b06 100644 --- a/moses/parameters/ReportingOptions.cpp +++ b/moses/parameters/ReportingOptions.cpp @@ -20,6 +20,7 @@ namespace Moses { , ReportHypoScore(false) , PrintID(false) , PrintPassThrough(false) + , include_lhs_in_search_graph(false) , lattice_sample_size(0) { factor_order.assign(1,0); @@ -64,7 +65,9 @@ namespace Moses { #endif param.SetParameter(DontPruneSearchGraph, "unpruned-search-graph", false); - + param.SetParameter(include_lhs_in_search_graph, + "include-lhs-in-search-graph", false ); + // miscellaneous param.SetParameter(RecoverPath, "recover-input-path",false); diff --git a/moses/parameters/ReportingOptions.h b/moses/parameters/ReportingOptions.h index ee8c58f97..76f8fdae4 100644 --- a/moses/parameters/ReportingOptions.h +++ b/moses/parameters/ReportingOptions.h @@ -44,6 +44,8 @@ namespace Moses std::string detailed_transrep_filepath; std::string detailed_tree_transrep_filepath; std::string detailed_all_transrep_filepath; + bool include_lhs_in_search_graph; + std::string lattice_sample_filepath; size_t lattice_sample_size; diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index d5141aae1..174fe39e6 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -262,7 +262,7 @@ parse_request(std::map const& params) m_scope.reset(new Moses::ContextScope); } - boost::shared_ptr opts(new Moses::AllOptions(StaticData::Instance().options())); + boost::shared_ptr opts(new Moses::AllOptions(*StaticData::Instance().options())); opts->update(params); m_withGraphInfo = check(params, "sg"); @@ -327,7 +327,7 @@ run_chart_decoder() { Moses::TreeInput tinput(m_options); istringstream buf(m_source_string + "\n"); - tinput.Read(buf, options()->input.factor_order, *m_options); + tinput.Read(buf); Moses::ChartManager manager(this->self()); manager.Decode();