From a9e4e3e3224647c178cca1177f17e89fe8866d22 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 20 Jul 2014 15:28:48 +0200 Subject: cleanup --- fast/grammar.cc | 11 +---------- fast/grammar.hh | 17 +++++------------ fast/grammar.o | Bin 34344 -> 2928 bytes fast/hypergraph.cc | 31 ++++++++++--------------------- fast/semiring.hh | 3 +-- 5 files changed, 17 insertions(+), 45 deletions(-) (limited to 'fast') diff --git a/fast/grammar.cc b/fast/grammar.cc index 946b062..9f26bd7 100644 --- a/fast/grammar.cc +++ b/fast/grammar.cc @@ -1,16 +1,7 @@ #include "grammar.hh" -namespace Grammar { - - -string -NT::s() -{ - ostringstream os; - os << "NT<" << this->symbol << "," << this->index << ">"; - return os.str(); -} +namespace G { } // namespace diff --git a/fast/grammar.hh b/fast/grammar.hh index c4ef3ad..d17a331 100644 --- a/fast/grammar.hh +++ b/fast/grammar.hh @@ -1,30 +1,23 @@ #pragma once #include -#include using namespace std; -namespace Grammar { +namespace G { -class NT { - public: - string symbol; - unsigned int index; - - string s(); +struct NT { + string symbol; + unsigned int index; }; class T { - public: - string word; + string word; }; class Rule { - public: }; - } // namespace diff --git a/fast/grammar.o b/fast/grammar.o index 9582624..705aed9 100644 Binary files a/fast/grammar.o and b/fast/grammar.o differ diff --git a/fast/hypergraph.cc b/fast/hypergraph.cc index a01fb3e..d24713e 100644 --- a/fast/hypergraph.cc +++ b/fast/hypergraph.cc @@ -29,7 +29,7 @@ std::ostream& operator<<(std::ostream& os, const Edge& e) { ostringstream _; - for (auto it = e.tails.begin(); it != e.tails.end(); ++it) { + for (auto it = e.tails.begin(); it != e.tails.end(); it++) { _ << (**it).id; if (*it != e.tails.back()) _ << ","; } os << \ @@ -50,16 +50,16 @@ operator<<(std::ostream& os, const Edge& e) void reset(list nodes, vector edges) { - for (auto it = nodes.begin(); it != nodes.end(); ++it) + for (auto it = nodes.begin(); it != nodes.end(); it++) (**it).mark = 0; - for (auto it = edges.begin(); it != edges.end(); ++it) + for (auto it = edges.begin(); it != edges.end(); it++) (**it).mark = 0; } template void init(list& nodes, list::iterator root, Semiring& semiring) { - for (auto it = nodes.begin(); it != nodes.end(); ++it) + for (auto it = nodes.begin(); it != nodes.end(); it++) (**it).score = semiring.null; (**root).score = semiring.one; } @@ -76,7 +76,7 @@ topological_sort(list& nodes, list::iterator root) if ((**p).is_marked()) { cout << **p<< endl; // explore edges - for (auto e = (**p).outgoing.begin(); e!=(**p).outgoing.end(); ++e) { + for (auto e = (**p).outgoing.begin(); e!=(**p).outgoing.end(); e++) { (**e).mark++; cout << " " << **e << endl; if ((**e).is_marked()) { @@ -86,21 +86,10 @@ topological_sort(list& nodes, list::iterator root) } if ((**p).is_marked()) { nodes.splice(to, nodes, p); - to = next(p); + to++; p = to; } else { ++p; - /*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; @@ -116,10 +105,10 @@ viterbi(Hypergraph& hg) Hg::topological_sort(hg.nodes, root); Semiring::Viterbi semiring; Hg::init(hg.nodes, root, semiring); - for (auto n = hg.nodes.begin(); n != hg.nodes.end(); ++n) { - for (auto e = (**n).incoming.begin(); e != (**n).incoming.end(); ++e) { + for (auto n = hg.nodes.begin(); n != hg.nodes.end(); n++) { + for (auto e = (**n).incoming.begin(); e != (**n).incoming.end(); e++) { double s = semiring.one; - for (auto m = (**e).tails.begin(); m != (**e).tails.end(); ++m) { + for (auto m = (**e).tails.begin(); m != (**e).tails.end(); m++) { s = semiring.multiply(s, (**m).score); } (**n).score = semiring.add((**n).score, semiring.multiply(s, (**e).score)); @@ -161,7 +150,7 @@ read(Hypergraph& hg, string fn) 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) { + 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]); e->arity++; diff --git a/fast/semiring.hh b/fast/semiring.hh index 5874e88..3f4ac08 100644 --- a/fast/semiring.hh +++ b/fast/semiring.hh @@ -1,7 +1,7 @@ #pragma once -namespace Semiring { +namespace Semiring { template struct Viterbi { @@ -31,6 +31,5 @@ Viterbi::convert(T x) return (T)x; } - } // namespace -- cgit v1.2.3