summaryrefslogtreecommitdiff
path: root/decoder/hg_cfg.h
blob: b90aca47fdf0e14c41d819b473afbed13c74b57b (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
#ifndef HG_CFG_H
#define HG_CFG_H

#include "cfg.h"

class Hypergraph;

// in case you might want the CFG whether or not you apply FSA models:
struct HgCFG {
  void set_defaults() {
    have_cfg=binarized=have_features=uniqed=false;
    want_features=true;
  }
  HgCFG(Hypergraph const& ih) : ih(ih) {
    set_defaults();
  }
  Hypergraph const& ih;
  CFG cfg;
  bool have_cfg;
  bool have_features;
  bool want_features;
  void InitCFG(CFG &to) {
    to.Init(ih,true,want_features,true);
  }
  bool binarized;
  bool uniqed;
  CFG &GetCFG()
  {
    if (!have_cfg) {
      have_cfg=true;
      InitCFG(cfg);
    }
    return cfg;
  }
  void GiveCFG(CFG &to) {
    if (!have_cfg)
      InitCFG(to);
    else {
      cfg.VisitRuleIds(*this);
      have_cfg=false;
      to.Clear();
      swap(to,cfg);
    }
  }
  void operator()(int ri) const {
  }
  CFG const& GetCFG() const {
    assert(have_cfg);
    return cfg;
  }
};


#endif