2011-07-19 01:44:27 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - statistical machine translation system
|
|
|
|
Copyright (C) 2006-2011 University of Edinburgh
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "DotChart.h"
|
2013-05-24 19:23:31 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionaryNodeMemory.h"
|
2011-07-19 01:44:27 +04:00
|
|
|
|
2011-11-18 16:07:41 +04:00
|
|
|
#include "util/check.hh"
|
2011-07-19 01:44:27 +04:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2012-06-29 02:29:46 +04:00
|
|
|
/** @todo what is this?
|
|
|
|
*/
|
2011-07-19 01:44:27 +04:00
|
|
|
class DottedRuleInMemory : public DottedRule
|
|
|
|
{
|
2013-05-29 21:16:15 +04:00
|
|
|
public:
|
2011-07-19 01:44:27 +04:00
|
|
|
// used only to init dot stack.
|
2013-05-24 19:33:30 +04:00
|
|
|
explicit DottedRuleInMemory(const PhraseDictionaryNodeMemory &node)
|
2013-05-29 21:16:15 +04:00
|
|
|
: DottedRule()
|
|
|
|
, m_node(node) {}
|
2011-07-19 01:44:27 +04:00
|
|
|
|
2013-05-24 19:33:30 +04:00
|
|
|
DottedRuleInMemory(const PhraseDictionaryNodeMemory &node,
|
2011-07-19 01:44:27 +04:00
|
|
|
const ChartCellLabel &cellLabel,
|
|
|
|
const DottedRuleInMemory &prev)
|
2013-05-29 21:16:15 +04:00
|
|
|
: DottedRule(cellLabel, prev)
|
|
|
|
, m_node(node) {}
|
2011-07-19 01:44:27 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const PhraseDictionaryNodeMemory &GetLastNode() const {
|
|
|
|
return m_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-24 19:33:30 +04:00
|
|
|
const PhraseDictionaryNodeMemory &m_node;
|
2011-07-19 01:44:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<const DottedRuleInMemory*> DottedRuleList;
|
|
|
|
|
|
|
|
// Collection of all in-memory DottedRules that share a common start point,
|
|
|
|
// grouped by end point. Additionally, maintains a list of all
|
|
|
|
// DottedRules that could be expanded further, i.e. for which the
|
2013-05-24 19:33:30 +04:00
|
|
|
// corresponding PhraseDictionaryNodeMemory is not a leaf.
|
2011-07-19 01:44:27 +04:00
|
|
|
class DottedRuleColl
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
typedef std::vector<DottedRuleList> CollType;
|
|
|
|
CollType m_coll;
|
|
|
|
DottedRuleList m_expandableDottedRuleList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef CollType::iterator iterator;
|
|
|
|
typedef CollType::const_iterator const_iterator;
|
|
|
|
|
|
|
|
const_iterator begin() const {
|
|
|
|
return m_coll.begin();
|
|
|
|
}
|
|
|
|
const_iterator end() const {
|
|
|
|
return m_coll.end();
|
|
|
|
}
|
|
|
|
iterator begin() {
|
|
|
|
return m_coll.begin();
|
|
|
|
}
|
|
|
|
iterator end() {
|
|
|
|
return m_coll.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
DottedRuleColl(size_t size)
|
2013-06-10 21:11:55 +04:00
|
|
|
: m_coll(size) {
|
|
|
|
}
|
2011-07-19 01:44:27 +04:00
|
|
|
|
|
|
|
~DottedRuleColl();
|
|
|
|
|
|
|
|
const DottedRuleList &Get(size_t pos) const {
|
|
|
|
return m_coll[pos];
|
|
|
|
}
|
|
|
|
DottedRuleList &Get(size_t pos) {
|
|
|
|
return m_coll[pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(size_t pos, const DottedRuleInMemory *dottedRule) {
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(dottedRule);
|
2011-07-19 01:44:27 +04:00
|
|
|
m_coll[pos].push_back(dottedRule);
|
|
|
|
if (!dottedRule->GetLastNode().IsLeaf()) {
|
|
|
|
m_expandableDottedRuleList.push_back(dottedRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear(size_t pos) {
|
|
|
|
#ifdef USE_BOOST_POOL
|
|
|
|
m_coll[pos].clear();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const DottedRuleList &GetExpandableDottedRuleList() const {
|
|
|
|
return m_expandableDottedRuleList;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|