mosesdecoder/contrib/other-builds/moses2/SubPhrase.h

54 lines
1011 B
C
Raw Normal View History

#pragma once
#include "Phrase.h"
2016-04-27 19:32:22 +03:00
#include "Word.h"
#include "SCFG/Word.h"
namespace Moses2
{
2016-06-11 00:03:11 +03:00
class System;
2016-04-27 00:18:19 +03:00
template<typename WORD>
class SubPhrase: public Phrase<WORD>
{
public:
2016-04-27 00:18:19 +03:00
SubPhrase(const Phrase<WORD> &origPhrase, size_t start, size_t size)
2016-04-26 11:23:18 +03:00
:m_origPhrase(&origPhrase)
,m_start(start)
,m_size(size)
{}
2016-04-27 00:18:19 +03:00
virtual const WORD& operator[](size_t pos) const
2016-04-26 23:44:15 +03:00
{ return (*m_origPhrase)[pos + m_start]; }
virtual size_t GetSize() const
2016-04-26 23:44:15 +03:00
{ return m_size; }
SubPhrase GetSubPhrase(size_t start, size_t size) const
2016-03-31 23:00:16 +03:00
{
2016-04-26 23:44:15 +03:00
SubPhrase ret(*m_origPhrase, m_start + start, m_size);
return ret;
2016-03-31 23:00:16 +03:00
}
2016-06-18 00:54:32 +03:00
virtual std::ostream &Debug(std::ostream &out, const System &system) const
2016-06-11 00:03:11 +03:00
{
if (GetSize()) {
2016-06-11 04:07:43 +03:00
(*this)[0].Debug(out, system);
2016-06-11 00:03:11 +03:00
for (size_t i = 1; i < GetSize(); ++i) {
const WORD &word = (*this)[i];
out << " ";
2016-06-11 04:07:43 +03:00
word.Debug(out, system);
2016-06-11 00:03:11 +03:00
}
}
2016-06-18 00:54:32 +03:00
return out;
2016-06-11 00:03:11 +03:00
}
protected:
2016-04-27 00:18:19 +03:00
const Phrase<WORD> *m_origPhrase;
size_t m_start, m_size;
};
2016-04-27 19:32:22 +03:00
}