src/Generic/edt/StatNameLinker.cpp
//load generic and specific unseen weights

load generic and specific unseen weights
load generic and specific unseen weights
void StatNameLinker::loadWeights() {
	int i;
	for (i=0; i < EntityType::getNTypes(); i++) {
		LexEntity::unseen_weights[i] = 0.1;
		_generic_unseen_weights[i] = 0.1;
	}
	std::string spec_file = ParamReader::getRequiredParam("specific_unseen_weights");
	boost::scoped_ptr<UTF8InputStream> specStream_scoped_ptr(UTF8InputStream::build(spec_file.c_str()));
	UTF8InputStream& specStream(*specStream_scoped_ptr);
	int n_entries = -1;
	specStream >> n_entries;
	if (specStream.eof() || n_entries < 0) 
	{
		std::stringstream errMsg;
		errMsg << "Could not read file:\n";
		errMsg << spec_file;
		errMsg << "\nSpecified by parameter 'specific_unseen_weights'";
		throw UnrecoverableException("StatNameLinker::loadWeights()", errMsg.str().c_str());
	}
	UTF8Token token;
	if (n_entries != EntityType::getNTypes()) {
		SessionLogger::dbg("spec_wts_0") << "About to read in " << n_entries
			<< " specific weights; there have been " << EntityType::getNTypes()
			<< " types read in.";
	}
	for (i=0; i < n_entries; i++) {
		specStream >> token;
		if (token.symValue() != SymbolConstants::leftParen) {
			SessionLogger::err("read_ch_0") << "Expected '('; read in " << token.chars()
				<< "; Aborting file";
			break;
		}
		specStream >> token;
		int pos = -1;
		try {
			pos = EntityType(token.symValue()).getNumber();
		}
		catch (UnexpectedInputException &) {
			std::string message = "";
			message += "The name linker model refers to "
					   "at least one unrecognized entity type: ";
			message += token.symValue().to_debug_string();
			throw UnexpectedInputException("StatNameLinker::loadWeights()",
										   message.c_str());
		}
		double val;
		specStream >> val;
		if (pos >=0)
			LexEntity::unseen_weights[pos] = val;
		specStream >> token;
		if (token.symValue() != SymbolConstants::rightParen) {
			SessionLogger::err("read_ch_1") << "Expected ')'; read in " << token.chars()
				<< "; Aborting file";
			break;
		}
	}
	specStream.close();
	std::string gen_file = ParamReader::getRequiredParam("generic_unseen_weights");
	boost::scoped_ptr<UTF8InputStream> genStream_scoped_ptr(UTF8InputStream::build(gen_file.c_str()));
	UTF8InputStream& genStream(*genStream_scoped_ptr);
	n_entries = -1;
	genStream >> n_entries;
	if (genStream.eof() || n_entries < 0) {
		std::stringstream errMsg;
		errMsg << "Could not read file:\n";
		errMsg << gen_file;
		errMsg << "\nSpecified by parameter generic_unseen_weights";
		throw UnrecoverableException("StatNameLinker::loadWeights()", errMsg.str().c_str());
	}
	if (n_entries != EntityType::getNTypes() && n_entries != EntityType::getNTypes() - 1) {
		SessionLogger::dbg("gen_wts_0") << "About to read in " << n_entries
			<< " generic weights; there have been " << EntityType::getNTypes()
			<< " types read in.";
	}
	for (i=0; i < n_entries; i++) {
		genStream >> token;
		if (token.symValue() != SymbolConstants::leftParen) {
			SessionLogger::err("exp_ch_5") << "Expected '('; read in " << token.chars()
				<< "; Aborting file";
			break;
		}
		genStream >> token;
		int pos = -1;
		try {
			pos = EntityType(token.symValue()).getNumber();
		}
		catch (UnexpectedInputException &) {
			std::string message = "";
			message += "The name linker model refers to "
					   "at least one unrecognized entity type: ";
			message += token.symValue().to_debug_string();
			throw UnexpectedInputException("StatNameLinker::loadWeights()",
										   message.c_str());
		}
		double val;
		genStream >> val;
		if (pos >= 0)
			_generic_unseen_weights[pos] = val;
		genStream >> token;
		if (token.symValue() != SymbolConstants::rightParen) {
			SessionLogger::err("no_paren_0") << "Expected ')'; read in " << token.chars()
				<< "; Aborting file";
			break;
		}
	}
	genStream.close();
}
void StatNameLinker :: loadWeights ( ) { int i ; for ( i = 0 ; i < EntityType :: getNTypes ( ) ; i ++ ) { LexEntity :: unseen_weights [ i ] = 0.1 ; _generic_unseen_weights [ i ] = 0.1 ; } std :: string spec_file = ParamReader :: getRequiredParam ( " " ) ; boost :: scoped_ptr < UTF8InputStream > specStream_scoped_ptr ( UTF8InputStream :: build ( spec_file . c_str ( ) ) ) ; UTF8InputStream & specStream ( * specStream_scoped_ptr ) ; int n_entries = -1 ; specStream >> n_entries ; if ( specStream . eof ( ) || n_entries < 0 ) { std :: stringstream errMsg ; errMsg << " \n " ; errMsg << spec_file ; errMsg << " \n " ; throw UnrecoverableException ( " " , errMsg . str ( ) . c_str ( ) ) ; } UTF8Token token ; if ( n_entries != EntityType :: getNTypes ( ) ) { SessionLogger :: dbg ( " " ) << " " << n_entries << " " << EntityType :: getNTypes ( ) << " " ; } for ( i = 0 ; i < n_entries ; i ++ ) { specStream >> token ; if ( token . symValue ( ) != SymbolConstants :: leftParen ) { SessionLogger :: err ( " " ) << " " << token . chars ( ) << " " ; break ; } specStream >> token ; int pos = -1 ; try { pos = EntityType ( token . symValue ( ) ) . getNumber ( ) ; } catch ( UnexpectedInputException & ) { std :: string message = " " ; message += " " " " ; message += token . symValue ( ) . to_debug_string ( ) ; throw UnexpectedInputException ( " " , message . c_str ( ) ) ; } double val ; specStream >> val ; if ( pos >= 0 ) LexEntity :: unseen_weights [ pos ] = val ; specStream >> token ; if ( token . symValue ( ) != SymbolConstants :: rightParen ) { SessionLogger :: err ( " " ) << " " << token . chars ( ) << " " ; break ; } } specStream . close ( ) ; std :: string gen_file = ParamReader :: getRequiredParam ( " " ) ; boost :: scoped_ptr < UTF8InputStream > genStream_scoped_ptr ( UTF8InputStream :: build ( gen_file . c_str ( ) ) ) ; UTF8InputStream & genStream ( * genStream_scoped_ptr ) ; n_entries = -1 ; genStream >> n_entries ; if ( genStream . eof ( ) || n_entries < 0 ) { std :: stringstream errMsg ; errMsg << " \n " ; errMsg << gen_file ; errMsg << " \n " ; throw UnrecoverableException ( " " , errMsg . str ( ) . c_str ( ) ) ; } if ( n_entries != EntityType :: getNTypes ( ) && n_entries != EntityType :: getNTypes ( ) - 1 ) { SessionLogger :: dbg ( " " ) << " " << n_entries << " " << EntityType :: getNTypes ( ) << " " ; } for ( i = 0 ; i < n_entries ; i ++ ) { genStream >> token ; if ( token . symValue ( ) != SymbolConstants :: leftParen ) { SessionLogger :: err ( " " ) << " " << token . chars ( ) << " " ; break ; } genStream >> token ; int pos = -1 ; try { pos = EntityType ( token . symValue ( ) ) . getNumber ( ) ; } catch ( UnexpectedInputException & ) { std :: string message = " " ; message += " " " " ; message += token . symValue ( ) . to_debug_string ( ) ; throw UnexpectedInputException ( " " , message . c_str ( ) ) ; } double val ; genStream >> val ; if ( pos >= 0 ) _generic_unseen_weights [ pos ] = val ; genStream >> token ; if ( token . symValue ( ) != SymbolConstants :: rightParen ) { SessionLogger :: err ( " " ) << " " << token . chars ( ) << " " ; break ; } } genStream . close ( ) ; }
load generic and specific unseen weights
load generic and specific unseen weights
// initialize the arrays (to something other than 0)
 // notice the specific weights actually reside in LexEntity!
 //The generic weights are local.
 // Expect paren, type, val, paren
 // JCS - 2/23/04 don't really need the generic weight for OTH - it doesn't ever get used.
 // Expect paren, type, val, paren
