diff options
| author | Patrick Simianer <patrick@lilt.com> | 2026-02-26 19:31:35 +0100 |
|---|---|---|
| committer | Patrick Simianer <patrick@lilt.com> | 2026-02-26 19:31:35 +0100 |
| commit | a1c5862a46b524d3e11a87c5a732c0c257aefe20 (patch) | |
| tree | db49b2e5f7bbb580217996810f9c26dcc59d2d58 /src | |
| parent | 44f225d0642d2ecf13f533f68b9ae12d849809ea (diff) | |
Fix C++ ow binary to produce translations
- Node::mark and Node::score uninitialized, causing segfaults in
topological_sort — add default initializers (0, 0.0)
- odenwald.cc called incomplete sv_path() + exit(1) instead of
viterbi_path()
- viterbi_path: add reset() before topological_sort, initialize
best_edge to nullptr
- derive: off-by-one in NT order indexing — start j at 1 and
use order[j]-1 (1-indexed alignment map)
- read: ifs.readsome() returns 0 on macOS — use ifs.read() +
ifs.gcount()
- manual() signature: add missing Vocabulary parameter
- Remove gperftools/tcmalloc dependency from Makefile
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/hypergraph.cc | 11 | ||||
| -rw-r--r-- | src/hypergraph.hh | 6 | ||||
| -rw-r--r-- | src/odenwald.cc | 3 |
3 files changed, 10 insertions, 10 deletions
diff --git a/src/hypergraph.cc b/src/hypergraph.cc index 6ec8441..0c36abe 100644 --- a/src/hypergraph.cc +++ b/src/hypergraph.cc @@ -73,13 +73,13 @@ viterbi_path(Hypergraph& hg, Path& p) [](Node* n) { return n->incoming.size() == 0; }); //list<Node*>::iterator root = hg.nodes.begin(); + Hg::reset(hg.nodes, hg.edges); Hg::topological_sort(hg.nodes, root); - // ^^^ FIXME do I need to do this when reading from file? Semiring::Viterbi<score_t> semiring; Hg::init(hg.nodes, root, semiring); for (auto n: hg.nodes) { - Edge* best_edge; + Edge* best_edge = nullptr; bool best = false; for (auto e: n->incoming) { score_t s = semiring.one; @@ -135,10 +135,10 @@ derive(const Path& p, const Node* cur, vector<string>& carry) } } // FIXME this is probably not so good - unsigned j = 0; + unsigned j = 1; for (auto it: next->rule->target) { if (it->type() == G::NON_TERMINAL) { - derive(p, next->tails[next->rule->order[j]], carry); + derive(p, next->tails[next->rule->order[j]-1], carry); j++; } else { carry.push_back(it->symbol()); @@ -156,7 +156,8 @@ read(Hypergraph& hg, vector<G::Rule*>& rules, G::Vocabulary& vocab, const string msgpack::unpacker pac; while(true) { pac.reserve_buffer(32*1024); - size_t bytes = ifs.readsome(pac.buffer(), pac.buffer_capacity()); + ifs.read(pac.buffer(), pac.buffer_capacity()); + size_t bytes = ifs.gcount(); pac.buffer_consumed(bytes); msgpack::unpacked result; while(pac.next(&result)) { diff --git a/src/hypergraph.hh b/src/hypergraph.hh index 7a268c3..d782c9e 100644 --- a/src/hypergraph.hh +++ b/src/hypergraph.hh @@ -48,10 +48,10 @@ struct Node { string symbol; short left; short right; - score_t score; + score_t score = 0.0; vector<Edge*> incoming; vector<Edge*> outgoing; - unsigned int mark; + unsigned int mark = 0; inline bool is_marked() { return mark >= incoming.size(); }; friend ostream& operator<<(ostream& os, const Node& n); @@ -98,7 +98,7 @@ void write(Hypergraph& hg, vector<G::Rule*>& rules, const string& fn); // FIXME void -manual(Hypergraph& hg, vector<G::Rule*>& rules); +manual(Hypergraph& hg, vector<G::Rule*>& rules, G::Vocabulary& vocab); } // namespace diff --git a/src/odenwald.cc b/src/odenwald.cc index a520d0b..bdf21f8 100644 --- a/src/odenwald.cc +++ b/src/odenwald.cc @@ -20,8 +20,7 @@ main(int argc, char** argv) // viterbi clock_t begin_viterbi = clock(); Hg::Path p; - Hg::sv_path(hg, p); - exit(1); + Hg::viterbi_path(hg, p); vector<string> s; Hg::derive(p, p.back()->head, s); for (auto it: s) |
