diff options
author | Patrick Simianer <p@simianer.de> | 2014-07-20 15:08:12 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-07-20 15:08:12 +0200 |
commit | 08e9a6f71c80fc7327d1758312b40bd5ba763dc9 (patch) | |
tree | 93a027bbb3e34fd60cc8e5d030a443a7f665389f /fast/make_paks.cc | |
parent | f219bab21c07d02e7e54d557e23387bd93c9ce5f (diff) |
a lot
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()); |