From 190f68c880eb27506669e95e2bc0493e2ec42c4c Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sun, 17 Aug 2014 07:51:16 +0100
Subject: functional again
---
util/make_pak.cc | 72 ++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 38 deletions(-)
(limited to 'util/make_pak.cc')
diff --git a/util/make_pak.cc b/util/make_pak.cc
index f09c17d..e858155 100644
--- a/util/make_pak.cc
+++ b/util/make_pak.cc
@@ -1,58 +1,52 @@
#include
#include
-#include
#include
#include
+#include
-#include "json-cpp.hpp"
-#include "../fast/dummyvector.h"
+#include "json-cpp/single_include/json-cpp.hpp"
#include "../fast/hypergraph.hh"
+#include "../fast/weaver.hh"
using namespace std;
struct DummyNode {
- size_t id;
- string cat;
+ size_t id;
+ string symbol;
vector span;
};
struct DummyEdge {
- size_t head;
- string rule;
- vector tails;
- DummyVector f;
- score_t weight;
+ size_t head_id;
+ size_t rule_id;
+ vector tails_ids;
+ string f;
+ score_t score;
};
struct DummyHg {
+ vector rules;
vector nodes;
vector edges;
- DummyVector weights;
};
template inline void
serialize(jsoncpp::Stream& stream, DummyNode& o)
{
- fields(o, stream, "id", o.id, "cat", o.cat, "span", o.span);
+ fields(o, stream, "id", o.id, "symbol", o.symbol, "span", o.span);
}
template inline void
serialize(jsoncpp::Stream& stream, DummyEdge& o)
{
- fields(o, stream, "head", o.head, "rule", o.rule, "tails", o.tails, "f", o.f, "weight", o.weight);
+ fields(o, stream, "head", o.head_id, "rule", o.rule_id, "tails", o.tails_ids, "score", o.score);
}
template inline void
serialize(jsoncpp::Stream& stream, DummyHg& o)
{
- fields(o, stream, "nodes", o.nodes, "edges", o.edges, "weights", o.weights);
-}
-
-template inline void
-serialize(jsoncpp::Stream& 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);
+ fields(o, stream, "rules", o.rules, "nodes", o.nodes, "edges", o.edges);
}
int
@@ -63,44 +57,46 @@ main(int argc, char** argv)
string json_str((istreambuf_iterator(ifs) ),
(istreambuf_iterator()));
DummyHg hg;
+ vector rules;
+ hg.rules = rules;
vector nodes;
hg.nodes = nodes;
vector edges;
hg.edges = edges;
- DummyVector w;
- hg.weights = w;
jsoncpp::parse(hg, json_str);
- // convert objects
+ // convert to proper objects
vector nodes_conv;
- for (auto it = hg.nodes.begin(); it != hg.nodes.end(); ++it) {
+ for (const auto it: hg.nodes) {
Hg::Node* n = new Hg::Node;
- n->id = it->id;
- n->symbol = it->cat;
- n->left = it->span[0];
- n->right = it->span[1];
+ n->id = it.id;
+ n->symbol = it.symbol;
+ n->left = it.span[0];
+ n->right = it.span[1];
nodes_conv.push_back(n);
}
vector edges_conv;
- for (auto it = hg.edges.begin(); it != hg.edges.end(); ++it) {
+ for (const auto it: hg.edges) {
Hg::Edge* e = new Hg::Edge;
- e->head_id_ = it->head;
- e->tails_ids_ = it->tails;
- e->score = it->weight;
- e->rule = it->rule;
- e->f = it->f;
+ e->head_id_ = it.head_id;
+ e->tails_ids_ = it.tails_ids;
+ e->score = it.score;
+ e->rule_id_ = it.rule_id;
edges_conv.push_back(e);
}
// write to msgpack
FILE* file = fopen(argv[2], "wb");
msgpack::fbuffer fbuf(file);
+ msgpack::pack(fbuf, hg.rules.size());
msgpack::pack(fbuf, hg.nodes.size());
msgpack::pack(fbuf, hg.edges.size());
- for (auto it = nodes_conv.begin(); it != nodes_conv.end(); ++it)
- msgpack::pack(fbuf, **it);
- for (auto it = edges_conv.begin(); it != edges_conv.end(); ++it)
- msgpack::pack(fbuf, **it);
+ for (const auto it: hg.rules)
+ msgpack::pack(fbuf, it);
+ for (const auto it: nodes_conv)
+ msgpack::pack(fbuf, *it);
+ for (const auto it: edges_conv)
+ msgpack::pack(fbuf, *it);
fclose(file);
return 0;
--
cgit v1.2.3