mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-05 02:22:21 +03:00
templatize SubPhrase class
This commit is contained in:
parent
5ed6fe1434
commit
d06bdecbd3
@ -11,28 +11,7 @@ using namespace std;
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
const Word &SubPhrase::operator[](size_t pos) const
|
||||
{
|
||||
return (*m_origPhrase)[pos + m_start];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SubPhrase SubPhrase::GetSubPhrase(size_t start, size_t size) const
|
||||
{
|
||||
SubPhrase ret(*m_origPhrase, m_start + start, m_size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,19 +14,35 @@ public:
|
||||
,m_size(size)
|
||||
{}
|
||||
|
||||
virtual const Word& operator[](size_t pos) const;
|
||||
virtual const Word& operator[](size_t pos) const
|
||||
{ return (*m_origPhrase)[pos + m_start]; }
|
||||
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
{ return m_size; }
|
||||
|
||||
SubPhrase GetSubPhrase(size_t start, size_t size) const;
|
||||
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;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user