From 3418c41232756adb9bf29036980e55a3ce0140e0 Mon Sep 17 00:00:00 2001 From: "philblunsom@gmail.com" Date: Tue, 29 Jun 2010 04:28:03 +0000 Subject: Debugged hierarchical backoff model. git-svn-id: https://ws10smt.googlecode.com/svn/trunk@48 ec762483-ff6d-05da-a07a-a48fb63a330f --- gi/pyp-topics/src/corpus.hh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'gi/pyp-topics/src/corpus.hh') diff --git a/gi/pyp-topics/src/corpus.hh b/gi/pyp-topics/src/corpus.hh index 243f7e2c..c2f37130 100644 --- a/gi/pyp-topics/src/corpus.hh +++ b/gi/pyp-topics/src/corpus.hh @@ -22,7 +22,7 @@ public: public: Corpus(); - ~Corpus() {} + virtual ~Corpus() {} unsigned read(const std::string &filename); @@ -71,9 +71,10 @@ class TermBackoff { public: typedef std::vector dictionary_type; typedef dictionary_type::const_iterator const_iterator; + const static int NullBackoff=-1; public: - TermBackoff() : m_backoff_order(-1) {} + TermBackoff() { order(1); } ~TermBackoff() {} void read(const std::string &filename); @@ -86,12 +87,33 @@ public: return m_dict[t]; } + Term& operator[](const Term& t) { + if (t >= static_cast(m_dict.size())) + m_dict.resize(t+1, -1); + return m_dict[t]; + } + + bool has_backoff(const Term& t) { + return t >= 0 && t < static_cast(m_dict.size()) && m_dict[t] >= 0; + } + int order() const { return m_backoff_order; } + void order(int o) { + if (o >= (int)m_terms_at_order.size()) + m_terms_at_order.resize(o, 0); + m_backoff_order = o; + } + // int levels() const { return m_terms_at_order.size(); } bool is_null(const Term& term) const { return term < 0; } int terms_at_level(int level) const { assert (level < (int)m_terms_at_order.size()); - return m_terms_at_order[level]; + return m_terms_at_order.at(level); + } + + int& terms_at_level(int level) { + assert (level < (int)m_terms_at_order.size()); + return m_terms_at_order.at(level); } int size() const { return m_dict.size(); } -- cgit v1.2.3