src/Arabic/parse/ar_ChartDecoder.cpp
/* simultaneously add constraints and morph analysis 
	returns the maximum number of tokens in the chart
*/
simultaneously add constraints and morph analysis
returns the maximum number of tokens in the chart
simultaneously add constraints and morph analysis returns the maximum number of tokens in the chart
int ArabicChartDecoder::initChart(Symbol* sentence,  Symbol* split_sentence, int length)
{	
	int curr_const = 0;
	int left = -1, right = -1;
	Symbol type;
	EntityType entityType;
	if(numConstraints >0){
		left = constraints[curr_const].left;
		right = constraints[curr_const].right;
		type = constraints[curr_const].type;
		entityType = constraints[curr_const].entityType;
	}
	int chart_index = 0;  
	_numNameWords = 0;
	int m = 0;			
	while(m < length){
		if(m ==left){
			int name_len = right - left;
			if(DEBUG1)
				_debugStream<<"Adding Name Tokens: ";
			int i = left;
			int k = 0;
			for(; i<=right; i++, k++){
				_nameWords[_numNameWords++] =sentence[i];
				split_sentence[chart_index+k] = sentence[i];
				if(DEBUG1){
					Symbol debugSym = ArabicSymbol::BWSymbol(sentence[i].to_string());
					_debugStream<<debugSym.to_debug_string()<<" ";
				}
			}
			if(DEBUG1){
				_debugStream<<"\n";
			}
			addConstraintEntry(left, right,chart_index, chart_index + name_len, sentence, type, entityType);
			m = right +1;
			curr_const++;
			if(curr_const < numConstraints){
				left = constraints[curr_const].left;
				right = constraints[curr_const].right;
				type = constraints[curr_const].type;
			}
			chart_index = chart_index+name_len +1;
		}
		else{
			if(DEBUG1){
				Symbol debugSym = ArabicSymbol::BWSymbol(sentence[m].to_string());
				_debugStream<<"Adding Token: "<<m<<" "<<debugSym.to_debug_string()<<"\n";
			}
			WordSegment* word_parts = new WordSegment();
			word_parts->getSegments(sentence[m]);
			WordAnalysis longword = word_parts->getLongest(); 
			for(int i = 0; i<word_parts->maxLength(); i++){
				split_sentence[chart_index+i] = longword.segments[i]->getText();
			}
			chart_index = initChartWordMultiple(word_parts, chart_index, m ==0);
			m++;
			delete word_parts;	
		}
	}
	return chart_index;
}
int ArabicChartDecoder :: initChart ( Symbol * sentence , Symbol * split_sentence , int length ) { int curr_const = 0 ; int left = -1 , right = -1 ; Symbol type ; EntityType entityType ; if ( numConstraints > 0 ) { left = constraints [ curr_const ] . left ; right = constraints [ curr_const ] . right ; type = constraints [ curr_const ] . type ; entityType = constraints [ curr_const ] . entityType ; } int chart_index = 0 ; _numNameWords = 0 ; int m = 0 ; while ( m < length ) { if ( m == left ) { int name_len = right - left ; if ( DEBUG1 ) _debugStream << " " ; int i = left ; int k = 0 ; for ( ; i <= right ; i ++ , k ++ ) { _nameWords [ _numNameWords ++ ] = sentence [ i ] ; split_sentence [ chart_index + k ] = sentence [ i ] ; if ( DEBUG1 ) { Symbol debugSym = ArabicSymbol :: BWSymbol ( sentence [ i ] . to_string ( ) ) ; _debugStream << debugSym . to_debug_string ( ) << " " ; } } if ( DEBUG1 ) { _debugStream << " \n " ; } addConstraintEntry ( left , right , chart_index , chart_index + name_len , sentence , type , entityType ) ; m = right + 1 ; curr_const ++ ; if ( curr_const < numConstraints ) { left = constraints [ curr_const ] . left ; right = constraints [ curr_const ] . right ; type = constraints [ curr_const ] . type ; } chart_index = chart_index + name_len + 1 ; } else { if ( DEBUG1 ) { Symbol debugSym = ArabicSymbol :: BWSymbol ( sentence [ m ] . to_string ( ) ) ; _debugStream << " " << m << " " << debugSym . to_debug_string ( ) << " \n " ; } WordSegment * word_parts = new WordSegment ( ) ; word_parts -> getSegments ( sentence [ m ] ) ; WordAnalysis longword = word_parts -> getLongest ( ) ; for ( int i = 0 ; i < word_parts -> maxLength ( ) ; i ++ ) { split_sentence [ chart_index + i ] = longword . segments [ i ] -> getText ( ) ; } chart_index = initChartWordMultiple ( word_parts , chart_index , m == 0 ) ; m ++ ; delete word_parts ; } } return chart_index ; }
simultaneously add constraints and morph analysis
returns the maximum number of tokens in the chart
simultaneously add constraints and morph analysis returns the maximum number of tokens in the chart
//initialize entire chart to 0 in preparation of post processing
 /*
	for(int i = 0; i < MAX_SENTENCE_LENGTH; i++){
		for(int j = 0; j< MAX_SENTENCE_LENGTH; j++){
			for(int k = 0; k<MAX_ENTRIES_PER_CELL; k++){
				chart[i][j][k] = 0;
			}
		}
	} 
	*/ //Assume constraints are in increasing order ?
 //chart index is the current position in the chart
 //m is the index into the original sentence
 //for postprocessing
 //debugging
 //chart_index+=word_parts->maxLength();
 //reset would be better!
