00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include "ChartCellLabel.h"
00023 #include "NonTerminal.h"
00024
00025 #include <boost/functional/hash.hpp>
00026 #include <boost/unordered_map.hpp>
00027 #include <boost/version.hpp>
00028
00029 namespace Moses
00030 {
00031
00032 class ChartHypothesisCollection;
00033
00036 class ChartCellLabelSet
00037 {
00038 private:
00039 #if defined(BOOST_VERSION) && (BOOST_VERSION >= 104200)
00040 typedef boost::unordered_map<Word, ChartCellLabel,
00041 NonTerminalHasher, NonTerminalEqualityPred
00042 > MapType;
00043 #else
00044 typedef std::map<Word, ChartCellLabel> MapType;
00045 #endif
00046
00047 public:
00048 typedef MapType::const_iterator const_iterator;
00049 typedef MapType::iterator iterator;
00050
00051 ChartCellLabelSet(const WordsRange &coverage) : m_coverage(coverage) {}
00052
00053 const_iterator begin() const { return m_map.begin(); }
00054 const_iterator end() const { return m_map.end(); }
00055
00056 iterator mutable_begin() { return m_map.begin(); }
00057 iterator mutable_end() { return m_map.end(); }
00058
00059 void AddWord(const Word &w)
00060 {
00061 m_map.insert(std::make_pair(w, ChartCellLabel(m_coverage, w)));
00062 }
00063
00064
00065 void AddConstituent(const Word &w, const HypoList *stack)
00066 {
00067 ChartCellLabel::Stack s;
00068 s.cube = stack;
00069 m_map.insert(std::make_pair(w, ChartCellLabel(m_coverage, w, s)));
00070 }
00071
00072 bool Empty() const { return m_map.empty(); }
00073
00074 size_t GetSize() const { return m_map.size(); }
00075
00076 const ChartCellLabel *Find(const Word &w) const
00077 {
00078 MapType::const_iterator p = m_map.find(w);
00079 return p == m_map.end() ? 0 : &(p->second);
00080 }
00081
00082 ChartCellLabel::Stack &FindOrInsert(const Word &w) {
00083 return m_map.insert(std::make_pair(w, ChartCellLabel(m_coverage, w))).first->second.MutableStack();
00084 }
00085
00086 private:
00087 const WordsRange &m_coverage;
00088 MapType m_map;
00089 };
00090
00091 }