#pragma once #include "Phrase.h" #include "Word.h" #include "SCFG/Word.h" namespace Moses2 { template class SubPhrase: public Phrase { friend std::ostream& operator<<(std::ostream &, const SubPhrase &); public: SubPhrase(const Phrase &origPhrase, size_t start, size_t size) :m_origPhrase(&origPhrase) ,m_start(start) ,m_size(size) {} virtual const WORD& operator[](size_t pos) const { return (*m_origPhrase)[pos + m_start]; } virtual size_t GetSize() const { return m_size; } SubPhrase GetSubPhrase(size_t start, size_t size) const { SubPhrase ret(*m_origPhrase, m_start + start, m_size); return ret; } protected: const Phrase *m_origPhrase; size_t m_start, m_size; }; /////////////////////////////////////////////////////// inline std::ostream& operator<<(std::ostream &out, const SubPhrase &obj) { if (obj.GetSize()) { out << obj[0]; for (size_t i = 1; i < obj.GetSize(); ++i) { const Word &word = obj[i]; out << " " << word; } } return out; } inline std::ostream& operator<<(std::ostream &out, const SubPhrase &obj) { if (obj.GetSize()) { out << obj[0]; for (size_t i = 1; i < obj.GetSize(); ++i) { const SCFG::Word &word = obj[i]; out << " " << word; } } return out; } }