src/PredFinder/db/PlayerDB.cpp
/**
 * Read the sqlite database from the specified
 * location into cached tables.
 *
 * @param db_location Path to the sqlite .db file. If string is empty, db will not be loaded.
 *
 * @author nward@bbn.com
 * @date 2010.08.17
 **/
Read the sqlite database from the specified
location into cached tables.

@param db_location Path to the sqlite .db file. If string is empty, db will not be loaded.


Read the sqlite database from the specified location into cached tables . @param db_location Path to the sqlite . db file . If string is empty db will not be loaded .
PlayerDB::PlayerDB(const std::string db_location) {
	if (db_location == "")
		return;
	SessionLogger::info("LEARNIT") << "Reading NFL player database " << db_location << "..." << std::endl;
	SqliteDB db(db_location);
	Table_ptr player_roster = db.exec(
		L"SELECT roster.season, team.ontology_uri, player.name, player.uri "
		L"FROM roster, team, player "
		L"WHERE roster.player = player.id AND roster.team = team.id AND team.ontology_uri IS NOT NULL"
		);
	BOOST_FOREACH(std::vector<std::wstring> roster_row, *player_roster) {
		int season = boost::lexical_cast<int>(roster_row[0]);
		std::wstring team_uri = roster_row[1];
		std::wstring player_name = roster_row[2];
		std::wstring player_uri = boost::replace_first_copy(roster_row[3], L"http://www.footballdb.com/players/", L"fdb:");
		std::pair<SeasonMap::iterator, bool> season_insert = _players_by_team_and_season.insert(SeasonMap::value_type(season, StringVectorMap()));
		std::pair<StringVectorMap::iterator, bool> team_insert = season_insert.first->second.insert(StringVectorMap::value_type(team_uri, std::vector<std::pair<std::wstring,std::wstring> >()));
		team_insert.first->second.push_back(std::pair<std::wstring, std::wstring>(player_name, player_uri));
	}
	SessionLogger::info("LEARNIT") << "  Found " << player_roster->size() << " roster entries over " << _players_by_team_and_season.size() << " seasons" << std::endl;
}
PlayerDB :: PlayerDB ( const std :: string db_location ) { if ( db_location == " " ) return ; SessionLogger :: info ( " " ) << " " << db_location << " " << std :: endl ; SqliteDB db ( db_location ) ; Table_ptr player_roster = db . exec ( L" " L" " L" " ) ; BOOST_FOREACH ( std :: vector < std :: wstring > roster_row , * player_roster ) { int season = boost :: lexical_cast < int > ( roster_row [ 0 ] ) ; std :: wstring team_uri = roster_row [ 1 ] ; std :: wstring player_name = roster_row [ 2 ] ; std :: wstring player_uri = boost :: replace_first_copy ( roster_row [ 3 ] , L" " , L" " ) ; std :: pair < SeasonMap :: iterator , bool > season_insert = _players_by_team_and_season . insert ( SeasonMap :: value_type ( season , StringVectorMap ( ) ) ) ; std :: pair < StringVectorMap :: iterator , bool > team_insert = season_insert . first -> second . insert ( StringVectorMap :: value_type ( team_uri , std :: vector < std :: pair < std :: wstring , std :: wstring > > ( ) ) ) ; team_insert . first -> second . push_back ( std :: pair < std :: wstring , std :: wstring > ( player_name , player_uri ) ) ; } SessionLogger :: info ( " " ) << " " << player_roster -> size ( ) << " " << _players_by_team_and_season . size ( ) << " " << std :: endl ; }
Read the sqlite database from the specified
 location into cached tables.
Read the sqlite database from the specified location into cached tables .
// Ignore unspecified parameter
 // Open the database
 // Populate the player lookup table
 // Get the values from the database
 // Make sure this season has an entry
 // Make sure this team has an entry
 // Append this player
