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-test.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 //
36 
37 #include <iostream>
38 #include <memory>
39 
40 #include "candidate.H"
41 #include "candidate-set.H"
42 #include "feature-extractor.H"
44 
45 using namespace std;
46 using namespace reranker;
47 
48 int
49 main(int argc, char **argv) {
51  shared_ptr<FeatureExtractor> example_feature_extractor1 =
52  factory.CreateOrDie("ExampleFeatureExtractor(arg(\"my_feats:\"))", "");
53 
54  shared_ptr<FeatureExtractor> example_feature_extractor2 =
55  factory.CreateOrDie("ExampleFeatureExtractor(b(true), "
56  "arg(\"your_feats:\"))", "");
57 
58  shared_ptr<FeatureExtractor> example_feature_extractor3 =
59  factory.CreateOrDie("ExampleFeatureExtractor(arg(\"whose_feats:\"), "
60  "strvec({\"foo\", \"bar\", \"baz\"}))", "");
61 
62  shared_ptr<FeatureExtractor> example_feature_extractor4 =
63  factory.CreateOrDie("ExampleFeatureExtractor(b(true))", "");
64 
65  CandidateSet candidate_set("test candidate set");
66  candidate_set.set_reference_string("This is a reference string.");
67  shared_ptr<Candidate> c1(new Candidate(0, 0.1, 0.7, 5,
68  "This is a silly string."));
69  candidate_set.AddCandidate(c1);
70  shared_ptr<Candidate> c2(new Candidate(1, 0.2, 0.8, 5,
71  "This is a sillier string."));
72  candidate_set.AddCandidate(c2);
73 
74  example_feature_extractor1->Extract(candidate_set);
75  example_feature_extractor2->Extract(candidate_set);
76  example_feature_extractor3->Extract(candidate_set);
77 
78  cout << candidate_set << endl;
79 }
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
void set_reference_string(const string &reference_string)
Provides the reranker::FeatureExtractor interface.
void AddCandidate(shared_ptr< Candidate > candidate)
Factory for dynamically created instance of the specified type.
Definition: factory.H:396
A class to hold a set of candidates, either for training or test.
Definition: candidate-set.H:62
Provides the reranker::ExampleFeatureExtractor class, which illustrates how to write a reranker::Feat...
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
A class to represent a candidate in a set of candidates that constitutes a training instance for a re...
Definition: candidate.H:60
int main(int argc, char **argv)
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.