summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--fast/.gitignore5
-rw-r--r--fast/Makefile11
-rw-r--r--fast/hypergraph.cc16
-rw-r--r--fast/hypergraph.hh2
-rw-r--r--fast/main.cc7
-rw-r--r--util/Makefile14
-rw-r--r--util/json-cpp.hpp (renamed from fast/json-cpp.hpp)0
-rw-r--r--util/make_pak.cc (renamed from fast/make_paks.cc)18
-rw-r--r--util/read_pak.cc (renamed from fast/read_pak.cc)1
10 files changed, 45 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..00b0e1a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.o
+fast/example/
+fast/fast_weaver
+util/make_pak
+util/read_pak
diff --git a/fast/.gitignore b/fast/.gitignore
deleted file mode 100644
index c37a566..0000000
--- a/fast/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-fast_weaver
-*.o
-data
-make_paks
-read_pak
diff --git a/fast/Makefile b/fast/Makefile
index 55c4df7..2d2ba68 100644
--- a/fast/Makefile
+++ b/fast/Makefile
@@ -1,20 +1,15 @@
COMPILER=clang
+
all: hypergraph.o main.cc
$(COMPILER) -std=c++11 -lstdc++ -lm -lmsgpack hypergraph.o main.cc -o fast_weaver
hypergraph.o: hypergraph.cc hypergraph.hh grammar.o semiring.hh
- $(COMPILER) -g -std=c++11 -lmsgpack -c hypergraph.cc
+ $(COMPILER) -g -std=c++11 -c hypergraph.cc
grammar.o: grammar.cc grammar.hh
$(COMPILER) -g -std=c++11 -c grammar.cc
-make_paks: make_paks.cc
- $(COMPILER) -std=c++11 -lstdc++ -lm -lmsgpack make_paks.cc -o make_paks
-
-read_pak: read_pak.cc
- $(COMPILER) -std=c++11 -lmsgpack read_pak.cc -o read_pak
-
clean:
- rm -f fast_weaver hypergraph.o grammar.o make_paks read_pak
+ rm -f fast_weaver hypergraph.o grammar.o
diff --git a/fast/hypergraph.cc b/fast/hypergraph.cc
index c3c587c..a01fb3e 100644
--- a/fast/hypergraph.cc
+++ b/fast/hypergraph.cc
@@ -74,9 +74,11 @@ topological_sort(list<Node*>& nodes, list<Node*>::iterator root)
auto to = nodes.begin();
while (to != nodes.end()) {
if ((**p).is_marked()) {
+ cout << **p<< endl;
// explore edges
for (auto e = (**p).outgoing.begin(); e!=(**p).outgoing.end(); ++e) {
(**e).mark++;
+ cout << " " << **e << endl;
if ((**e).is_marked()) {
(**e).head->mark++;
}
@@ -88,10 +90,17 @@ topological_sort(list<Node*>& nodes, list<Node*>::iterator root)
p = to;
} else {
++p;
- if (p == nodes.end()) {
- p = next(to);
+ /*if (p == nodes.end()) {
+ for (auto e = (**to).outgoing.begin(); e!=(**to).outgoing.end(); ++e) {
+ // explore edges
+ (**e).mark++;
+ if ((**e).is_marked()) {
+ (**e).head->mark++;
+ }
+ }
to = next(to);
- }
+ p = to;
+ }*/
}
}
cout << "---" << endl;
@@ -151,6 +160,7 @@ read(Hypergraph& hg, string fn)
e->head = hg.nodes_by_id[e->head_id_];
hg.edges.push_back(e);
hg.nodes_by_id[e->head_id_]->incoming.push_back(e);
+ e->arity = 0;
for (auto it = e->tails_ids_.begin(); it != e->tails_ids_.end(); ++it) {
hg.nodes_by_id[*it]->outgoing.push_back(e);
e->tails.push_back(hg.nodes_by_id[*it]);
diff --git a/fast/hypergraph.hh b/fast/hypergraph.hh
index 530fbe6..5a68742 100644
--- a/fast/hypergraph.hh
+++ b/fast/hypergraph.hh
@@ -32,7 +32,7 @@ struct Edge {
score_t score;
string rule; //FIXME
DummyVector f; //FIXME
- unsigned int arity;
+ unsigned int arity = 0;
unsigned int mark = 0;
inline bool is_marked() { return mark >= arity; }
diff --git a/fast/main.cc b/fast/main.cc
index 9c64976..2a8676b 100644
--- a/fast/main.cc
+++ b/fast/main.cc
@@ -5,14 +5,7 @@ int
main(int argc, char** argv)
{
Hg::Hypergraph hg;
- //Hg::io::manual(hg);
Hg::io::read(hg, argv[1]);
- /*cout << "---" << endl;
- for (auto it = hg.nodes.begin(); it!=hg.nodes.end(); it++)
- cout << **it << endl;
- for (auto it = hg.edges.begin(); it!=hg.edges.end(); it++)
- cout << **it << endl;
- cout << "---" << endl;*/
Hg::viterbi(hg);
return 0;
diff --git a/util/Makefile b/util/Makefile
new file mode 100644
index 0000000..08ead26
--- /dev/null
+++ b/util/Makefile
@@ -0,0 +1,14 @@
+COMPILER=clang
+
+
+all: make_pak read_pak
+
+make_pak: make_pak.cc
+ $(COMPILER) -std=c++11 -lstdc++ -lm -lmsgpack make_pak.cc -o make_pak
+
+read_pak: read_pak.cc
+ $(COMPILER) -std=c++11 -lstdc++ -lmsgpack read_pak.cc -o read_pak
+
+clean:
+ rm -f make_pak read_pak
+
diff --git a/fast/json-cpp.hpp b/util/json-cpp.hpp
index 851a4f4..851a4f4 100644
--- a/fast/json-cpp.hpp
+++ b/util/json-cpp.hpp
diff --git a/fast/make_paks.cc b/util/make_pak.cc
index c0fee90..f09c17d 100644
--- a/fast/make_paks.cc
+++ b/util/make_pak.cc
@@ -1,13 +1,12 @@
#include <iostream>
#include <fstream>
#include <string>
-#include <unordered_map>
#include <msgpack.hpp>
#include <msgpack/fbuffer.hpp>
#include "json-cpp.hpp"
-#include "dummyvector.h"
-#include "hypergraph.hh"
+#include "../fast/dummyvector.h"
+#include "../fast/hypergraph.hh"
using namespace std;
@@ -73,16 +72,16 @@ main(int argc, char** argv)
jsoncpp::parse(hg, json_str);
// convert objects
- vector<Hg::Node*> nodes_;
+ vector<Hg::Node*> nodes_conv;
for (auto it = hg.nodes.begin(); it != hg.nodes.end(); ++it) {
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);
+ nodes_conv.push_back(n);
}
- vector<Hg::Edge*> edges_;
+ vector<Hg::Edge*> edges_conv;
for (auto it = hg.edges.begin(); it != hg.edges.end(); ++it) {
Hg::Edge* e = new Hg::Edge;
e->head_id_ = it->head;
@@ -90,7 +89,7 @@ main(int argc, char** argv)
e->score = it->weight;
e->rule = it->rule;
e->f = it->f;
- edges_.push_back(e);
+ edges_conv.push_back(e);
}
// write to msgpack
@@ -98,11 +97,10 @@ main(int argc, char** argv)
msgpack::fbuffer fbuf(file);
msgpack::pack(fbuf, hg.nodes.size());
msgpack::pack(fbuf, hg.edges.size());
- for (auto it = nodes_.begin(); it != nodes_.end(); ++it)
+ for (auto it = nodes_conv.begin(); it != nodes_conv.end(); ++it)
msgpack::pack(fbuf, **it);
- for (auto it = edges_.begin(); it != edges_.end(); ++it)
+ for (auto it = edges_conv.begin(); it != edges_conv.end(); ++it)
msgpack::pack(fbuf, **it);
-
fclose(file);
return 0;
diff --git a/fast/read_pak.cc b/util/read_pak.cc
index c1cf761..d4bff91 100644
--- a/fast/read_pak.cc
+++ b/util/read_pak.cc
@@ -25,3 +25,4 @@ main(int argc, char** argv)
return 0;
}
+