src/Generic/names/IdFDecoder.cpp
/**
 * Given a set of sentence tokens, decodes over them and fills in set of theories 
 */
Given a set of sentence tokens, decodes over them and fills in set of theories
Given a set of sentence tokens decodes over them and fills in set of theories
int IdFDecoder::decodeSentenceNBestAsGiven(IdFSentenceTokens* sentenceTokens, 
										   IdFSentenceTheory **theories, 
									       int max_theories)
{
	int back_pointer = walkForwardThroughSentence(sentenceTokens);
	if (back_pointer == -1) {
		theories[0] = new IdFSentenceTheory(sentenceTokens->getLength(),
			_nameClassTags->getNoneStartTagIndex());
		theories[0]->setBestPossibleScore(-10000);
		return 1;
	}
	if (max_theories == 1) {
		theories[0] = new IdFSentenceTheory();
		theories[0]->setLength(sentenceTokens->getLength());
		for (int sent_index = sentenceTokens->getLength() - 1; sent_index >= 0; sent_index--) {
			theories[0]->setTag(sent_index, back_pointer);
			back_pointer = _backPointers[back_pointer][sent_index];
		}
		return 1;
	}
	walkBackwardThroughSentence(sentenceTokens);
	if (max_theories > _numCurrentTheories) {
		int num_theories = _numCurrentTheories;
		for (int i = 0; i < _numCurrentTheories; i++) {
			theories[i] = _currentTheories[i];
			theories[i]->setLength(sentenceTokens->getLength());
			_currentTheories[i] = 0;
		}
		_numCurrentTheories = 0;
		return num_theories;
	} else {
		for (int j = 0; j < max_theories; j++) {
			double best_score = -10000;
			int best_index = 0;
			for (int i = 0; i < _numCurrentTheories; i++) {
				if (_currentTheories[i] == 0)
					continue;
				if (_currentTheories[i]->getBestPossibleScore() > best_score) {
					best_index = i;
					best_score = _currentTheories[i]->getBestPossibleScore();
				}
			}
			theories[j] = _currentTheories[best_index];
			theories[j]->setLength(sentenceTokens->getLength());
			_currentTheories[best_index] = 0;
		}
		for (int i = 0; i < _numCurrentTheories; i++) {
			if (_currentTheories[i] != 0)
				delete _currentTheories[i];
			_currentTheories[i] = 0;
		}
		_numCurrentTheories = 0;
		return max_theories;
	}
}
int IdFDecoder :: decodeSentenceNBestAsGiven ( IdFSentenceTokens * sentenceTokens , IdFSentenceTheory * * theories , int max_theories ) { int back_pointer = walkForwardThroughSentence ( sentenceTokens ) ; if ( back_pointer == -1 ) { theories [ 0 ] = new IdFSentenceTheory ( sentenceTokens -> getLength ( ) , _nameClassTags -> getNoneStartTagIndex ( ) ) ; theories [ 0 ] -> setBestPossibleScore ( -10000 ) ; return 1 ; } if ( max_theories == 1 ) { theories [ 0 ] = new IdFSentenceTheory ( ) ; theories [ 0 ] -> setLength ( sentenceTokens -> getLength ( ) ) ; for ( int sent_index = sentenceTokens -> getLength ( ) - 1 ; sent_index >= 0 ; sent_index -- ) { theories [ 0 ] -> setTag ( sent_index , back_pointer ) ; back_pointer = _backPointers [ back_pointer ] [ sent_index ] ; } return 1 ; } walkBackwardThroughSentence ( sentenceTokens ) ; if ( max_theories > _numCurrentTheories ) { int num_theories = _numCurrentTheories ; for ( int i = 0 ; i < _numCurrentTheories ; i ++ ) { theories [ i ] = _currentTheories [ i ] ; theories [ i ] -> setLength ( sentenceTokens -> getLength ( ) ) ; _currentTheories [ i ] = 0 ; } _numCurrentTheories = 0 ; return num_theories ; } else { for ( int j = 0 ; j < max_theories ; j ++ ) { double best_score = -10000 ; int best_index = 0 ; for ( int i = 0 ; i < _numCurrentTheories ; i ++ ) { if ( _currentTheories [ i ] == 0 ) continue ; if ( _currentTheories [ i ] -> getBestPossibleScore ( ) > best_score ) { best_index = i ; best_score = _currentTheories [ i ] -> getBestPossibleScore ( ) ; } } theories [ j ] = _currentTheories [ best_index ] ; theories [ j ] -> setLength ( sentenceTokens -> getLength ( ) ) ; _currentTheories [ best_index ] = 0 ; } for ( int i = 0 ; i < _numCurrentTheories ; i ++ ) { if ( _currentTheories [ i ] != 0 ) delete _currentTheories [ i ] ; _currentTheories [ i ] = 0 ; } _numCurrentTheories = 0 ; return max_theories ; } }
Given a set of sentence tokens, decodes over them and fills in set of theories
Given a set of sentence tokens decodes over them and fills in set of theories
// no valid path found
 // NB: theories[] will now own the pointer to this IdFSentenceTheory 
 // NB: theories[] will now own the pointer to this IdFSentenceTheory 
 // clean up _currentTheories
