Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

BasicIndex.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2001 Carnegie Mellon University.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.cs.cmu.edu/~lemur/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 #ifndef _BASICINDEX_HPP
00014 #define _BASICINDEX_HPP
00015 
00017 
00025 //--------------------------------------------------------
00026 // originally written by J. Lafferty, 11/00
00027 //-----------------------------------------------------------------
00028 
00029 
00030 #include <cstdio>
00031 #include <ctime>
00032 #include "common_headers.hpp"
00033 #include "Compress.hpp"
00034 #include "DocStream.hpp"
00035 #include "FastList.hpp"
00036 #include "IndexCount.hpp"
00037 #include "MemList.hpp"
00038 #include "String.hpp"
00039 #include "Terms.hpp"
00040 #include "Index.hpp"
00041 #include "DocStream.hpp"
00042 
00043 class BasicIndex : public Index {
00044 public:
00046   BasicIndex();
00047 
00049   BasicIndex (Compress * pc);
00050 
00051   virtual ~BasicIndex();
00052   
00054   virtual bool open(const char * indexName);
00055 
00057 
00058 
00060   virtual int term (const char * word) { return terms[word];}
00061 
00063   virtual const char * term (int termID) { return terms[termID];} 
00064 
00066   virtual int document (const char * docIDStr) {return docids[docIDStr];}
00067 
00069   virtual const char * document (int docID) {return docids[docID];}
00070 
00072   virtual const char *termLexiconID() { return wordVocabulary;} 
00074 
00076 
00077 
00079   virtual int docCount ()  { return docids.size()-1;}
00080 
00082   virtual int termCountUnique () { return terms.size()-1;}
00083 
00085   virtual int termCount (int termID) const { return countOfTerm[termID] ;}
00086 
00088   virtual int termCount () const {return (int)avgDocumentLength*docids.size() ;}
00089   // XXX Better to have an exact count!
00090 
00092   virtual float docLengthAvg() { return avgDocumentLength;}
00093 
00095   virtual int docCount(int termID);
00096 
00098   virtual int docLength (int docID) const { return countOfDoc[docID];}  ;
00099 
00101 
00103 
00104 
00105   virtual DocInfoList *docInfoList(int termID) ;
00106 
00108   virtual TermInfoList *termInfoList(int docID) ;
00109 
00111 
00112 
00113   // Create basic inverted indices 
00114   void build(DocStream *collectionStream,
00115              const char *file,
00116              const char * outputPrefix, 
00117              int totalDocs=0x1000000, int maxMemory=0x4000000,
00118              int minimumCount=1, int maxVocSize=2000000);
00119 private:
00120   void buildVocabulary(int maxVocSize, int minimumCount);
00121   void writeWordIndex(int indexNum, FastList<IndexCount> * dlw);
00122   int indexCollection();
00123   int headDocIndex();
00124   int headWordIndex();
00125   void createKeys();
00126   void mergeIndexFiles();
00127   void createKey(const char * inName, const char * outName, Terms & voc, int * byteOffset);
00128   int mergePair(const char * fn1, const char * fn2, const char * fn3);
00129   void writeIndexFile();
00130 
00131   ifstream textStream;
00132 
00133   String      prefix;
00134   String      textFile;
00135   String      wordVocabulary;
00136   String      documentVocabulary;
00137   String      wordIndexFile, documentIndexFile;
00138   String      wordKeyFile, documentKeyFile;
00139   Terms       terms;
00140   Terms       docids;
00141   int         numDocuments;
00142   int         numWords;
00143   int         numBytes;
00144   int         maxDocumentLength;
00145   float       avgDocumentLength;
00146   int         totalDocuments;
00147 
00148   // The following are "utility" variables
00149 private:
00150   int         memorySegment;
00151   int         maxSegmentsPerIndex;
00152   time_t      timeToIndex;
00153   int         maximumMemory;
00154   // int *       byteOffsetOfDoc;
00155   MemList *   pMemList;  
00156   Compress *  pCompressor;
00157   bool deleteCompressor;
00158   DocStream * pDocStream;
00159 
00160 private:
00161   // fields for managing indices
00162   ifstream  wordIndexStream, documentIndexStream;
00163   int * woffset, * doffset; //  *toffset;
00164   int * tmpdarr, * tmpwarr;
00165   int * countOfTerm;
00166   int * countOfDoc;
00167 
00168 };
00169 
00170 #endif

Generated at Fri Jul 26 18:22:26 2002 for LEMUR by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000