diff options
Diffstat (limited to 'phrase-extract/SyntaxNodeCollection.cpp')
-rw-r--r-- | phrase-extract/SyntaxNodeCollection.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/phrase-extract/SyntaxNodeCollection.cpp b/phrase-extract/SyntaxNodeCollection.cpp index 70f52317e..2a321f1e2 100644 --- a/phrase-extract/SyntaxNodeCollection.cpp +++ b/phrase-extract/SyntaxNodeCollection.cpp @@ -47,6 +47,8 @@ SyntaxNode *SyntaxNodeCollection::AddNode(int startPos, int endPos, SyntaxNode* newNode = new SyntaxNode(label, startPos, endPos); m_nodes.push_back( newNode ); m_index[ startPos ][ endPos ].push_back( newNode ); + m_endPositionsIndex[ endPos ].push_back( newNode ); + m_startPositionsIndex[ startPos ].push_back( newNode ); // TODO: may not need this: access m_index by startPos and iterate over its InnerNodeIndex (= end positions)? m_numWords = std::max(endPos+1, m_numWords); return newNode; } @@ -70,6 +72,36 @@ const std::vector< SyntaxNode* >& SyntaxNodeCollection::GetNodes( return endIndex->second; } +bool SyntaxNodeCollection::HasNodeStartingAtPosition( int startPos ) const +{ + return GetNodesByStartPosition(startPos).size() > 0; +} + +const std::vector< SyntaxNode* >& SyntaxNodeCollection::GetNodesByStartPosition( + int startPos ) const +{ + InnerNodeIndex::const_iterator startIndex = m_startPositionsIndex.find( startPos ); + if (startIndex == m_startPositionsIndex.end() ) + return m_emptyNode; + + return startIndex->second; +} + +bool SyntaxNodeCollection::HasNodeEndingAtPosition( int endPos ) const +{ + return GetNodesByEndPosition(endPos).size() > 0; +} + +const std::vector< SyntaxNode* >& SyntaxNodeCollection::GetNodesByEndPosition( + int endPos ) const +{ + InnerNodeIndex::const_iterator endIndex = m_endPositionsIndex.find( endPos ); + if (endIndex == m_endPositionsIndex.end() ) + return m_emptyNode; + + return endIndex->second; +} + std::auto_ptr<SyntaxTree> SyntaxNodeCollection::ExtractTree() { std::map<SyntaxNode *, SyntaxTree *> nodeToTree; |