2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-08 21:16:10 +04:00
|
|
|
// vim:tabstop=2
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 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 <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <iterator>
|
2010-08-17 17:41:46 +04:00
|
|
|
#include <utility>
|
|
|
|
#include <ostream>
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "Word.h"
|
|
|
|
#include "TargetPhraseCollection.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2010-08-17 17:41:46 +04:00
|
|
|
class PhraseDictionarySCFG;
|
|
|
|
|
2010-08-17 15:01:03 +04:00
|
|
|
/** One node of the PhraseDictionarySCFG structure
|
2010-04-08 21:16:10 +04:00
|
|
|
*/
|
2010-08-17 15:01:03 +04:00
|
|
|
class PhraseDictionaryNodeSCFG
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2010-08-17 17:41:46 +04:00
|
|
|
typedef std::map<Word, PhraseDictionaryNodeSCFG> TerminalMap;
|
|
|
|
typedef std::pair<Word, Word> NonTerminalMapKey;
|
|
|
|
typedef std::map<NonTerminalMapKey, PhraseDictionaryNodeSCFG> NonTerminalMap;
|
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream&, const PhraseDictionarySCFG&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
// only these classes are allowed to instantiate this class
|
2010-07-18 02:29:06 +04:00
|
|
|
friend class PhraseDictionarySCFG;
|
|
|
|
friend class std::map<Word, PhraseDictionaryNodeSCFG>;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
2010-08-17 17:41:46 +04:00
|
|
|
TerminalMap m_sourceTermMap;
|
|
|
|
NonTerminalMap m_nonTermMap;
|
2010-04-08 21:16:10 +04:00
|
|
|
mutable TargetPhraseCollection *m_targetPhraseCollection;
|
|
|
|
|
2010-07-18 02:29:06 +04:00
|
|
|
PhraseDictionaryNodeSCFG()
|
2010-08-17 15:01:03 +04:00
|
|
|
:m_targetPhraseCollection(NULL)
|
2010-04-08 21:16:10 +04:00
|
|
|
{}
|
|
|
|
public:
|
2010-07-18 02:29:06 +04:00
|
|
|
virtual ~PhraseDictionaryNodeSCFG();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2010-09-10 19:19:25 +04:00
|
|
|
bool IsLeaf() const
|
|
|
|
{ return m_sourceTermMap.empty() && m_nonTermMap.empty(); }
|
|
|
|
|
2010-09-26 15:38:09 +04:00
|
|
|
void Prune(size_t tableLimit);
|
2010-08-17 17:41:46 +04:00
|
|
|
PhraseDictionaryNodeSCFG *GetOrCreateChild(const Word &sourceTerm);
|
|
|
|
PhraseDictionaryNodeSCFG *GetOrCreateChild(const Word &sourceNonTerm, const Word &targetNonTerm);
|
|
|
|
const PhraseDictionaryNodeSCFG *GetChild(const Word &sourceTerm) const;
|
|
|
|
const PhraseDictionaryNodeSCFG *GetChild(const Word &sourceNonTerm, const Word &targetNonTerm) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
const TargetPhraseCollection *GetTargetPhraseCollection() const
|
|
|
|
{ return m_targetPhraseCollection; }
|
|
|
|
TargetPhraseCollection &GetOrCreateTargetPhraseCollection()
|
|
|
|
{
|
|
|
|
if (m_targetPhraseCollection == NULL)
|
|
|
|
m_targetPhraseCollection = new TargetPhraseCollection();
|
|
|
|
return *m_targetPhraseCollection;
|
|
|
|
}
|
|
|
|
|
|
|
|
TO_STRING();
|
|
|
|
};
|
|
|
|
|
2010-08-17 15:01:03 +04:00
|
|
|
std::ostream& operator<<(std::ostream&, const PhraseDictionaryNodeSCFG&);
|
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
}
|