summaryrefslogtreecommitdiff
path: root/gi/pyp-topics/src/corpus.hh
diff options
context:
space:
mode:
authorphilblunsom@gmail.com <philblunsom@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-29 04:28:03 +0000
committerphilblunsom@gmail.com <philblunsom@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-29 04:28:03 +0000
commitc2d0652b798b2b23744b8c81f0f1abf8d7eeed2f (patch)
tree2c2d137dda292221c7c0e4a5f1d7204d5c6bc68f /gi/pyp-topics/src/corpus.hh
parentebd00f59aab18446051f9838d3d08427b242b435 (diff)
Debugged hierarchical backoff model.
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@48 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/pyp-topics/src/corpus.hh')
-rw-r--r--gi/pyp-topics/src/corpus.hh28
1 files changed, 25 insertions, 3 deletions
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<Term> 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<int>(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<int>(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(); }