diff options
author | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-22 05:12:27 +0000 |
---|---|---|
committer | redpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-22 05:12:27 +0000 |
commit | 0172721855098ca02b207231a654dffa5e4eb1c9 (patch) | |
tree | 8069c3a62e2d72bd64a2cdeee9724b2679c8a56b /decoder/lattice.h | |
parent | 37728b8be4d0b3df9da81fdda2198ff55b4b2d91 (diff) |
initial checkin
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@2 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/lattice.h')
-rw-r--r-- | decoder/lattice.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/decoder/lattice.h b/decoder/lattice.h new file mode 100644 index 00000000..ad4ca50d --- /dev/null +++ b/decoder/lattice.h @@ -0,0 +1,46 @@ +#ifndef __LATTICE_H_ +#define __LATTICE_H_ + +#include <string> +#include <vector> +#include "wordid.h" +#include "array2d.h" + +class Lattice; +struct LatticeTools { + static bool LooksLikePLF(const std::string &line); + static void ConvertTextToLattice(const std::string& text, Lattice* pl); + static void ConvertTextOrPLF(const std::string& text_or_plf, Lattice* pl); +}; + +struct LatticeArc { + WordID label; + double cost; + int dist2next; + LatticeArc() : label(), cost(), dist2next() {} + LatticeArc(WordID w, double c, int i) : label(w), cost(c), dist2next(i) {} +}; + +class Lattice : public std::vector<std::vector<LatticeArc> > { + friend void LatticeTools::ConvertTextOrPLF(const std::string& text_or_plf, Lattice* pl); + friend void LatticeTools::ConvertTextToLattice(const std::string& text, Lattice* pl); + public: + Lattice() : is_sentence_(false) {} + explicit Lattice(size_t t, const std::vector<LatticeArc>& v = std::vector<LatticeArc>()) : + std::vector<std::vector<LatticeArc> >(t, v), + is_sentence_(false) {} + int Distance(int from, int to) const { + if (dist_.empty()) + return (to - from); + return dist_(from, to); + } + // TODO this should actually be computed based on the contents + // of the lattice + bool IsSentence() const { return is_sentence_; } + private: + void ComputeDistances(); + Array2D<int> dist_; + bool is_sentence_; +}; + +#endif |