00001 // -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*- 00002 #include "AllOptions.h" 00003 00004 namespace Moses 00005 { 00006 AllOptions:: 00007 AllOptions() 00008 : mira(false) 00009 , use_legacy_pt(false) 00010 { } 00011 00012 AllOptions:: 00013 AllOptions(Parameter const& param) 00014 { 00015 init(param); 00016 } 00017 00018 bool 00019 AllOptions:: 00020 init(Parameter const& param) 00021 { 00022 if (!search.init(param)) return false; 00023 if (!cube.init(param)) return false; 00024 if (!nbest.init(param)) return false; 00025 if (!reordering.init(param)) return false; 00026 if (!context.init(param)) return false; 00027 if (!input.init(param)) return false; 00028 if (!mbr.init(param)) return false; 00029 if (!lmbr.init(param)) return false; 00030 if (!output.init(param)) return false; 00031 if (!unk.init(param)) return false; 00032 if (!syntax.init(param)) return false; 00033 00034 param.SetParameter(mira, "mira", false); 00035 00036 return sanity_check(); 00037 } 00038 00039 bool 00040 AllOptions:: 00041 sanity_check() 00042 { 00043 using namespace std; 00044 if (lmbr.enabled) 00045 { 00046 if (mbr.enabled) 00047 { 00048 cerr << "Error: Cannot use both n-best mbr and lattice mbr together" << endl; 00049 return false; 00050 } 00051 mbr.enabled = true; 00052 } 00053 if (search.consensus) 00054 { 00055 if (mbr.enabled) 00056 { 00057 cerr << "Error: Cannot use consensus decoding together with mbr" 00058 << endl; 00059 return false; 00060 } 00061 mbr.enabled = true; 00062 } 00063 00064 // RecoverPath should only be used with confusion net or word lattice input 00065 if (output.RecoverPath && input.input_type == SentenceInput) 00066 { 00067 TRACE_ERR("--recover-input-path should only be used with " 00068 <<"confusion net or word lattice input!\n"); 00069 output.RecoverPath = false; 00070 } 00071 00072 // set m_nbest_options.enabled = true if necessary: 00073 nbest.enabled = (nbest.enabled || mira || search.consensus 00074 || nbest.nbest_size > 0 00075 || mbr.enabled || lmbr.enabled 00076 || !output.SearchGraph.empty() 00077 || !output.SearchGraphExtended.empty() 00078 || !output.SearchGraphSLF.empty() 00079 || !output.SearchGraphHG.empty() 00080 || !output.SearchGraphPB.empty() 00081 || output.lattice_sample_size != 0); 00082 00083 return true; 00084 } 00085 00086 #ifdef HAVE_XMLRPC_C 00087 bool 00088 AllOptions:: 00089 update(std::map<std::string,xmlrpc_c::value>const& param) 00090 { 00091 if (!search.update(param)) return false; 00092 if (!cube.update(param)) return false; 00093 if (!nbest.update(param)) return false; 00094 if (!reordering.update(param)) return false; 00095 if (!context.update(param)) return false; 00096 if (!input.update(param)) return false; 00097 if (!mbr.update(param)) return false; 00098 if (!lmbr.update(param)) return false; 00099 if (!output.update(param)) return false; 00100 if (!unk.update(param)) return false; 00101 if (!syntax.update(param)) return false; 00102 return sanity_check(); 00103 } 00104 #else 00105 bool 00106 AllOptions:: 00107 update(std::map<std::string,xmlrpc_c::value>const& param) 00108 {} 00109 #endif 00110 00111 bool 00112 AllOptions:: 00113 NBestDistinct() const 00114 { 00115 return (nbest.only_distinct 00116 || mbr.enabled || lmbr.enabled 00117 || output.lattice_sample_size 00118 || !output.SearchGraph.empty() 00119 || !output.SearchGraphExtended.empty() 00120 || !output.SearchGraphSLF.empty() 00121 || !output.SearchGraphHG.empty()); 00122 } 00123 00124 00125 }