Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
executive-feature-extractor.C
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 //
38 
39 #include <iostream>
40 #include <fstream>
41 #include <string>
42 #include <vector>
43 
44 #include "candidate.H"
45 #include "candidate-set.H"
46 #include "feature-extractor.H"
48 #include "stream-tokenizer.H"
49 
50 #define DEBUG 1
51 
52 using std::cerr;
53 using std::endl;
54 using std::ifstream;
55 using std::istream;
56 using std::string;
57 using std::vector;
58 
59 namespace reranker {
60 
61 IMPLEMENT_FACTORY(ExecutiveFeatureExtractor)
62 
64 
65 // Factory method to initialize an ExecutiveFeatureExtractor instance
66 // from a spec string contained in a file.
67 shared_ptr<ExecutiveFeatureExtractor>
68 ExecutiveFeatureExtractor::InitFromSpec(const string &filename) {
70  ifstream is(filename.c_str());
71  StreamTokenizer st(is);
72  return factory.CreateOrDie(st);
73 }
74 
75 void
76 ExecutiveFeatureExtractorImpl::Reset() const {
77  for (vector<shared_ptr<FeatureExtractor> >::const_iterator it =
78  extractors_.begin();
79  it != extractors_.end();
80  ++it) {
81  (*it)->Reset();
82  }
83 }
84 
85 void
86 ExecutiveFeatureExtractorImpl::Extract(CandidateSet &candidate_set) const {
87  for (vector<shared_ptr<FeatureExtractor> >::const_iterator it =
88  extractors_.begin();
89  it != extractors_.end();
90  ++it) {
91  (*it)->Extract(candidate_set);
92  }
93 }
94 
95 } // namespace reranker
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
A simple class for tokenizing a stream of tokens for the formally specified language used to construc...
Provides the reranker::FeatureExtractor interface.
This class is like a regular FeatureExtractor, but has been promoted to the executive level and thus ...
Factory for dynamically created instance of the specified type.
Definition: factory.H:396
Provides the StreamTokenizer class.
Provides the reranker::ExecutiveFeatureExtractor class.
shared_ptr< T > CreateOrDie(StreamTokenizer &st, Environment *env=NULL)
Dynamically creates an object, whose type and initialization are contained in a specification string...
Definition: factory.H:562
#define IMPLEMENT_FACTORY(BASE)
Provides the necessary implementation for a factory for the specified BASE class type.
Definition: factory.H:821
#define REGISTER_EXECUTIVE_FEATURE_EXTRACTOR(TYPE)
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.