00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class CXMLElement;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _CACIFFILESYSTEM
00053 #define _CACIFFILESYSTEM
00054 #include "libGIFTAcInvertedFile/include/uses-declarations.h"
00055 #include <string>
00056 #include "libMRML/include/TID.h"
00057 #include "libMRML/include/CSelfDestroyPointer.h"
00058 #include "libMRML/include/CArraySelfDestroyPointer.h"
00059 #include "libGIFTAcInvertedFile/include/CDocumentFrequencyList.h"
00060 #include "libMRML/include/CMutex.h"
00061
00062 #include "libGIFTAcInvertedFile/include/CADIHash.h"
00063 #include "libGIFTAcURL2FTS/include/CAcURL2FTS.h"
00064 #include "libGIFTAcInvertedFile/include/CAcInvertedFile.h"
00065 #include <iostream>
00066 #include <fstream>
00067 #include <map>
00068 #include <vector>
00069 #ifdef HAS_HASH_MAP
00070 #include <hash_map>
00071 #define HASH_MAP hash_map
00072 #else
00073 #define HASH_MAP map
00074 #endif
00075 #include <functional>
00076 #include <algorithm>
00077
00078 #include "libMRML/include/CMagic.h"
00079
00080
00081 typedef TID TFeatureID ;
00082
00093 class CAcIFFileSystem:public CAcInvertedFile{
00094
00095 protected:
00097 CMutex mMutex;
00103 CSelfDestroyPointer<CAcURL2FTS> mURL2FTS;
00105 TID mMaximumFeatureID;
00108 #ifndef V295
00109 string mInvertedFileBuffer;
00110 #else
00111 CArraySelfDestroyPointer<char> mInvertedFileBuffer;
00112 #endif
00113
00115 string mTemporaryIndexingFileBase;
00117 mutable CSelfDestroyPointer<istream> mInvertedFile;
00118
00120 mutable ifstream mOffsetFile;
00121
00123 ifstream mFeatureDescriptionFile;
00124
00126 string mInvertedFileName;
00127
00129 string mOffsetFileName;
00130
00132 string mFeatureDescriptionFileName;
00133
00135 typedef HASH_MAP<TID,streampos> CIDToOffset;
00137 CIDToOffset mIDToOffset;
00138
00140 mutable HASH_MAP<TID,double> mFeatureToCollectionFrequency;
00141
00145 HASH_MAP<TID,unsigned int> mFeatureDescription;
00146
00150 CADIHash mDocumentInformation;
00152
00155 void writeOffsetFileElement(TID inFeatureID,
00156 streampos inPosition,
00157 ostream& inOpenOffsetFile);
00159 CDocumentFrequencyList* getFeatureFile(string inFileName)const;
00160 public:
00162 bool operator()()const;
00163
00190 CAcIFFileSystem(const CXMLElement& inCollectionElement);
00192 bool init(bool);
00193
00195 ~CAcIFFileSystem();
00196
00198 string IDToURL(TID inID)const;
00199
00203 CDocumentFrequencyList* FeatureToList(TFeatureID)const;
00204
00206 CDocumentFrequencyList* URLToFeatureList(string inURL)const;
00207
00209 CDocumentFrequencyList* DIDToFeatureList(TID inDID)const;
00210
00212
00213
00217 double FeatureToCollectionFrequency(TFeatureID)const;
00218
00220 unsigned int getFeatureDescription(TID inFeatureID)const;
00222
00226 double DIDToMaxDocumentFrequency(TID)const;
00227
00229 double DIDToDFSquareSum(TID)const;
00230
00232 double DIDToSquareDFLogICFSum(TID)const;
00234
00235
00237
00245 bool generateInvertedFile();
00246
00254 bool newGenerateInvertedFile();
00255
00258 bool checkConsistency();
00259
00266 bool findWithinStream(TID inFeatureID,
00267 TID inDocumentID,
00268 double inDocumentFrequency)const;
00269
00271
00277 virtual pair<bool,TID> URLToID(const string& inURL)const;
00278
00280 void getAllIDs(list<TID>&)const;
00283 void getAllAccessorElements(list<CAccessorElement>&)const;
00288 void getRandomIDs(list<TID>&,
00289 list<TID>::size_type)const;
00298 void getRandomAccessorElements(list<CAccessorElement>& outResult,
00299 list<CAccessorElement>::size_type inSize)const;
00301 int size()const;
00303
00304 TID getMaximumFeatureID()const;
00312 list<TID>* getAllFeatureIDs()const;
00318 virtual pair<bool,CAccessorElement> IDToAccessorElement(TID inID)const;
00320 operator bool()const;
00321
00322 };
00323
00324 #endif