2010-04-12 19:22:50 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2009 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
|
|
|
|
***********************************************************************/
|
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
#pragma once
|
2015-05-29 20:46:02 +03:00
|
|
|
|
2010-04-12 19:22:50 +04:00
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
2015-05-29 20:46:02 +03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-04-12 19:22:50 +04:00
|
|
|
|
2015-06-01 18:54:12 +03:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2015-05-29 22:57:25 +03:00
|
|
|
#include "SyntaxNode.h"
|
2015-06-01 18:54:12 +03:00
|
|
|
#include "SyntaxTree.h"
|
2012-06-30 18:43:47 +04:00
|
|
|
|
2015-05-29 22:57:25 +03:00
|
|
|
namespace MosesTraining
|
2011-02-24 16:57:11 +03:00
|
|
|
{
|
2010-04-12 19:22:50 +04:00
|
|
|
|
|
|
|
typedef std::vector< int > SplitPoints;
|
|
|
|
typedef std::vector< SplitPoints > ParentNodes;
|
|
|
|
|
2015-05-29 20:46:02 +03:00
|
|
|
class SyntaxNodeCollection
|
2011-02-24 16:57:11 +03:00
|
|
|
{
|
2010-04-12 19:22:50 +04:00
|
|
|
protected:
|
2011-02-24 16:57:11 +03:00
|
|
|
std::vector< SyntaxNode* > m_nodes;
|
|
|
|
SyntaxNode* m_top;
|
2010-04-12 19:22:50 +04:00
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
typedef std::map< int, std::vector< SyntaxNode* > > SyntaxTreeIndex2;
|
|
|
|
typedef SyntaxTreeIndex2::const_iterator SyntaxTreeIndexIterator2;
|
|
|
|
typedef std::map< int, SyntaxTreeIndex2 > SyntaxTreeIndex;
|
|
|
|
typedef SyntaxTreeIndex::const_iterator SyntaxTreeIndexIterator;
|
|
|
|
SyntaxTreeIndex m_index;
|
2013-04-25 19:27:50 +04:00
|
|
|
int m_size;
|
2011-02-24 16:57:11 +03:00
|
|
|
std::vector< SyntaxNode* > m_emptyNode;
|
2010-04-12 19:22:50 +04:00
|
|
|
|
|
|
|
public:
|
2015-05-29 20:46:02 +03:00
|
|
|
SyntaxNodeCollection()
|
2015-01-14 14:07:42 +03:00
|
|
|
: m_top(0) // m_top doesn't get set unless ConnectNodes is called.
|
|
|
|
, m_size(0) {}
|
2014-12-07 15:56:41 +03:00
|
|
|
|
2015-05-29 20:46:02 +03:00
|
|
|
~SyntaxNodeCollection();
|
2011-02-24 16:57:11 +03:00
|
|
|
|
2015-05-29 22:57:25 +03:00
|
|
|
SyntaxNode *AddNode( int startPos, int endPos, const std::string &label );
|
2012-05-25 20:29:47 +04:00
|
|
|
|
2012-04-23 17:24:54 +04:00
|
|
|
SyntaxNode *GetTop() {
|
|
|
|
return m_top;
|
|
|
|
}
|
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
ParentNodes Parse();
|
|
|
|
bool HasNode( int startPos, int endPos ) const;
|
|
|
|
const std::vector< SyntaxNode* >& GetNodes( int startPos, int endPos ) const;
|
|
|
|
const std::vector< SyntaxNode* >& GetAllNodes() {
|
|
|
|
return m_nodes;
|
|
|
|
};
|
|
|
|
size_t GetNumWords() const {
|
2013-04-25 19:27:50 +04:00
|
|
|
return m_size;
|
2011-02-24 16:57:11 +03:00
|
|
|
}
|
2012-04-23 17:24:54 +04:00
|
|
|
void ConnectNodes();
|
|
|
|
void Clear();
|
2015-06-01 18:54:12 +03:00
|
|
|
|
|
|
|
std::auto_ptr<SyntaxTree> ExtractTree();
|
|
|
|
//boost::shared_ptr<SyntaxTree> ExtractTree();
|
2010-04-12 19:22:50 +04:00
|
|
|
};
|
|
|
|
|
2015-05-29 20:46:02 +03:00
|
|
|
} // namespace MosesTraining
|