2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-12 14:15:49 +04:00
|
|
|
// vim:tabstop=2
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 Hieu Hoang
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
2010-04-08 21:16:10 +04:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-16 03:55:36 +04:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
2012-10-02 19:34:25 +04:00
|
|
|
#include "InputType.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "ChartCell.h"
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "WordsRange.h"
|
2014-06-16 03:55:36 +04:00
|
|
|
#include "InputPath.h"
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
class InputType;
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartManager;
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
class ChartCellCollectionBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template <class Factory> ChartCellCollectionBase(const InputType &input, const Factory &factory) :
|
|
|
|
m_cells(input.GetSize()) {
|
2014-06-16 03:55:36 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
size_t size = input.GetSize();
|
|
|
|
for (size_t startPos = 0; startPos < size; ++startPos) {
|
|
|
|
std::vector<ChartCellBase*> &inner = m_cells[startPos];
|
|
|
|
inner.reserve(size - startPos);
|
|
|
|
for (size_t endPos = startPos; endPos < size; ++endPos) {
|
|
|
|
inner.push_back(factory(startPos, endPos));
|
2012-10-02 19:34:25 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
/* Hack: ChartCellLabel shouldn't need to know its span, but the parser
|
|
|
|
* gets it from there :-(. The span is actually stored as a reference,
|
|
|
|
* which needs to point somewhere, so I have it refer to the ChartCell.
|
|
|
|
*/
|
2014-06-16 03:55:36 +04:00
|
|
|
const WordsRange &range = inner[0]->GetCoverage();
|
|
|
|
|
|
|
|
m_source.push_back(new ChartCellLabel(range, input.GetWord(startPos)));
|
2012-10-02 19:34:25 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
}
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
virtual ~ChartCellCollectionBase();
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2014-06-16 03:55:36 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const ChartCellBase &GetBase(const WordsRange &coverage) const {
|
|
|
|
return *m_cells[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()];
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
ChartCellBase &MutableBase(const WordsRange &coverage) {
|
|
|
|
return *m_cells[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()];
|
|
|
|
}
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2012-10-12 16:53:08 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const ChartCellLabel &GetSourceWordLabel(size_t at) const {
|
|
|
|
return m_source[at];
|
|
|
|
}
|
2012-10-12 16:53:08 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
private:
|
|
|
|
std::vector<std::vector<ChartCellBase*> > m_cells;
|
2012-10-02 19:34:25 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
boost::ptr_vector<ChartCellLabel> m_source;
|
2014-06-16 03:55:36 +04:00
|
|
|
|
2012-10-02 19:34:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Hold all the chart cells for 1 input sentence. A variable of this type is held by the ChartManager
|
|
|
|
*/
|
2013-05-29 21:16:15 +04:00
|
|
|
class ChartCellCollection : public ChartCellCollectionBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChartCellCollection(const InputType &input, ChartManager &manager);
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2012-07-02 23:01:07 +04:00
|
|
|
//! get a chart cell for a particular range
|
2011-03-11 19:28:36 +03:00
|
|
|
ChartCell &Get(const WordsRange &coverage) {
|
2012-10-02 19:34:25 +04:00
|
|
|
return static_cast<ChartCell&>(MutableBase(coverage));
|
2011-02-24 15:36:50 +03:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-07-02 23:01:07 +04:00
|
|
|
//! get a chart cell for a particular range
|
2011-03-11 19:28:36 +03:00
|
|
|
const ChartCell &Get(const WordsRange &coverage) const {
|
2012-10-02 19:34:25 +04:00
|
|
|
return static_cast<const ChartCell&>(GetBase(coverage));
|
2011-02-24 15:36:50 +03:00
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|