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-09-23 21:39:32 +04:00
|
|
|
#include "ChartTranslationOption.h"
|
2011-03-11 19:28:36 +03:00
|
|
|
#include "CoveredChartSpan.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
namespace OnDiskPt
|
|
|
|
{
|
|
|
|
class PhraseNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
class DottedRuleOnDisk
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const DottedRuleOnDisk&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-02-24 16:14:42 +03:00
|
|
|
const OnDiskPt::PhraseNode &m_lastNode;
|
2011-03-11 19:28:36 +03:00
|
|
|
const CoveredChartSpan *m_coveredChartSpan; // usually contains something, unless its the init processed rule
|
2011-02-24 16:14:42 +03:00
|
|
|
mutable bool m_done;
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
// used only to init dot stack.
|
2011-03-11 16:08:43 +03:00
|
|
|
explicit DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode)
|
2011-02-24 16:14:42 +03:00
|
|
|
:m_lastNode(lastNode)
|
2011-03-11 19:28:36 +03:00
|
|
|
,m_coveredChartSpan(NULL)
|
2011-02-24 16:14:42 +03:00
|
|
|
,m_done(false)
|
|
|
|
{}
|
2011-03-11 19:28:36 +03:00
|
|
|
DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode, const CoveredChartSpan *coveredChartSpan)
|
2011-02-24 16:14:42 +03:00
|
|
|
:m_lastNode(lastNode)
|
2011-03-11 19:28:36 +03:00
|
|
|
,m_coveredChartSpan(coveredChartSpan)
|
2011-02-24 16:14:42 +03:00
|
|
|
,m_done(false)
|
|
|
|
{}
|
2011-03-11 16:08:43 +03:00
|
|
|
~DottedRuleOnDisk() {
|
2011-03-11 19:28:36 +03:00
|
|
|
delete m_coveredChartSpan;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
const OnDiskPt::PhraseNode &GetLastNode() const {
|
|
|
|
return m_lastNode;
|
|
|
|
}
|
2011-03-11 19:28:36 +03:00
|
|
|
const CoveredChartSpan *GetLastCoveredChartSpan() const {
|
|
|
|
return m_coveredChartSpan;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsCurrNonTerminal() const {
|
2011-03-11 19:28:36 +03:00
|
|
|
assert(m_coveredChartSpan);
|
|
|
|
return m_coveredChartSpan->IsNonTerminal();
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Done() const {
|
|
|
|
return m_done;
|
|
|
|
}
|
|
|
|
void Done(bool value) const {
|
|
|
|
m_done = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-11 16:08:43 +03:00
|
|
|
inline int Compare(const DottedRule &compare) const
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
if (m_lastNode < compare.m_lastNode)
|
|
|
|
return -1;
|
|
|
|
if (m_lastNode > compare.m_lastNode)
|
|
|
|
return 1;
|
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
return m_coveredChartSpan < compare.m_coveredChartSpan;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2011-03-11 16:08:43 +03:00
|
|
|
inline bool operator<(const DottedRule &compare) const
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
return Compare(compare) < 0;
|
|
|
|
}
|
|
|
|
*/
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
class DottedRuleCollOnDisk
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const DottedRuleCollOnDisk&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-03-11 16:08:43 +03:00
|
|
|
typedef std::vector<const DottedRuleOnDisk*> CollType;
|
2011-02-24 16:14:42 +03:00
|
|
|
CollType m_coll;
|
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();
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const DottedRuleOnDisk &Get(size_t ind) const {
|
2011-02-24 16:14:42 +03:00
|
|
|
return *m_coll[ind];
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
void Add(const DottedRuleOnDisk *dottedRule) {
|
|
|
|
m_coll.push_back(dottedRule);
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
void Delete(size_t ind) {
|
|
|
|
//delete m_coll[ind];
|
|
|
|
m_coll.erase(m_coll.begin() + ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetSize() const {
|
|
|
|
return m_coll.size();
|
|
|
|
}
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class SavedNodeOnDisk
|
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
const DottedRuleOnDisk *m_dottedRule;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
2011-03-11 16:08:43 +03:00
|
|
|
SavedNodeOnDisk(const DottedRuleOnDisk *dottedRule)
|
|
|
|
:m_dottedRule(dottedRule) {
|
|
|
|
assert(m_dottedRule);
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~SavedNodeOnDisk() {
|
2011-03-11 16:08:43 +03:00
|
|
|
delete m_dottedRule;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const DottedRuleOnDisk &GetDottedRule() const {
|
|
|
|
return *m_dottedRule;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
};
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
class DottedRuleStackOnDisk
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
// coll of coll of processed rules
|
2010-04-08 21:16:10 +04:00
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
typedef std::vector<SavedNodeOnDisk*> SavedNodeColl;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2011-03-11 16:08:43 +03:00
|
|
|
typedef std::vector<DottedRuleCollOnDisk*> CollType;
|
2011-02-24 16:14:42 +03:00
|
|
|
CollType m_coll;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
SavedNodeColl m_savedNode;
|
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();
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
DottedRuleStackOnDisk(size_t size);
|
|
|
|
~DottedRuleStackOnDisk();
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const DottedRuleCollOnDisk &Get(size_t pos) const {
|
2011-02-24 16:14:42 +03:00
|
|
|
return *m_coll[pos];
|
|
|
|
}
|
2011-03-11 16:08:43 +03:00
|
|
|
DottedRuleCollOnDisk &Get(size_t pos) {
|
2011-02-24 16:14:42 +03:00
|
|
|
return *m_coll[pos];
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const DottedRuleCollOnDisk &back() const {
|
2011-02-24 16:14:42 +03:00
|
|
|
return *m_coll.back();
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
void Add(size_t pos, const DottedRuleOnDisk *dottedRule) {
|
|
|
|
assert(dottedRule);
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
m_coll[pos]->Add(dottedRule);
|
|
|
|
m_savedNode.push_back(new SavedNodeOnDisk(dottedRule));
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const SavedNodeColl &GetSavedNodeColl() const {
|
|
|
|
return m_savedNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SortSavedNodes();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|