Node *Viterbi::buildAllLattice() { if (!buildBestLattice()) return 0; Node *prev = bosNode_; const size_t len = static_cast<size_t>(end_ - begin_); for (long pos = 0; pos <= static_cast<long>(len); ++pos) { for (Node *node = begin_node_list_[pos]; node; node = node->bnext) { prev->next = node; node->prev = prev; prev = node; for (Path *path = node->lpath; path; path = path->lnext) path->prob = std::exp(path->lnode->alpha - theta_ * path->cost + path->rnode->beta - Z_); } } return bosNode_; }
bool Viterbi::analyze(Lattice *lattice) const { if (!lattice || !lattice->sentence()) { return false; } if (!initPartial(lattice)) { return false; } if (lattice->has_request_type(MECAB_NBEST) || lattice->has_request_type(MECAB_MARGINAL_PROB)) { if (!viterbiWithAllPath(lattice)) { return false; } } else { if (!viterbi(lattice)) { return false; } } if (!forwardbackward(lattice)) { return false; } if (!buildBestLattice(lattice)) { return false; } if (!buildAllLattice(lattice)) { return false; } if (!initNBest(lattice)) { return false; } return true; }