summaryrefslogtreecommitdiff
path: root/klm/search/rule.hh
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-09-11 14:30:16 +0100
committerKenneth Heafield <github@kheafield.com>2012-09-11 14:31:42 +0100
commit45c9efc7d558dbe160056f02e74df1fee5d2d0e5 (patch)
tree0c26a847b78b4c0d86507b21b7338beb98ff1e73 /klm/search/rule.hh
parent8882e9ebe158aef382bb5544559ef7f2a553db62 (diff)
Add search library to cdec (not used yet)
Diffstat (limited to 'klm/search/rule.hh')
-rw-r--r--klm/search/rule.hh60
1 files changed, 60 insertions, 0 deletions
diff --git a/klm/search/rule.hh b/klm/search/rule.hh
new file mode 100644
index 00000000..79192d40
--- /dev/null
+++ b/klm/search/rule.hh
@@ -0,0 +1,60 @@
+#ifndef SEARCH_RULE__
+#define SEARCH_RULE__
+
+#include "lm/left.hh"
+#include "search/arity.hh"
+#include "search/types.hh"
+#include "search/word.hh"
+
+#include <boost/array.hpp>
+
+#include <iosfwd>
+#include <vector>
+
+namespace search {
+
+template <class Model> class Context;
+
+class Rule {
+ public:
+ Rule() : arity_(0) {}
+
+ void AppendTerminal(Word w) { items_.push_back(w); }
+
+ void AppendNonTerminal() {
+ items_.resize(items_.size() + 1);
+ ++arity_;
+ }
+
+ template <class Model> void FinishedAdding(const Context<Model> &context, Score additive, bool prepend_bos);
+
+ Score Bound() const { return bound_; }
+
+ Score Additive() const { return additive_; }
+
+ unsigned int Arity() const { return arity_; }
+
+ const lm::ngram::ChartState &Lexical(unsigned int index) const {
+ return lexical_[index];
+ }
+
+ // For printing.
+ typedef const std::vector<Word> ItemsRet;
+ ItemsRet &Items() const { return items_; }
+
+ private:
+ Score bound_, additive_;
+
+ unsigned int arity_;
+
+ // TODO: pool?
+ std::vector<Word> items_;
+
+ std::vector<lm::ngram::ChartState> lexical_;
+};
+
+std::ostream &operator<<(std::ostream &o, const Rule &rule);
+
+} // namespace search
+
+#endif // SEARCH_RULE__