mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
fix two bugs with relax-parse:
- size of sentence was not calculated correctly (instead, number of positions at which a subtree starts was used) - code entered an infinitive loop sometimes; added break condition
This commit is contained in:
parent
8a1e944bb4
commit
4e87a012d0
@ -50,6 +50,7 @@ SyntaxNode *SyntaxTree::AddNode( int startPos, int endPos, std::string label )
|
||||
SyntaxNode* newNode = new SyntaxNode( startPos, endPos, label );
|
||||
m_nodes.push_back( newNode );
|
||||
m_index[ startPos ][ endPos ].push_back( newNode );
|
||||
m_size = std::max(endPos+1, m_size);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
@ -57,11 +58,9 @@ ParentNodes SyntaxTree::Parse()
|
||||
{
|
||||
ParentNodes parents;
|
||||
|
||||
int size = m_index.size();
|
||||
|
||||
// looping through all spans of size >= 2
|
||||
for( int length=2; length<=size; length++ ) {
|
||||
for( int startPos = 0; startPos <= size-length; startPos++ ) {
|
||||
for( int length=2; length<=m_size; length++ ) {
|
||||
for( int startPos = 0; startPos <= m_size-length; startPos++ ) {
|
||||
if (HasNode( startPos, startPos+length-1 )) {
|
||||
// processing one (parent) span
|
||||
|
||||
@ -72,15 +71,18 @@ ParentNodes SyntaxTree::Parse()
|
||||
|
||||
int first = 1;
|
||||
int covered = 0;
|
||||
while( covered < length ) {
|
||||
int found_somehing = 1; // break loop if nothing found
|
||||
while( covered < length && found_somehing ) {
|
||||
// find largest covering subspan (child)
|
||||
// starting at last covered position
|
||||
found_somehing = 0;
|
||||
for( int midPos=length-first; midPos>covered; midPos-- ) {
|
||||
if( HasNode( startPos+covered, startPos+midPos-1 ) ) {
|
||||
covered = midPos;
|
||||
splitPoints.push_back( startPos+covered );
|
||||
// std::cerr << " " << ( startPos+covered );
|
||||
first = 0;
|
||||
found_somehing = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ protected:
|
||||
typedef std::map< int, SyntaxTreeIndex2 > SyntaxTreeIndex;
|
||||
typedef SyntaxTreeIndex::const_iterator SyntaxTreeIndexIterator;
|
||||
SyntaxTreeIndex m_index;
|
||||
int m_size;
|
||||
std::vector< SyntaxNode* > m_emptyNode;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const SyntaxTree&);
|
||||
@ -113,7 +114,7 @@ public:
|
||||
return m_nodes;
|
||||
};
|
||||
size_t GetNumWords() const {
|
||||
return m_index.size();
|
||||
return m_size;
|
||||
}
|
||||
void ConnectNodes();
|
||||
void Clear();
|
||||
|
Loading…
Reference in New Issue
Block a user