Browse the Index

19 篇文章 0 订阅
3 篇文章 0 订阅
November 24
Browse the Index
参考文档:
http://lemur.wiki.sourceforge.net/Example+Applications+in+CPlusPlus

http://www.lemurproject.org/doxygen/lemur/html/classlemur_1_1api_1_1Index.html

随便写一个测试程序:

  1. #include<iostream>
  2. #include"Index.hpp"
  3. #include"IndexManager.hpp"
  4. #include"TermInfoList.hpp"
  5. #include"DocInfoList.hpp"
  6. #include<string>
  7. using namespace std;
  8. using namespace lemur::api;
  9. int main()
  10. {
  11.     Index *ind=IndexManager::openIndex("/media/disk/IndexIndri");
  12. /*
  13.     *  term( char* s ): convert term string to a number
  14.     * term( int id ): convert term number to a string
  15.     * termCount(): Total number of terms indexed
  16.     * termCount( int id ): Total number of occurrences of term number id
  17.     * docLength( int docID ): The length, in number of terms, of document number docID.
  18.     * termCountUnique(): Size of the index vocabulary
  19.     * docInfoList( int termID ): Returns an iterator to the inverted list for termID.
  20.     * The list contains all documents that contain termID, including the positions where termID occurs.
  21.     * document( char* s ): convert doc string to a number
  22.     * document( int id ): convert doc number to a string
  23.     * docCount(): Number of documents indexed
  24.     * docCount( int id ): Number of documents that contain term number id
  25.     * docLengthAvg(): Average indexed document length
  26.     * termInfoList( int docID ): Returns an iterator to the direct list for docID.
  27.     * The list contains term numbers for every term contained in document docID, and the number of times each word occurs.
  28. */
  29.     //irst,we want to get some terms counts and its counts in special documents
  30.     string term1="How",term2="are",term3="you";
  31.     int termID=ind->term(term1);
  32.     cout<<term1<<":"<<ind->termCount(termID)<<"/n"
  33.     <<"Its ID is:"<<ind->term(term1)<<"/n"
  34.     <<"Unique Terms="<<ind->termCountUnique()<<"/n"
  35.     <<"All words="<<ind->termCount()<<endl;
  36.     int docID=ind->document("WTX001-B01-1");
  37.     cout<<ind->document(docID)<<"'s ID is "<<docID<<"/n"
  38.     <<"It has "<<ind->docCount()<<" words /n"   
  39.     <<"It has "<<ind->docCount(ind->term(term1))<<" /"how/" /n"
  40.     <<endl;//get one document ID;
  41.     DocInfoList *docList = ind->docInfoList(termID);
  42.     // iterate over entries in docList
  43.     docList->startIteration();  
  44.     DocInfo *dEntry;
  45.     int times=0;
  46.     while (docList->hasMore() && times++<20)
  47.     {
  48.         dEntry = docList->nextEntry();
  49.         // note that nextEntry() does *not* return an instance,
  50.         // instead, it passes out a pointer to a local static variable
  51.         // so no "delete" is needed.
  52.                 // print out this entry
  53.                 cout << "-> " << dEntry->termCount() << " times in doc "
  54.                   << ind->document(dEntry->docID()) << endl;
  55.         for (int t=0; t < dEntry->termCount(); t++)
  56.         {
  57.                  cout << dEntry->positions()[t] << " ";
  58.         }
  59.            cout << endl;
  60.          }
  61.         delete docList; // note that you MUST delete docList!
  62.  
  63.     TermInfoList * termInfoList = ind->termInfoList(docID);
  64.     termInfoList->startIteration();
  65.     times=0;
  66.     while(termInfoList->hasMore() &×++<10)
  67.     {
  68.         TermInfo * termInfo = termInfoList->nextEntry();
  69.         cout <<ind->term(termInfo->termID()) << "----" << termInfo->count()<<endl;
  70.     //    for(int s=0;s<termInfo->count();++s)
  71.     //        cout<<termInfo->positions()[s]<<"/t";
  72.     }
  73.     cout<<endl;
  74.     termInfoList=ind->termInfoListSeq(docID);
  75.     termInfoList->startIteration();
  76.     times=0;
  77.     while(termInfoList->hasMore() && times++<10)
  78.     {
  79.         TermInfo *termInfo=termInfoList->nextEntry();
  80.         cout <<ind->term(termInfo->termID()) << "/t" << termInfo->count()<<endl;
  81.     }
  82.     delete termInfoList;
  83.    return 0;
  84. }



下一站:Simple Retrieval
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值