2016-02-19 22:32:32 +03:00
|
|
|
#pragma once
|
|
|
|
#include "Phrase.h"
|
2016-04-27 19:32:22 +03:00
|
|
|
#include "Word.h"
|
|
|
|
#include "SCFG/Word.h"
|
2016-02-19 22:32:32 +03:00
|
|
|
|
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2016-04-27 00:18:19 +03:00
|
|
|
template<typename WORD>
|
|
|
|
class SubPhrase: public Phrase<WORD>
|
2016-02-19 22:32:32 +03:00
|
|
|
{
|
|
|
|
friend std::ostream& operator<<(std::ostream &, const SubPhrase &);
|
|
|
|
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]; }
|
2016-02-19 22:32:32 +03:00
|
|
|
|
|
|
|
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-02-19 22:32:32 +03:00
|
|
|
|
|
|
|
protected:
|
2016-04-27 00:18:19 +03:00
|
|
|
const Phrase<WORD> *m_origPhrase;
|
2016-03-04 02:56:36 +03:00
|
|
|
size_t m_start, m_size;
|
2016-02-19 22:32:32 +03:00
|
|
|
};
|
|
|
|
|
2016-04-26 23:44:15 +03:00
|
|
|
///////////////////////////////////////////////////////
|
2016-04-27 00:29:24 +03:00
|
|
|
inline std::ostream& operator<<(std::ostream &out, const SubPhrase<Moses2::Word> &obj)
|
2016-04-26 23:44:15 +03:00
|
|
|
{
|
|
|
|
if (obj.GetSize()) {
|
|
|
|
out << obj[0];
|
|
|
|
for (size_t i = 1; i < obj.GetSize(); ++i) {
|
|
|
|
const Word &word = obj[i];
|
|
|
|
out << " " << word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2016-04-27 19:32:22 +03:00
|
|
|
|
|
|
|
inline std::ostream& operator<<(std::ostream &out, const SubPhrase<SCFG::Word> &obj)
|
2016-04-27 00:18:19 +03:00
|
|
|
{
|
|
|
|
if (obj.GetSize()) {
|
|
|
|
out << obj[0];
|
|
|
|
for (size_t i = 1; i < obj.GetSize(); ++i) {
|
2016-04-27 19:32:22 +03:00
|
|
|
const SCFG::Word &word = obj[i];
|
2016-04-27 00:18:19 +03:00
|
|
|
out << " " << word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2016-04-27 19:32:22 +03:00
|
|
|
|
2016-02-19 22:32:32 +03:00
|
|
|
}
|
|
|
|
|