|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
|
|
#include <map> |
|
|
#include <memory> |
|
|
#include <sstream> |
|
|
#include <string> |
|
|
#include <vector> |
|
|
|
|
|
#include "SyntaxNode.h" |
|
|
#include "SyntaxTree.h" |
|
|
|
|
|
namespace MosesTraining |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SyntaxNodeCollection |
|
|
{ |
|
|
public: |
|
|
SyntaxNodeCollection() : m_numWords(0) {} |
|
|
|
|
|
~SyntaxNodeCollection(); |
|
|
|
|
|
|
|
|
SyntaxNode *AddNode( int startPos, int endPos, const std::string &label ); |
|
|
|
|
|
|
|
|
bool HasNode( int startPos, int endPos ) const; |
|
|
|
|
|
|
|
|
const std::vector< SyntaxNode* >& GetNodes( int startPos, int endPos ) const; |
|
|
|
|
|
bool HasNodeStartingAtPosition( int startPos ) const; |
|
|
const std::vector< SyntaxNode* >& GetNodesByStartPosition( int startPos ) const; |
|
|
bool HasNodeEndingAtPosition( int endPos ) const; |
|
|
const std::vector< SyntaxNode* >& GetNodesByEndPosition( int endPos ) const; |
|
|
|
|
|
|
|
|
const std::vector< SyntaxNode* >& GetAllNodes() { |
|
|
return m_nodes; |
|
|
}; |
|
|
|
|
|
|
|
|
std::size_t GetNumWords() const { |
|
|
return m_numWords; |
|
|
} |
|
|
|
|
|
|
|
|
void Clear(); |
|
|
|
|
|
|
|
|
std::auto_ptr<SyntaxTree> ExtractTree(); |
|
|
|
|
|
private: |
|
|
typedef std::map< int, std::vector< SyntaxNode* > > InnerNodeIndex; |
|
|
typedef std::map< int, InnerNodeIndex > NodeIndex; |
|
|
|
|
|
|
|
|
SyntaxNodeCollection(const SyntaxNodeCollection &); |
|
|
SyntaxNodeCollection &operator=(const SyntaxNodeCollection &); |
|
|
|
|
|
std::vector< SyntaxNode* > m_nodes; |
|
|
NodeIndex m_index; |
|
|
int m_numWords; |
|
|
std::vector< SyntaxNode* > m_emptyNode; |
|
|
|
|
|
InnerNodeIndex m_endPositionsIndex; |
|
|
InnerNodeIndex m_startPositionsIndex; |
|
|
}; |
|
|
|
|
|
} |
|
|
|