#ifndef moses_LVoc_h #define moses_LVoc_h #include #include #include #include #include typedef unsigned LabelId; extern const LabelId InvalidLabelId; extern const LabelId Epsilon; typedef std::vector IPhrase; /** class used in phrase-based binary phrase-table. * @todo vocab? * A = type of things to numberize, ie, std::string * B = map type to use, might consider using hash_map for better performance */ template > class LVoc { typedef A Key; typedef B M; typedef std::vector V; M m; V data; public: LVoc() {} bool isKnown(const Key& k) const { return m.find(k)!=m.end(); } LabelId index(const Key& k) const { typename M::const_iterator i=m.find(k); return i!=m.end()? i->second : InvalidLabelId; } LabelId add(const Key& k) { std::pair p =m.insert(std::make_pair(k,data.size())); if(p.second) data.push_back(k); assert(static_cast(p.first->second)second; } Key const& symbol(LabelId i) const { assert(static_cast(i)=0; --i) out<>i>>k) { if(i>=data.size()) data.resize(i+1); data[i]=k; m[k]=i; } } } }; #endif