Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AllOptions.cpp « parameters « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dfe5f89e02af5a6cd98931ed691e94629206e6bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "AllOptions.h"

namespace Moses
{
  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;
    if (!mbr.init(param))        return false;
    if (!lmbr.init(param))       return false;
    if (!output.init(param))     return false;
    if (!unk.init(param))        return false;
    if (!syntax.init(param))     return false;

    param.SetParameter(mira, "mira", false);

    return sanity_check();
  }

  bool
  AllOptions::
  sanity_check()
  {
    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) 
          {
            cerr << "Error: Cannot use consensus decoding together with mbr" 
                 << endl;
            return false;
          }
        mbr.enabled = true;
      }

    // 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
                     || mbr.enabled || lmbr.enabled
                     || !output.SearchGraph.empty()
                     || !output.SearchGraphExtended.empty()
                     || !output.SearchGraphSLF.empty()
                     || !output.SearchGraphHG.empty()
                     || !output.SearchGraphPB.empty()
                     || output.lattice_sample_size != 0);
    
    return true;
  }

#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;
    if (!output.update(param))     return false;
    if (!unk.update(param))        return false;
    if (!syntax.update(param))     return false;
    return sanity_check();
  }
#endif

  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());
  }

  
}