2015-08-06 02:51:02 +03:00
|
|
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
|
|
|
#include "AllOptions.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2015-12-09 20:59:14 +03:00
|
|
|
AllOptions::
|
|
|
|
AllOptions()
|
|
|
|
: mira(false)
|
|
|
|
, use_legacy_pt(false)
|
|
|
|
{ }
|
|
|
|
|
2015-08-06 02:51:02 +03:00
|
|
|
AllOptions::
|
|
|
|
AllOptions(Parameter const& param)
|
|
|
|
{
|
|
|
|
init(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AllOptions::
|
|
|
|
init(Parameter const& param)
|
|
|
|
{
|
|
|
|
if (!search.init(param)) return false;
|
|
|
|
if (!cube.init(param)) return false;
|
|
|
|
if (!nbest.init(param)) return false;
|
|
|
|
if (!reordering.init(param)) return false;
|
|
|
|
if (!context.init(param)) return false;
|
|
|
|
if (!input.init(param)) return false;
|
2015-08-07 00:52:34 +03:00
|
|
|
if (!mbr.init(param)) return false;
|
|
|
|
if (!lmbr.init(param)) return false;
|
2015-10-31 15:50:52 +03:00
|
|
|
if (!output.init(param)) return false;
|
2015-11-11 20:07:45 +03:00
|
|
|
if (!unk.init(param)) return false;
|
2015-12-08 02:34:57 +03:00
|
|
|
if (!syntax.init(param)) return false;
|
2015-08-07 00:52:34 +03:00
|
|
|
|
|
|
|
param.SetParameter(mira, "mira", false);
|
|
|
|
|
2015-08-06 02:51:02 +03:00
|
|
|
return sanity_check();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AllOptions::
|
|
|
|
sanity_check()
|
|
|
|
{
|
2015-08-07 00:52:34 +03:00
|
|
|
using namespace std;
|
|
|
|
if (lmbr.enabled)
|
|
|
|
{
|
|
|
|
if (mbr.enabled)
|
|
|
|
{
|
|
|
|
cerr << "Error: Cannot use both n-best mbr and lattice mbr together" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mbr.enabled = true;
|
|
|
|
}
|
|
|
|
if (search.consensus)
|
|
|
|
{
|
|
|
|
if (mbr.enabled)
|
|
|
|
{
|
2015-10-31 15:50:52 +03:00
|
|
|
cerr << "Error: Cannot use consensus decoding together with mbr"
|
|
|
|
<< endl;
|
2015-08-07 00:52:34 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mbr.enabled = true;
|
|
|
|
}
|
|
|
|
|
2015-10-31 15:50:52 +03:00
|
|
|
// RecoverPath should only be used with confusion net or word lattice input
|
|
|
|
if (output.RecoverPath && input.input_type == SentenceInput)
|
|
|
|
{
|
|
|
|
TRACE_ERR("--recover-input-path should only be used with "
|
|
|
|
<<"confusion net or word lattice input!\n");
|
|
|
|
output.RecoverPath = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set m_nbest_options.enabled = true if necessary:
|
|
|
|
nbest.enabled = (nbest.enabled || mira || search.consensus
|
|
|
|
|| nbest.nbest_size > 0
|
2015-11-23 15:37:11 +03:00
|
|
|
|| mbr.enabled || lmbr.enabled
|
2015-10-31 15:50:52 +03:00
|
|
|
|| !output.SearchGraph.empty()
|
|
|
|
|| !output.SearchGraphExtended.empty()
|
|
|
|
|| !output.SearchGraphSLF.empty()
|
|
|
|
|| !output.SearchGraphHG.empty()
|
|
|
|
|| !output.SearchGraphPB.empty()
|
|
|
|
|| output.lattice_sample_size != 0);
|
|
|
|
|
2015-08-06 02:51:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-07 21:17:37 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_XMLRPC_C
|
|
|
|
bool
|
|
|
|
AllOptions::
|
|
|
|
update(std::map<std::string,xmlrpc_c::value>const& param)
|
|
|
|
{
|
|
|
|
if (!search.update(param)) return false;
|
|
|
|
if (!cube.update(param)) return false;
|
|
|
|
if (!nbest.update(param)) return false;
|
|
|
|
if (!reordering.update(param)) return false;
|
|
|
|
if (!context.update(param)) return false;
|
|
|
|
if (!input.update(param)) return false;
|
|
|
|
if (!mbr.update(param)) return false;
|
|
|
|
if (!lmbr.update(param)) return false;
|
2015-10-31 15:50:52 +03:00
|
|
|
if (!output.update(param)) return false;
|
2015-11-11 20:07:45 +03:00
|
|
|
if (!unk.update(param)) return false;
|
2015-12-08 02:34:57 +03:00
|
|
|
if (!syntax.update(param)) return false;
|
2015-10-31 15:50:52 +03:00
|
|
|
return sanity_check();
|
2015-08-07 21:17:37 +03:00
|
|
|
}
|
2017-03-01 14:41:04 +03:00
|
|
|
#else
|
|
|
|
bool
|
|
|
|
AllOptions::
|
|
|
|
update(std::map<std::string,xmlrpc_c::value>const& param)
|
|
|
|
{}
|
2015-08-07 21:17:37 +03:00
|
|
|
#endif
|
|
|
|
|
2015-10-31 15:50:52 +03:00
|
|
|
bool
|
|
|
|
AllOptions::
|
|
|
|
NBestDistinct() const
|
|
|
|
{
|
|
|
|
return (nbest.only_distinct
|
|
|
|
|| mbr.enabled || lmbr.enabled
|
|
|
|
|| output.lattice_sample_size
|
|
|
|
|| !output.SearchGraph.empty()
|
|
|
|
|| !output.SearchGraphExtended.empty()
|
|
|
|
|| !output.SearchGraphSLF.empty()
|
|
|
|
|| !output.SearchGraphHG.empty());
|
|
|
|
}
|
2015-08-07 21:17:37 +03:00
|
|
|
|
2015-10-31 15:50:52 +03:00
|
|
|
|
2015-08-06 02:51:02 +03:00
|
|
|
}
|