2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-12 14:15:49 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 Hieu Hoang
|
2011-02-24 16:14:42 +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 16:14:42 +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 16:14:42 +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
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2010-08-17 15:01:03 +04:00
|
|
|
#include "PhraseDictionaryNodeSCFG.h"
|
2010-09-23 21:39:32 +04:00
|
|
|
#include "ChartTranslationOption.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "WordConsumed.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
class ProcessedRule
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const ProcessedRule&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-02-24 16:14:42 +03:00
|
|
|
const PhraseDictionaryNodeSCFG &m_lastNode;
|
|
|
|
const WordConsumed *m_wordsConsumed; // usually contains something, unless its the init processed rule
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
// used only to init dot stack.
|
|
|
|
explicit ProcessedRule(const PhraseDictionaryNodeSCFG &lastNode)
|
|
|
|
:m_lastNode(lastNode)
|
|
|
|
,m_wordsConsumed(NULL)
|
|
|
|
{}
|
|
|
|
ProcessedRule(const PhraseDictionaryNodeSCFG &lastNode, const WordConsumed *wordsConsumed)
|
|
|
|
:m_lastNode(lastNode)
|
|
|
|
,m_wordsConsumed(wordsConsumed)
|
|
|
|
{}
|
|
|
|
~ProcessedRule() {
|
2011-02-07 18:43:19 +03:00
|
|
|
#ifdef USE_BOOST_POOL
|
|
|
|
// Do nothing. WordConsumed objects are stored in object pools owned by
|
|
|
|
// the sentence-specific ChartRuleLookupManagers.
|
|
|
|
#else
|
2011-02-24 16:14:42 +03:00
|
|
|
delete m_wordsConsumed;
|
2011-02-07 18:43:19 +03:00
|
|
|
#endif
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
const PhraseDictionaryNodeSCFG &GetLastNode() const {
|
|
|
|
return m_lastNode;
|
|
|
|
}
|
|
|
|
const WordConsumed *GetLastWordConsumed() const {
|
|
|
|
return m_wordsConsumed;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
2010-09-10 19:19:25 +04:00
|
|
|
typedef std::vector<const ProcessedRule*> ProcessedRuleList;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2010-09-10 19:19:25 +04:00
|
|
|
// Collection of all ProcessedRules that share a common start point,
|
|
|
|
// grouped by end point. Additionally, maintains a list of all
|
|
|
|
// ProcessedRules that could be expanded further, i.e. for which the
|
|
|
|
// corresponding PhraseDictionaryNodeSCFG is not a leaf.
|
|
|
|
class ProcessedRuleColl
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
|
|
|
protected:
|
2011-02-24 16:14:42 +03:00
|
|
|
typedef std::vector<ProcessedRuleList> CollType;
|
|
|
|
CollType m_coll;
|
|
|
|
ProcessedRuleList m_runningNodes;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessedRuleColl(size_t size)
|
|
|
|
: m_coll(size)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~ProcessedRuleColl();
|
|
|
|
|
|
|
|
const ProcessedRuleList &Get(size_t pos) const {
|
|
|
|
return m_coll[pos];
|
|
|
|
}
|
|
|
|
ProcessedRuleList &Get(size_t pos) {
|
|
|
|
return m_coll[pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(size_t pos, const ProcessedRule *processedRule) {
|
|
|
|
assert(processedRule);
|
|
|
|
m_coll[pos].push_back(processedRule);
|
|
|
|
if (!processedRule->GetLastNode().IsLeaf()) {
|
|
|
|
m_runningNodes.push_back(processedRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProcessedRuleList &GetRunningNodes() const {
|
|
|
|
return m_runningNodes;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|