summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-20 15:28:48 +0200
committerPatrick Simianer <p@simianer.de>2014-07-20 15:28:48 +0200
commita9e4e3e3224647c178cca1177f17e89fe8866d22 (patch)
treef7a1d3da91c489af2748235e614b2bb0014f6304
parent41046f6ac02a1d947d656d033ecb53a249e7cc7e (diff)
cleanup
-rw-r--r--fast/grammar.cc11
-rw-r--r--fast/grammar.hh17
-rw-r--r--fast/grammar.obin34344 -> 2928 bytes
-rw-r--r--fast/hypergraph.cc31
-rw-r--r--fast/semiring.hh3
5 files changed, 17 insertions, 45 deletions
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 <string>
-#include <sstream>
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
--- a/fast/grammar.o
+++ b/fast/grammar.o
Binary files 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<Node*> nodes, vector<Edge*> 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<typename Semiring> void
init(list<Node*>& nodes, list<Node*>::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<Node*>& nodes, list<Node*>::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<Node*>& nodes, list<Node*>::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<double> 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<typename T>
struct Viterbi {
@@ -31,6 +31,5 @@ Viterbi<T>::convert(T x)
return (T)x;
}
-
} // namespace