summaryrefslogtreecommitdiff
path: root/decoder/decoder.h
blob: 79c7a602e825b4c8cd898dde625ba94ee78b3b35 (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
#ifndef _DECODER_H_
#define _DECODER_H_

#include <iostream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/program_options/variables_map.hpp>

#include "weights.h"  // weight_t

#undef CP_TIME
//#define CP_TIME
#ifdef CP_TIME
#include <time.h>
struct CpTime{
public:
	static void Add(clock_t x);
	static void Sub(clock_t x);
	static double Get();
private:
    static clock_t time_;
};
#endif

class SentenceMetadata;
class Hypergraph;
struct DecoderImpl;

struct DecoderObserver {
  virtual ~DecoderObserver();
  virtual void NotifyDecodingStart(const SentenceMetadata& smeta);
  virtual void NotifySourceParseFailure(const SentenceMetadata& smeta);
  virtual void NotifyTranslationForest(const SentenceMetadata& smeta, Hypergraph* hg);
  virtual void NotifyAlignmentFailure(const SentenceMetadata& semta);
  virtual void NotifyAlignmentForest(const SentenceMetadata& smeta, Hypergraph* hg);
  virtual void NotifyDecodingComplete(const SentenceMetadata& smeta);
};

struct Grammar;  // TODO once the decoder interface is cleaned up,
                 // this should be somewhere else
struct Decoder {
  Decoder(int argc, char** argv);
  Decoder(std::istream* config_file);
  bool Decode(const std::string& input, DecoderObserver* observer = NULL);

  // access this to either *read* or *write* to the decoder's last
  // weight vector (i.e., the weights of the finest past)
  std::vector<weight_t>& CurrentWeightVector();
  const std::vector<weight_t>& CurrentWeightVector() const;

  void SetId(int id);
  ~Decoder();
  const boost::program_options::variables_map& GetConf() const { return conf; }

  // add grammar rules (currently only supported by SCFG decoders)
  // that will be used on subsequent calls to Decode. rules should be in standard
  // text format. This function does NOT read from a file.
  void AddSupplementalGrammar(boost::shared_ptr<Grammar> gp);
  void AddSupplementalGrammarFromString(const std::string& grammar_string);
 private:
  boost::program_options::variables_map conf;
  boost::shared_ptr<DecoderImpl> pimpl_;
};

#endif