00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023 #include <iostream>
00024
00025 #include <boost/program_options.hpp>
00026 #include <boost/scoped_ptr.hpp>
00027
00028 #include "HopeFearDecoder.h"
00029
00030 using namespace std;
00031 using namespace MosesTuning;
00032
00033 namespace po = boost::program_options;
00034
00035
00036 int main(int argc, char** argv)
00037 {
00038 bool help;
00039 string denseInitFile;
00040 string sparseInitFile;
00041 string hypergraphFile;
00042 size_t edgeCount = 500;
00043
00044 po::options_description desc("Allowed options");
00045 desc.add_options()
00046 ("help,h", po::value(&help)->zero_tokens()->default_value(false), "Print this help message and exit")
00047 ("dense-init,d", po::value<string>(&denseInitFile), "Weight file for dense features.")
00048 ("sparse-init,s", po::value<string>(&sparseInitFile), "Weight file for sparse features")
00049 ("hypergraph,g", po::value<string>(&hypergraphFile), "File containing compressed hypergraph")
00050 ;
00051
00052 po::options_description cmdline_options;
00053 cmdline_options.add(desc);
00054 po::variables_map vm;
00055 po::store(po::command_line_parser(argc,argv).
00056 options(cmdline_options).run(), vm);
00057 po::notify(vm);
00058 if (help) {
00059 cout << "Usage: " + string(argv[0]) + " [options]" << endl;
00060 cout << desc << endl;
00061 exit(0);
00062 }
00063
00064 if (hypergraphFile.empty()) {
00065 cerr << "Error: missing hypergraph file" << endl;
00066 exit(1);
00067 }
00068
00069 Vocab vocab;
00070
00071
00072 ReferenceSet references;
00073 references.AddLine(0,"blah blah blah", vocab);
00074
00075
00076 pair<MiraWeightVector*, size_t> ret = InitialiseWeights(denseInitFile, sparseInitFile, "hypergraph", true);
00077 boost::scoped_ptr<MiraWeightVector> wv(ret.first);
00078 size_t initDenseSize = ret.second;
00079 SparseVector weights;
00080 wv->ToSparse(&weights, initDenseSize);
00081
00082
00083 Graph graph(vocab);
00084 util::scoped_fd fd(util::OpenReadOrThrow(hypergraphFile.c_str()));
00085 util::FilePiece file(fd.release());
00086 ReadGraph(file,graph);
00087
00088 boost::shared_ptr<Graph> prunedGraph;
00089 prunedGraph.reset(new Graph(vocab));
00090 graph.Prune(prunedGraph.get(), weights, edgeCount);
00091
00092 vector<ValType> bg(9);
00093 HgHypothesis bestHypo;
00094
00095 Viterbi(*prunedGraph, weights, 0, references, 0, bg, &bestHypo);
00096
00097 for (size_t i = 0; i < bestHypo.text.size(); ++i) {
00098 cout << bestHypo.text[i]->first << " ";
00099 }
00100 cout << endl;
00101
00102
00103 cerr << "WEIGHTS ";
00104 bestHypo.featureVector.write(cerr, "=");
00105 cerr << endl;
00106
00107 }
00108