00001 #include "RuleTableFF.h"
00002 #include "moses/parameters/AllOptions.h"
00003 #include "moses/Syntax/F2S/HyperTree.h"
00004 #include "moses/Syntax/F2S/HyperTreeLoader.h"
00005 #include "moses/Syntax/S2T/RuleTrieCYKPlus.h"
00006 #include "moses/Syntax/S2T/RuleTrieLoader.h"
00007 #include "moses/Syntax/S2T/RuleTrieScope3.h"
00008 #include "moses/Syntax/T2S/RuleTrie.h"
00009 #include "moses/Syntax/T2S/RuleTrieLoader.h"
00010 namespace Moses
00011 {
00012 namespace Syntax
00013 {
00014
00015 std::vector<RuleTableFF*> RuleTableFF::s_instances;
00016
00017 RuleTableFF::RuleTableFF(const std::string &line)
00018 : PhraseDictionary(line, true)
00019 {
00020 ReadParameters();
00021
00022 m_maxCacheSize = 0;
00023
00024 s_instances.push_back(this);
00025 }
00026
00027 void RuleTableFF::Load(Moses::AllOptions::ptr const& opts)
00028 {
00029 m_options = opts;
00030 SetFeaturesToApply();
00031
00032 if (opts->search.algo == SyntaxF2S || opts->search.algo == SyntaxT2S) {
00033 F2S::HyperTree *trie = new F2S::HyperTree(this);
00034 F2S::HyperTreeLoader loader;
00035 loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie, m_sourceTerminalSet);
00036 m_table = trie;
00037 } else if (opts->search.algo == SyntaxS2T) {
00038 S2TParsingAlgorithm algorithm = opts->syntax.s2t_parsing_algo;
00039 if (algorithm == RecursiveCYKPlus) {
00040 S2T::RuleTrieCYKPlus *trie = new S2T::RuleTrieCYKPlus(this);
00041 S2T::RuleTrieLoader loader;
00042 loader.Load(*opts,m_input, m_output, m_filePath, *this, *trie);
00043 m_table = trie;
00044 } else if (algorithm == Scope3) {
00045 S2T::RuleTrieScope3 *trie = new S2T::RuleTrieScope3(this);
00046 S2T::RuleTrieLoader loader;
00047 loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie);
00048 m_table = trie;
00049 } else {
00050 UTIL_THROW2("ERROR: unhandled S2T parsing algorithm");
00051 }
00052 } else if (opts->search.algo == SyntaxT2S_SCFG) {
00053 T2S::RuleTrie *trie = new T2S::RuleTrie(this);
00054 T2S::RuleTrieLoader loader;
00055 loader.Load(*opts, m_input, m_output, m_filePath, *this, *trie);
00056 m_table = trie;
00057 } else {
00058 UTIL_THROW2(
00059 "ERROR: RuleTableFF currently only supports the S2T, T2S, T2S_SCFG, and F2S search algorithms");
00060 }
00061 }
00062
00063 }
00064 }