Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
candidate-set-proto-writer-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 //
35 
36 #include <iostream>
37 
38 #include "../proto/data.pb.h"
39 #include "../proto/dataio.h"
40 #include "candidate.H"
41 #include "candidate-set.H"
44 
45 using namespace reranker;
46 using namespace std;
47 
48 int main(int argc, char **argv) {
50  bool is_compressed = true;
51  bool use_base64 = true;
52  ConfusionProtoIO* reader = NULL;
53  if (argc >= 2) {
54  reader = new ConfusionProtoIO(argv[1], ConfusionProtoIO::READ,
55  is_compressed, use_base64);
56  } else {
57  reader = new ConfusionProtoIO("", ConfusionProtoIO::READSTD,
58  is_compressed, use_base64);
59  }
60  bool reader_valid = true;
61  CandidateSet candidate_set;
62  while (reader_valid) {
63  confusion_learning::CandidateSetMessage tmp_msg;
64  reader_valid = reader->Read(&tmp_msg);
65  cspr.Read(tmp_msg, 1, candidate_set);
66 
67  cout << "Here's the one candidate set:" << endl;
68  cout << candidate_set;
69  break; // read a single CandidateSet
70  }
71  reader->Close();
72  delete reader;
73 
75  confusion_learning::CandidateSetMessage cs_msg;
76  cspw.Write(candidate_set, &cs_msg);
77 
78  CandidateSet re_read_candidate_set;
79  cspr.Read(cs_msg, re_read_candidate_set);
80  cout << "Successfully wrote out and then re-read candidate set. Here it is:"
81  << endl
82  << re_read_candidate_set
83  << endl
84  << "Have a nice day!" << endl;
85 }
void Read(const CandidateSetMessage &m, CandidateSet &set)
Fills in the specified CandidateSet based on the specified CandidateSetMessage, crucially constructin...
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
int main(int argc, char **argv)
void Write(const CandidateSet &set, CandidateSetMessage *candidate_set_message) const
Serializes a CandidateSet instance to a CandidateSetMessage.
A class to construct a CandidateSetMessage from a CandidateSet instance.
Serializer for reranker::CandidateSet instances to CandidateSetMessage instances. ...
A class to hold a set of candidates, either for training or test.
Definition: candidate-set.H:62
Reads CandidateSetMessage instances and converts them to reranker::CandidateSet instances.
A class to fill in a CandidateSet based on a CandidateSetMessage, crucially constructing new Candidat...
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.