00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <map>
00023 #include <memory>
00024 #include <sstream>
00025 #include <string>
00026 #include <vector>
00027
00028 #include "SyntaxNode.h"
00029 #include "SyntaxTree.h"
00030
00031 namespace MosesTraining
00032 {
00033
00037 class SyntaxNodeCollection
00038 {
00039 public:
00040 SyntaxNodeCollection() : m_numWords(0) {}
00041
00042 ~SyntaxNodeCollection();
00043
00045 SyntaxNode *AddNode( int startPos, int endPos, const std::string &label );
00046
00048 bool HasNode( int startPos, int endPos ) const;
00049
00051 const std::vector< SyntaxNode* >& GetNodes( int startPos, int endPos ) const;
00052
00053 bool HasNodeStartingAtPosition( int startPos ) const;
00054 const std::vector< SyntaxNode* >& GetNodesByStartPosition( int startPos ) const;
00055 bool HasNodeEndingAtPosition( int endPos ) const;
00056 const std::vector< SyntaxNode* >& GetNodesByEndPosition( int endPos ) const;
00057
00059 const std::vector< SyntaxNode* >& GetAllNodes() {
00060 return m_nodes;
00061 };
00062
00064 std::size_t GetNumWords() const {
00065 return m_numWords;
00066 }
00067
00069 void Clear();
00070
00072 std::auto_ptr<SyntaxTree> ExtractTree();
00073
00074 private:
00075 typedef std::map< int, std::vector< SyntaxNode* > > InnerNodeIndex;
00076 typedef std::map< int, InnerNodeIndex > NodeIndex;
00077
00078
00079 SyntaxNodeCollection(const SyntaxNodeCollection &);
00080 SyntaxNodeCollection &operator=(const SyntaxNodeCollection &);
00081
00082 std::vector< SyntaxNode* > m_nodes;
00083 NodeIndex m_index;
00084 int m_numWords;
00085 std::vector< SyntaxNode* > m_emptyNode;
00086
00087 InnerNodeIndex m_endPositionsIndex;
00088 InnerNodeIndex m_startPositionsIndex;
00089 };
00090
00091 }