2016-02-19 22:32:32 +03:00
|
|
|
#pragma once
|
2016-06-20 16:59:31 +03:00
|
|
|
#include <sstream>
|
2016-02-19 22:32:32 +03:00
|
|
|
#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-06-11 00:03:11 +03:00
|
|
|
class System;
|
2016-02-19 22:32:32 +03:00
|
|
|
|
2016-04-27 00:18:19 +03:00
|
|
|
template<typename WORD>
|
|
|
|
class SubPhrase: public Phrase<WORD>
|
2016-02-19 22:32:32 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-04-27 00:18:19 +03:00
|
|
|
SubPhrase(const Phrase<WORD> &origPhrase, size_t start, size_t size)
|
2017-02-01 03:27:14 +03:00
|
|
|
:m_origPhrase(&origPhrase)
|
|
|
|
,m_start(start)
|
|
|
|
,m_size(size)
|
2016-04-26 11:23:18 +03:00
|
|
|
{}
|
|
|
|
|
2017-02-01 03:27:14 +03:00
|
|
|
virtual const WORD& operator[](size_t pos) const {
|
|
|
|
return (*m_origPhrase)[pos + m_start];
|
|
|
|
}
|
2016-02-19 22:32:32 +03:00
|
|
|
|
2017-02-01 03:27:14 +03:00
|
|
|
virtual size_t GetSize() const {
|
|
|
|
return m_size;
|
|
|
|
}
|
2016-04-26 23:44:15 +03:00
|
|
|
|
2017-02-01 03:27:14 +03:00
|
|
|
SubPhrase GetSubPhrase(size_t start, size_t size) const {
|
2016-10-03 14:03:18 +03:00
|
|
|
SubPhrase ret(*m_origPhrase, m_start + start, size);
|
2016-04-26 23:44:15 +03:00
|
|
|
return ret;
|
2016-03-31 23:00:16 +03:00
|
|
|
}
|
2016-02-19 22:32:32 +03:00
|
|
|
|
2017-02-01 03:27:14 +03:00
|
|
|
virtual std::string Debug(const System &system) const {
|
2016-06-20 16:59:31 +03:00
|
|
|
std::stringstream out;
|
2016-06-11 00:03:11 +03:00
|
|
|
if (GetSize()) {
|
2016-06-20 16:59:31 +03:00
|
|
|
out << (*this)[0].Debug(system);
|
2016-06-11 00:03:11 +03:00
|
|
|
for (size_t i = 1; i < GetSize(); ++i) {
|
|
|
|
const WORD &word = (*this)[i];
|
2016-06-20 16:59:31 +03:00
|
|
|
out << " " << word.Debug(system);
|
2016-06-11 00:03:11 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-18 00:54:32 +03:00
|
|
|
|
2016-06-20 16:59:31 +03:00
|
|
|
return out.str();
|
2016-06-11 00:03:11 +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-27 19:32:22 +03:00
|
|
|
|
2016-02-19 22:32:32 +03:00
|
|
|
}
|
|
|
|
|