Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
feature-extractor.H
Go to the documentation of this file.
1 // Copyright 2012, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 // -----------------------------------------------------------------------------
30 //
31 //
35 
36 #ifndef RERANKER_FEATURE_EXTRACTOR_H_
37 #define RERANKER_FEATURE_EXTRACTOR_H_
38 
39 #include <string>
40 #include <memory>
41 #include <unordered_map>
42 
43 #include "feature-vector.H"
44 #include "candidate.H"
45 #include "candidate-set.H"
46 #include "factory.H"
47 
48 namespace reranker {
49 
50 using std::string;
51 using std::shared_ptr;
52 using std::unordered_map;
53 
56 void TearDown();
57 
87  public:
91  virtual ~FeatureExtractor() {}
92 
104  virtual void Extract(Candidate &candidate,
105  FeatureVector<int,double> &features) = 0;
106 
119  virtual void ExtractSymbolic(Candidate &candidate,
120  FeatureVector<string,double> &symbolic_features)
121  = 0;
122 
128  virtual void Reset() {
129  }
130 
139  virtual void Extract(CandidateSet &candidate_set) {
140  for (CandidateSet::iterator it = candidate_set.begin();
141  it != candidate_set.end();
142  ++it) {
143  Candidate &candidate = *(*it);
144  Extract(candidate, candidate.mutable_features());
145  ExtractSymbolic(candidate, candidate.mutable_symbolic_features());
146  }
147  }
148 };
149 
154 #define REGISTER_NAMED_FEATURE_EXTRACTOR(TYPE,NAME) \
155  REGISTER_NAMED(TYPE,NAME,FeatureExtractor)
156 
161 #define REGISTER_FEATURE_EXTRACTOR(TYPE) \
162  REGISTER_NAMED_FEATURE_EXTRACTOR(TYPE,TYPE)
163 
164 } // namespace reranker
165 
166 #endif
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
FeatureExtractor()
Constructs an empty feature vector.
vector< shared_ptr< Candidate > >::iterator iterator
Definition: candidate-set.H:73
virtual void Extract(Candidate &candidate, FeatureVector< int, double > &features)=0
Extracts features for the specified candidate, where each feature is represented by an int for its un...
virtual ~FeatureExtractor()
Destroys this vector.
virtual void Reset()
Indicates to this instance that iteration over candidate sets on which features are being extracted h...
virtual void Extract(CandidateSet &candidate_set)
Extracts features for all the candidates in the specified CandidateSet.
void TearDown()
A free-floating function (within the reranker namespace) that frees statically allocated objects...
A class to hold a set of candidates, either for training or test.
Definition: candidate-set.H:62
A class to represent a candidate in a set of candidates that constitutes a training instance for a re...
Definition: candidate.H:60
An abstract base class/interface for all feature extractors.
const_iterator begin() const
Definition: candidate-set.H:86
Defines the reranker::FeatureVector class, which, as it happens, is used to store feature vectors...
An interface to make it easier to implement Factory-constructible types by implementing both required...
Definition: factory.H:382
virtual void ExtractSymbolic(Candidate &candidate, FeatureVector< string, double > &symbolic_features)=0
Extracts symbolic features for the specified candidate, where each feature is represented by a string...
const_iterator end() const
Definition: candidate-set.H:88
Provides a generic dynamic object factory.
Class to hold a single training instance for a reranker, which is a set of examples, typically the n-best output of some input process, posibly including a gold-standard feature vector.