generateDistanceMatrix.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "../config.h"
00020
00021
00022 #include "libMRML/include/TID.h"
00023 #include <iostream>
00024 #include "libMRML/include/CRelevanceLevelList.h"
00025 #include "CInvertedFileAccessor.h"
00026 #include "CInvertedFileQuery.h"
00027 #include "libGIFTQuInvertedFile/include/CQNBestFullyWeighted.h"
00028 #include "libGIFTQuInvertedFile/include/CWFBestFullyWeighted.h"
00029 #include "libGIFTQuInvertedFile/include/CQNNoNormalization.h"
00030 #include "libGIFTQuInvertedFile/include/CQNEuclideanLengthSquare.h"
00031 #include "libGIFTQuInvertedFile/include/CQNSquareDFLogICFSum.h"
00032 #include "libGIFTQuInvertedFile/include/CQNMaxDocumentFrequency.h"
00033 #include "libGIFTQuInvertedFile/include/CWFBestProbabilistic.h"
00034 #include "libGIFTQuInvertedFile/include/CWFClassicalIDF.h"
00035 #include "libGIFTQuInvertedFile/include/CWFBinaryTerm.h"
00036 #include "libGIFTQuInvertedFile/include/CWFStandardTF.h"
00037 #include "libGIFTQuInvertedFile/include/CWFCoordinationLevel.h"
00038 #include "CWFNormal.h"
00039 #include "CWFColorHistogram.h"
00040 #include "CWFTextureHistogram.h"
00041
00042 #include "CWFBlockOnly.h"
00043 #include "CWFColorBlockOnly.h"
00044 #include "CWFTextureBlockOnly.h"
00045
00046 #include <algorithm>
00047 #include <cstdio>
00048 #include <stdlib.h>
00049 #include <string>
00050
00051
00052 TID gID;
00053
00054 #define QUERY
00055
00056
00057
00058
00059
00060
00061 bool sortByFirst(const pair<TID,float>& l,
00062 const pair<TID,float>& t){
00063 return
00064 l.first
00065 >
00066 t.first;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 void printListAsHTML(CRelevanceLevelList* inQueryResultList,
00083 string inQueryResultFileName){
00084 if(inQueryResultList)
00085 {
00086
00087 ofstream lQueryResultFile(inQueryResultFileName.c_str(),
00088 fstream::in+fstream::out);
00089 if(lQueryResultFile)
00090 {
00091 lQueryResultFile << "<HTML>"
00092 << endl
00093 << "<BODY>"
00094 << endl
00095 << "<TABLE>"
00096 << endl
00097 << "<TR>";
00098
00099 int lCount=0;
00100 for(CRelevanceLevelList::const_iterator i=inQueryResultList->begin();
00101 i!=inQueryResultList->end()
00102 && lCount<NUMBER_OF_IMAGES;
00103 i++,lCount++){
00104
00105
00106 if (lCount == 20)
00107 lQueryResultFile << "</TR>" << endl << "</TABLE>" << endl
00108 << "<!--"
00109 << endl;
00110
00111 if(!(lCount%5))
00112 lQueryResultFile << "</TR>"
00113 << endl
00114 << "<TR>";
00115
00116 lQueryResultFile << "<TD>"
00117 << endl;
00118 (*i).outputHTML(lQueryResultFile);
00119 lQueryResultFile << "</TD>"
00120 << endl;
00121
00122 }
00123
00124 lQueryResultFile << "</TR>"
00125 << endl
00126 << "</TABLE>"
00127 << endl
00128 << "-->"
00129 << endl
00130 << "</BODY>"
00131 << endl
00132 << "</HTML>";
00133 }
00134 }else
00135 cout << "failed"
00136 << endl;
00137
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 main(int argc,
00156 char** argv){
00157
00158 if(argc!=2){
00159 cout << "Usage: "
00160 << argv[0]
00161 << " <number_of_entries_to_skip>"
00162 << endl;
00163 }
00164
00165 const int lSkipNumber=atoi(argv[1]);
00166
00167
00168
00169 cout << "Constructing Accessor..."
00170 << flush;
00171
00172 CInvertedFileAccessor lAccessor(INVERTED_FILE_LOCATION,
00173 OFFSET_FILE_LOCATION,
00174 FEATURE_FILE_LOCATION,
00175 FEATURE_DESCRIPTION_LOCATION);
00176 cout << "...after construction"
00177 << endl;
00178
00179
00180 cout << "Classic" << flush;
00181 CQueryNormalizer*
00182 lDocumentNormalizer(new CQNNoNormalization(&lAccessor));
00183 CQueryNormalizer*
00184 lQueryNormalizer(new CQNNoNormalization(&lAccessor));
00185 CWeightingFunction* lWeightingFunction=
00186 new CWFClassicalIDF(&lAccessor,
00187 lQueryNormalizer,
00188 lDocumentNormalizer);
00189
00190 CRelevanceLevelList* lOutList;
00191
00192 cout << "Constructing Query-handler..."
00193 << flush;
00194 CInvertedFileQuery lQuery(lAccessor,
00195 *lWeightingFunction,
00196 *lQueryNormalizer,
00197 *lDocumentNormalizer);
00198 #ifdef W_PRUNING
00199 lQuery.activateBlockingFeatures();
00200
00201
00202 lQuery.blockFeatureGroup(GABOR_POS);
00203 #endif
00204
00205 cout << "...after construction"
00206 << endl;
00207
00208
00209 list<TID> lAllIDs;
00210
00211 lAccessor.getAllIDs(lAllIDs);
00212
00213 lAllIDs.sort();
00214
00215 {
00216 ofstream lTranslatorFile(DISTANCE_MATRIX_HOME
00217
00218 ".trans");
00219 int lCounter(0);
00220 for(list<TID>::const_iterator i=lAllIDs.begin();
00221 i!=lAllIDs.end();
00222 i++,
00223 lCounter++){
00224 lTranslatorFile << *i
00225 << " "
00226 << lCounter
00227 << endl;
00228 }
00229 }
00230
00231 fstream lDistanceFile(DISTANCE_MATRIX_HOME,
00232 fstream::in+fstream::out);
00233
00234 lDistanceFile.seekp(lAllIDs.size() * lSkipNumber * sizeof(float));
00235
00236 int lSkipCount=0;
00237 list<TID>::const_iterator i=lAllIDs.begin();
00238 for(;
00239 (i!=lAllIDs.end()) && (lSkipCount<lSkipNumber);
00240 i++,lSkipCount++){
00241
00242 };
00243
00244 for(;
00245 i!=lAllIDs.end();
00246 i++){
00247
00248 CRelevanceLevelList lRLL;
00249 lRLL.push_back(CRelevanceLevel(lAccessor.IDToURL(*i),1));
00250
00251 cout << "The Query:"
00252 << lRLL.back().getURL()
00253 << endl;
00254
00255
00256 lOutList=lQuery.startQuery(lRLL,
00257 lAllIDs.size());
00258 {
00259 if(lOutList){
00260
00261 list<pair<TID,float> > lLineVector;
00262
00263 for(CRelevanceLevelList::iterator j=lOutList->begin();
00264 j!=lOutList->end();
00265 j++){
00266 lLineVector.push_back(make_pair(lAccessor.URLToID(j->getURL()),
00267 j->getRelevanceLevel()));
00268 }
00269 lLineVector.sort();
00270
00271
00272
00273 int lWriteCount=0;
00274
00275 int lOld=0;
00276 for(list<pair<TID,float> >::const_iterator j=lLineVector.begin();
00277 j!=lLineVector.end();
00278 j++){
00279 for(;
00280 lOld < j->first;
00281 lOld++){
00282 float lBuffer(0.0);
00283 lDistanceFile.write(&lBuffer,sizeof(lBuffer));
00284 lWriteCount++;
00285 }
00286 lOld++;
00287
00288 cout << "["
00289 << j->first
00290 << ","
00291 << j->second
00292 << "]";
00293
00294 float lDistance(j->second);
00295
00296 lDistanceFile.write(&lDistance,sizeof(lDistance));
00297 lWriteCount++;
00298 }
00299 for(;
00300 lOld < lAllIDs.size();
00301 lOld++){
00302 float lBuffer(0.0);
00303 lDistanceFile.write(&lBuffer,sizeof(lBuffer));
00304 lWriteCount++;
00305 }
00306 lDistanceFile << flush;
00307
00308 cout << endl
00309 << "Written: "
00310 << lWriteCount
00311 << "----------------------------------------Size: "
00312 << lLineVector.size()
00313 << endl;
00314 }
00315 }
00316
00317 delete lOutList;
00318 }
00319 }
00320
00321
00322
00323