自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(4)

以下是根据正向索引建立倒排索引的注释

 

  1. int main(int argc, char* argv[])    //./CrtInvertedIdx moon.fidx.sort > sun.iidx
  2. {
  3.     ifstream ifsImgInfo(argv[1]);
  4.     if (!ifsImgInfo) 
  5.     {
  6.         cerr << "Cannot open " << argv[1] << " for input/n";
  7.         return -1;
  8.     }
  9.     string strLine,strDocNum,tmp1="";
  10.     int cnt = 0;
  11.     while (getline(ifsImgInfo, strLine)) 
  12.     {
  13.         string::size_type idx;
  14.         string tmp;
  15.         idx = strLine.find("/t");
  16.         tmp = strLine.substr(0,idx);
  17.         if (tmp.size()<2 || tmp.size() > 8) continue;
  18.         if (tmp1.empty()) tmp1=tmp;
  19.         if (tmp == tmp1) 
  20.         {
  21.             strDocNum = strDocNum + " " + strLine.substr(idx+1);
  22.         }
  23.         else 
  24.         {
  25.             if ( strDocNum.empty() )
  26.                 strDocNum = strDocNum + " " + strLine.substr(idx+1);
  27.             cout << tmp1 << "/t" << strDocNum << endl;
  28.             tmp1 = tmp;
  29.             strDocNum.clear();
  30.             strDocNum = strDocNum + " " + strLine.substr(idx+1);
  31.         }
  32.         cnt++;
  33.         //if (cnt==100) break;
  34.     }
  35.     cout << tmp1 << "/t" << strDocNum << endl;  //倒排索引中每个字典单词后的文档编号以table键为间隔
  36.     return 0;
  37. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zda天天爱打卡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值