| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #include "DotChart.h" |
| #include "moses/TranslationModel/PhraseDictionaryNodeMemory.h" |
|
|
| #include <vector> |
|
|
| namespace Moses |
| { |
|
|
| |
| |
| class DottedRuleInMemory : public DottedRule |
| { |
| public: |
| |
| explicit DottedRuleInMemory(const PhraseDictionaryNodeMemory &node) |
| : DottedRule() |
| , m_node(node) {} |
|
|
| DottedRuleInMemory(const PhraseDictionaryNodeMemory &node, |
| const ChartCellLabel &cellLabel, |
| const DottedRuleInMemory &prev) |
| : DottedRule(cellLabel, prev) |
| , m_node(node) {} |
|
|
| const PhraseDictionaryNodeMemory &GetLastNode() const { |
| return m_node; |
| } |
|
|
| private: |
| const PhraseDictionaryNodeMemory &m_node; |
| }; |
|
|
| typedef std::vector<const DottedRuleInMemory*> DottedRuleList; |
| typedef std::map<size_t, DottedRuleList> DottedRuleMap; |
|
|
| |
| |
| |
| |
| class DottedRuleColl |
| { |
| protected: |
| typedef std::vector<DottedRuleList> CollType; |
| CollType m_coll; |
| DottedRuleList m_expandableDottedRuleList; |
| DottedRuleMap m_expandableDottedRuleListTerminalsOnly; |
|
|
| public: |
| typedef CollType::iterator iterator; |
| typedef CollType::const_iterator const_iterator; |
|
|
| const_iterator begin() const { |
| return m_coll.begin(); |
| } |
| const_iterator end() const { |
| return m_coll.end(); |
| } |
| iterator begin() { |
| return m_coll.begin(); |
| } |
| iterator end() { |
| return m_coll.end(); |
| } |
|
|
| DottedRuleColl(size_t size) |
| : m_coll(size) { |
| } |
|
|
| ~DottedRuleColl(); |
|
|
| const DottedRuleList &Get(size_t pos) const { |
| return m_coll[pos]; |
| } |
| DottedRuleList &Get(size_t pos) { |
| return m_coll[pos]; |
| } |
|
|
| void Add(size_t pos, const DottedRuleInMemory *dottedRule) { |
| UTIL_THROW_IF2(dottedRule == NULL, "Dotted rule is null"); |
| m_coll[pos].push_back(dottedRule); |
| if (!dottedRule->GetLastNode().IsLeaf()) { |
| if (dottedRule->GetLastNode().GetNonTerminalMap().empty() && !dottedRule->IsRoot()) { |
| size_t startPos = dottedRule->GetWordsRange().GetEndPos() + 1; |
| m_expandableDottedRuleListTerminalsOnly[startPos].push_back(dottedRule); |
| } else { |
| m_expandableDottedRuleList.push_back(dottedRule); |
| } |
| } |
| } |
|
|
| void Clear(size_t pos) { |
| #ifdef USE_BOOST_POOL |
| m_coll[pos].clear(); |
| #endif |
| } |
|
|
| const DottedRuleList &GetExpandableDottedRuleList() const { |
| return m_expandableDottedRuleList; |
| } |
|
|
| DottedRuleMap &GetExpandableDottedRuleListTerminalsOnly() { |
| return m_expandableDottedRuleListTerminalsOnly; |
| } |
|
|
| }; |
|
|
| } |
|
|