summaryrefslogtreecommitdiff
path: root/decoder/ff_tagger.h
blob: 41c3ee5b1799c847cbffce67de3d543df8ce9990 (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
#ifndef _FF_TAGGER_H_
#define _FF_TAGGER_H_

#include <map>
#include "ff.h"

typedef std::map<WordID, int> Class2FID;
typedef std::map<WordID, Class2FID> Class2Class2FID;

// the reason this is a "tagger" feature is that it assumes that
// the sequence unfolds from left to right, which means it doesn't
// have to split states based on left context.
// fires unigram features as well
class Tagger_BigramIdentity : public FeatureFunction {
 public:
  Tagger_BigramIdentity(const std::string& param);
 protected:
  virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta,
                                     const Hypergraph::Edge& edge,
                                     const std::vector<const void*>& ant_contexts,
                                     SparseVector<double>* features,
                                     SparseVector<double>* estimated_features,
                                     void* context) const;
 private:
  void FireFeature(const WordID& left,
                   const WordID& right,
                   SparseVector<double>* features) const;
  mutable Class2Class2FID fmap_;
};

// for each pair of symbols cooccuring in a lexicalized rule, fire
// a feature (mostly used for tagging, but could be used for any model)
class LexicalPairIdentity : public FeatureFunction {
 public:
  LexicalPairIdentity(const std::string& param);
 protected:
  virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta,
                                     const Hypergraph::Edge& edge,
                                     const std::vector<const void*>& ant_contexts,
                                     SparseVector<double>* features,
                                     SparseVector<double>* estimated_features,
                                     void* context) const;
 private:
  void FireFeature(WordID src,
                   WordID trg,
                   SparseVector<double>* features) const;
  mutable Class2Class2FID fmap_;
};


#endif