mosesdecoder/moses2/SubPhrase.h

55 lines
1.0 KiB
C
Raw Normal View History

#pragma once
2016-06-20 16:59:31 +03:00
#include <sstream>
#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)
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];
}
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
}
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
}
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
}