当前位置: 首页>>代码示例>>C++>>正文


C++ DataReader::readline方法代码示例

本文整理汇总了C++中DataReader::readline方法的典型用法代码示例。如果您正苦于以下问题:C++ DataReader::readline方法的具体用法?C++ DataReader::readline怎么用?C++ DataReader::readline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataReader的用法示例。


在下文中一共展示了DataReader::readline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ss

RatingMatrix::RatingMatrix( DataReader& dreader, int userpos, int itempos, int ratingpos )
: m_numRatings( 0 ),
  m_sumRatings( 0 ),
  m_minRating( INT_MAX ),
  m_maxRating( INT_MIN )
{
   map< pair<size_t,size_t>, double > inputData;
   while( !dreader.eof() )
   {
      vector<string> line = dreader.readline();
      if( line.empty() )
      {
         break;
      }
      string userId = line[userpos];
      string itemId = line[itempos];
      std::stringstream ss( line[ratingpos] );
      double rating;
      ss >> rating;

      //cout << "user [" << userId << "] item [" << itemId << "] rating: [" << rating << "]" << endl;
      size_t row, col;
      map<string,size_t>::iterator ind;

      ind = m_userMapper.find( userId );
      if( ind == m_userMapper.end() )
      {
         row = m_userMapper.size();
         m_userMapper[userId] = row;
      }
      else
      {
         row = ind->second;
      }

      ind = m_itemMapper.find( itemId );
      if( ind == m_itemMapper.end() )
      {
         col = m_itemMapper.size();
         m_itemMapper[itemId] = col;
      }
      else
      {
         col = ind->second;
      }

      if( inputData.find( pair<size_t,size_t>( row, col ) ) != inputData.end() )
      {
         cout << "warning: <user:" << userId << " ,item:" << itemId << "> pair duplicated" << endl;
         continue;
      }
      inputData[pair<size_t,size_t>( row, col )] = rating;

      // Statistical data
      ++m_numRatings;
      m_sumRatings += rating;
      if( rating < m_minRating )
      {
         m_minRating = rating;
      }
      if( rating > m_maxRating )
      {
         m_maxRating = rating;
      }
   }

   m_smatrix.resize( m_userMapper.size(), m_itemMapper.size() );
   map< pair<size_t,size_t>, double >::iterator ind;
   map< pair<size_t,size_t>, double >::iterator end = inputData.end();
   for( ind = inputData.begin() ; ind != end ; ++ind )
   {
      size_t row = ind->first.first;
      size_t col = ind->first.second;
      double rating = ind->second;

      //cout << "row: " << row << " col: " << col << " rating: " << rating << endl;
      m_smatrix.set( row, col, rating );
   }
   //cout << "min rating: " << m_minRating << " max rating: " << m_maxRating << endl;
   //cout << "dim: " << m_smatrix.rows() << "x" << m_smatrix.columns() << endl;
   //m_smatrix.print();
}
开发者ID:wellsoftware,项目名称:pyreclab,代码行数:82,代码来源:RatingMatrix.cpp


注:本文中的DataReader::readline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。