diff options
Diffstat (limited to 'fast/make_paks.cc')
-rw-r--r-- | fast/make_paks.cc | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/fast/make_paks.cc b/fast/make_paks.cc index 6fe7fae..c0fee90 100644 --- a/fast/make_paks.cc +++ b/fast/make_paks.cc @@ -1,26 +1,25 @@ #include <iostream> #include <fstream> #include <string> +#include <unordered_map> #include <msgpack.hpp> -#include <msgpack/fbuffer.h> #include <msgpack/fbuffer.hpp> -#include <unordered_map> #include "json-cpp.hpp" -#include "hypergraph.hh" #include "dummyvector.h" +#include "hypergraph.hh" using namespace std; struct DummyNode { - int id; + size_t id; string cat; - vector<int> span; + vector<short> span; }; struct DummyEdge { - int head; + size_t head; string rule; vector<size_t> tails; DummyVector f; @@ -57,15 +56,13 @@ serialize(jsoncpp::Stream<X>& stream, DummyVector& o) fields(o, stream, "EgivenFCoherent", o.EgivenFCoherent, "SampleCountF", o.SampleCountF, "CountEF", o.CountEF, "MaxLexFgivenE", o.MaxLexFgivenE, "MaxLexEgivenF", o.MaxLexEgivenF, "IsSingletonF", o.IsSingletonF, "IsSingletonFE", o.IsSingletonFE, "LanguageModel", o.LanguageModel, "LanguageModel_OOV", o.LanguageModel_OOV, "PassThrough", o.PassThrough, "PassThrough_1", o.PassThrough_1, "PassThrough_2", o.PassThrough_2, "PassThrough_3", o.PassThrough_3, "PassThrough_4", o.PassThrough_4, "PassThrough_5", o.PassThrough_5, "PassThrough_6", o.PassThrough_6, "WordPenalty", o.WordPenalty, "Glue", o.Glue); } - - int main(int argc, char** argv) { + // read from json ifstream ifs(argv[1]); string json_str((istreambuf_iterator<char>(ifs) ), (istreambuf_iterator<char>())); - DummyHg hg; vector<DummyNode> nodes; hg.nodes = nodes; @@ -75,19 +72,19 @@ main(int argc, char** argv) hg.weights = w; jsoncpp::parse(hg, json_str); + // convert objects vector<Hg::Node*> nodes_; for (auto it = hg.nodes.begin(); it != hg.nodes.end(); ++it) { - Hg::Node* n = new Hg::Node; - n->id = it->id; + Hg::Node* n = new Hg::Node; + n->id = it->id; n->symbol = it->cat; n->left = it->span[0]; n->right = it->span[1]; nodes_.push_back(n); } - vector<Hg::Edge*> edges_; for (auto it = hg.edges.begin(); it != hg.edges.end(); ++it) { - Hg::Edge* e = new Hg::Edge; + Hg::Edge* e = new Hg::Edge; e->head_id_ = it->head; e->tails_ids_ = it->tails; e->score = it->weight; @@ -96,6 +93,7 @@ main(int argc, char** argv) edges_.push_back(e); } + // write to msgpack FILE* file = fopen(argv[2], "wb"); msgpack::fbuffer fbuf(file); msgpack::pack(fbuf, hg.nodes.size()); |