00001 // -*- c++ -*- 00002 #pragma once 00003 00004 #include <vector> 00005 #include "util/exception.hh" 00006 #include <iostream> 00007 #include "Util.h" 00008 00009 namespace Moses 00010 { 00011 00012 class TranslationOption; 00013 00016 class TranslationOptionList 00017 { 00018 friend std::ostream& operator<<(std::ostream& out, const TranslationOptionList& coll); 00019 00020 protected: 00021 typedef std::vector<TranslationOption*> CollType; 00022 CollType m_coll; 00023 00024 public: 00025 typedef CollType::iterator iterator; 00026 typedef CollType::const_iterator const_iterator; 00027 const_iterator begin() const { 00028 return m_coll.begin(); 00029 } 00030 const_iterator end() const { 00031 return m_coll.end(); 00032 } 00033 iterator begin() { 00034 return m_coll.begin(); 00035 } 00036 iterator end() { 00037 return m_coll.end(); 00038 } 00039 00040 TranslationOptionList() { 00041 } 00042 TranslationOptionList(const TranslationOptionList ©); 00043 ~TranslationOptionList(); 00044 00045 void resize(size_t newSize) { 00046 m_coll.resize(newSize); 00047 } 00048 size_t size() const { 00049 return m_coll.size(); 00050 } 00051 00052 const TranslationOption *Get(size_t ind) const { 00053 return m_coll.at(ind); 00054 } 00055 00056 void Remove( size_t ind ) { 00057 UTIL_THROW_IF2(ind >= m_coll.size(), 00058 "Out of bound index " << ind); 00059 m_coll.erase( m_coll.begin()+ind ); 00060 } 00061 void Add(TranslationOption *transOpt) { 00062 UTIL_THROW_IF2(!transOpt, "Not a valid translation option!"); 00063 m_coll.push_back(transOpt); 00064 } 00065 00066 TO_STRING(); 00067 00068 size_t SelectNBest(size_t const N); 00069 size_t PruneByThreshold(float const th); 00070 00071 }; 00072 }