学着站在巨人的肩膀上

金融数学,InformationSearch,Compiler,OS,

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  12 随笔 :: 0 文章 :: 8 评论 :: 0 Trackbacks

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

 

int main(int argc, char* argv[])    //./CrtInvertedIdx moon.fidx.sort > sun.iidx
{
    ifstream ifsImgInfo(argv[1]);
    if (!ifsImgInfo) 
    {
        cerr << "Cannot open " << argv[1] << " for input\n";
        return -1;
    }

    string strLine,strDocNum,tmp1="";
    int cnt = 0;
    while (getline(ifsImgInfo, strLine)) 
    {
        string::size_type idx;
        string tmp;


        idx = strLine.find("\t");
        tmp = strLine.substr(0,idx);

        if (tmp.size()<2 || tmp.size() > 8) continue;

        if (tmp1.empty()) tmp1=tmp;

        if (tmp == tmp1) 
        {
            strDocNum = strDocNum + " " + strLine.substr(idx+1);
        }
        else 
        {
            if ( strDocNum.empty() )
                strDocNum = strDocNum + " " + strLine.substr(idx+1);

            cout << tmp1 << "\t" << strDocNum << endl;
            tmp1 = tmp;
            strDocNum.clear();
            strDocNum = strDocNum + " " + strLine.substr(idx+1);
        }

        cnt++;
        //if (cnt==100) break;
    }
    cout << tmp1 << "\t" << strDocNum << endl;  //倒排索引中每个字典单词后的文档编号以table键为间隔

    return 0;
}

 

 

posted on 2009-12-10 23:03 学者站在巨人的肩膀上 阅读(1558) 评论(3)  编辑 收藏 引用 所属分类: 中文文本信息处理

评论

# re: 自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(4) 2009-12-12 13:15 罗莱价格
深深地克里夫克莱顿法  回复  更多评论
  

# re: 自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(4)[未登录] 2009-12-13 13:54 megax
能不能不要这么发文章?啊?不能合并在一块吗?弄的首页上都是你的。。。好吗  回复  更多评论
  

# re: 自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(4) 2009-12-14 22:34 mac
好文!请问博主能留个联系方式吗?  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理