Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

mainRepository.cpp

Go to the documentation of this file.
00001 #include "Persistency/FikSvmRepository.h"
00002 #include "Persistency/AllParameterFileRepository.h"
00003 #include "Persistency/ScoreFileRepository.h"
00004 #include "Persistency/KernelMatrixRepository.h"
00005 #include "Persistency/FoldRepository.h"
00006 #include "Persistency/ImageSetRepository.h"
00007 #include "Persistency/AnnotationTableSetRepository.h"
00008 #include "Persistency/AnnotationTableRepository.h"
00009 #include "Persistency/QuidTableRepository.h"
00010 #include "Persistency/FeatureTableRepository.h"
00011 #include "Persistency/Mpeg7DocRepository.h"
00012 #include "Persistency/ImageArchiveRepository.h"
00013 #include "Persistency/VideoSetRepository.h"
00014 #include "Persistency/SegmentationRepository.h"
00015 #include "Persistency/KeyframesRepository.h"
00016 #include "Persistency/StillsRepository.h"
00017 #include "Persistency/KeywordListRepository.h"
00018 #include "Persistency/SimilarityTableSetRepository.h"
00019 #include "Persistency/BestFileRepository.h"
00020 #include "Persistency/SvmProblemRepository.h"
00021 #include "Persistency/SvmRepository.h"
00022 #include "Persistency/FrameHashesRepository.h"
00023 #include "Core/Table/KeywordListDiff.h"
00024 #include "Core/Training/BestFile.h"
00025 #include "Core/Table/SetQuidSet.h"
00026 #include "Core/Database/MakeRawDataSet.h"
00027 #include "Core/Stream/RgbDataSrc.h"
00028 
00029 // since we are not using libraries:
00030 #include "Link/ImpalaLib.cpp"
00031 
00032 namespace Impala
00033 {
00034 namespace Application
00035 {
00036 namespace Repository
00037 {
00038 
00039 
00040 using namespace Persistency;
00041 
00042 using Core::Array::ImageArchive;
00043 using Core::Database::RawDataSet;
00044 using Core::ImageSet::ImageSet;
00045 using Core::VideoSet::VideoSet;
00046 using Core::VideoSet::Segmentation;
00047 using Core::VideoSet::Keyframes;
00048 using Core::VideoSet::Stills;
00049 using Core::VideoSet::Mpeg7Doc;
00050 using Core::Table::QuidTable;
00051 using Core::Table::AnnotationTable;
00052 using Core::Table::AnnotationTableSet;
00053 using Core::Table::KeywordList;
00054 using Core::Table::SimilarityTableSet;
00055 using Core::Feature::FeatureTable;
00056 using Core::Training::Svm;
00057 using Core::Training::FikSvm;
00058 using Core::Training::KernelMatrix;
00059 using Core::Stream::RgbDataSrc;
00060 
00061 // Convenience functions
00062 
00063 RawDataSet*
00064 GetRawDataSet(String locString, String setName, bool required)
00065 {
00066     ILOG_VAR(Impala.Application.Repository.GetRawDataSet);
00067 
00068     Locator loc(locString, setName);
00069     RawDataSet* dataSet = 0;
00070     if (VideoSetsRepository::GetInstance().Contains(setName))
00071     {
00072         if (required)
00073             dataSet = VideoSetRepository().Get(loc);
00074         else if (VideoSetRepository().Exists(loc))
00075             dataSet = VideoSetRepository().Get(loc);
00076     }
00077     else if (ImageSetsRepository::GetInstance().Contains(setName))
00078     {
00079         ImageSetLocator imSetLoc(loc, "");
00080         if (required)
00081             dataSet = ImageSetRepository().Get(imSetLoc);
00082         else if (ImageSetRepository().Exists(imSetLoc))
00083             dataSet = ImageSetRepository().Get(imSetLoc);
00084     }
00085     else if (required)
00086     {
00087         ILOG_ERROR("Could not find " << loc);
00088     }
00089     return dataSet;
00090 }
00091 
00092 RawDataSet*
00093 GetRawDataSet(CmdOptions& options, bool required)
00094 {
00095     ILOG_VAR(Impala.Application.Repository.GetRawDataSet);
00096 
00097     int a = 1;
00098     String locString = options.GetArg(a++);
00099     String setName = options.GetArg(a++);
00100     return GetRawDataSet(locString, setName, required);
00101 }
00102 
00103 ImageSet*
00104 GetImageSet(String locString, String setName, bool required)
00105 {
00106     ILOG_VAR(Impala.Application.Repository.GetImageSet);
00107 
00108     ImageSetLocator loc(locString, setName);
00109     ImageSet* imSet = 0;
00110     if (ImageSetsRepository::GetInstance().Contains(setName))
00111     {
00112         if (required)
00113             imSet = ImageSetRepository().Get(loc);
00114         else if (ImageSetRepository().Exists(loc))
00115             imSet = ImageSetRepository().Get(loc);
00116     }
00117     else if (required)
00118     {
00119         ILOG_ERROR("Could not find " << loc);
00120     }
00121     return imSet;
00122 }
00123 
00124 ImageSet*
00125 GetImageSet(CmdOptions& options, bool required, bool getSrcLoc = true)
00126 {
00127     ILOG_VAR(Impala.Application.Repository.GetImageSet);
00128 
00129     int nrArg = 2;
00130     if (!getSrcLoc)
00131         nrArg++;
00132     if (options.GetNrArg() < nrArg)
00133     {
00134         ILOG_ERROR("Need at least " << nrArg << " parameters");
00135     }
00136     int a = 1;
00137     String locString = options.GetArg(a++);
00138     String setName = options.GetArg(a++);
00139     if (!getSrcLoc)
00140         locString = options.GetArg(a++);
00141     return GetImageSet(locString, setName, required);
00142 }
00143 
00144 VideoSet*
00145 GetVideoSet(String locString, String setName, bool required)
00146 {
00147     ILOG_VAR(Impala.Application.Repository.GetVideoSet);
00148 
00149     Locator loc(locString, setName);
00150     VideoSet* vidSet = 0;
00151     if (VideoSetsRepository::GetInstance().Contains(setName))
00152     {
00153         if (required)
00154             vidSet = VideoSetRepository().Get(loc);
00155         else if (VideoSetRepository().Exists(loc))
00156             vidSet = VideoSetRepository().Get(loc);
00157     }
00158     else if (required)
00159     {
00160         ILOG_ERROR("Could not find " << loc);
00161     }
00162     return vidSet;
00163 }
00164 
00165 VideoSet*
00166 GetVideoSet(CmdOptions& options, bool required, bool getSrcLoc = true)
00167 {
00168     ILOG_VAR(Impala.Application.Repository.GetVideoSet);
00169 
00170     int nrArg = 2;
00171     if (!getSrcLoc)
00172         nrArg++;
00173     if (options.GetNrArg() < nrArg)
00174     {
00175         ILOG_ERROR("Need at least " << nrArg << " parameters");
00176     }
00177     int a = 1;
00178     String locString = options.GetArg(a++);
00179     String setName = options.GetArg(a++);
00180     if (!getSrcLoc)
00181         locString = options.GetArg(a++);
00182     return GetVideoSet(locString, setName, required);
00183 }
00184 
00185 Locator
00186 GetDataSetLocator(CmdOptions& options, bool getSrcLoc = true)
00187 {
00188     ILOG_VAR(Impala.Application.Repository.GetVideoSet);
00189 
00190     int nrArg = 2;
00191     if (!getSrcLoc)
00192         nrArg++;
00193     if (options.GetNrArg() < nrArg)
00194     {
00195         ILOG_ERROR("Need at least " << nrArg << " parameters");
00196     }
00197     int a = 1;
00198     String locString = options.GetArg(a++);
00199     String setName = options.GetArg(a++);
00200     if (!getSrcLoc)
00201         locString = options.GetArg(a++);
00202     return Locator(locString, setName);
00203 }
00204 
00205 // ImageSets part
00206 
00207 void
00208 DoDumpImageSets()
00209 {
00210     ImageSetsRepository::GetInstance().Dump();
00211 }
00212 
00213 // VideoSets part
00214 
00215 void
00216 DoDumpVideoSets()
00217 {
00218     VideoSetsRepository::GetInstance().Dump();
00219 }
00220 
00221 void
00222 DoCopyVideoSets()
00223 {
00224     ILOG_VAR(Impala.Application.Repository.DoCopyVideoSets);
00225     CmdOptions& options = CmdOptions::GetInstance();
00226 
00227     String locString = options.GetArg(1);
00228     Locator dstLoc(options.GetArg(1), "dummy");
00229     VideoSetsRepository::GetInstance().CopyTo(dstLoc);
00230 }
00231 
00232 // ImageSet part
00233 
00234 void
00235 DoDumpImageSet()
00236 {
00237     ILOG_VAR(Impala.Application.Repository.DoDumpImageSet);
00238     CmdOptions& options = CmdOptions::GetInstance();
00239 
00240     ImageSet* imSet = GetImageSet(options, true);
00241     ILOG_INFO("nrDirs = " << imSet->NrDirs());
00242     ILOG_INFO("nrFiles = " << imSet->NrFiles());
00243     int minNr = imSet->GetNrFiles(0);
00244     int maxNr = imSet->GetNrFiles(0);
00245     for (int i=1 ; i<imSet->NrDirs() ; i++)
00246     {
00247         int nr = imSet->GetNrFiles(i);
00248         if (nr < minNr)
00249             minNr = nr;
00250         if (nr > maxNr)
00251             maxNr = nr;
00252     }
00253     ILOG_INFO("minNrFiles/dir = " << minNr << ", maxNrFiles/dir = " << maxNr);
00254     if (options.GetInt("end") == 0)
00255         return;
00256     imSet->Dump(0, -1, options.GetInt("start"), options.GetInt("end"));
00257     delete imSet;
00258 }
00259 
00260 void
00261 DoDiffImageSet()
00262 {
00263     ILOG_VAR(Impala.Application.Repository.DoDiffImageSet);
00264     CmdOptions& options = CmdOptions::GetInstance();
00265 
00266     ImageSet* imSet1 = GetImageSet(options, true);
00267     ImageSet* imSet2 = GetImageSet(options, true, false);
00268     imSet1->Diff(imSet2);
00269     delete imSet2;
00270     delete imSet1;
00271 }
00272 
00273 void
00274 DoCopyImageSet()
00275 {
00276     ILOG_VAR(Impala.Application.Repository.DoCopyImageSet);
00277     CmdOptions& options = CmdOptions::GetInstance();
00278 
00279     String locString1 = options.GetArg(1);
00280     String setName = options.GetArg(2);
00281     String locString2 = options.GetArg(3);
00282     ImageSet* imSet = GetImageSet(options, true);
00283     ImageSetLocator setLoc2(locString2, setName);
00284     if (options.GetBool("sync"))
00285         ImageSetRepository().Sync(setLoc2, imSet);
00286     else
00287         ImageSetRepository().Add(setLoc2, imSet);
00288     delete imSet;
00289 }
00290 
00291 void
00292 DoDeleteImageSet()
00293 {
00294     ILOG_VAR(Impala.Application.Repository.DoDeleteImageSet);
00295     CmdOptions& options = CmdOptions::GetInstance();
00296 
00297     String locString = options.GetArg(1);
00298     String setName = options.GetArg(2);
00299     ImageSetLocator loc(locString, setName);
00300     ImageSetRepository().Delete(loc);
00301 }
00302 
00303 void
00304 DoSyncImageFiles()
00305 {
00306     ILOG_VAR(Impala.Application.Repository.DoSyncImageFiles);
00307     CmdOptions& options = CmdOptions::GetInstance();
00308 
00309     String locString1 = options.GetArg(1);
00310     String setName = options.GetArg(2);
00311     String locString2 = options.GetArg(3);
00312 
00313     ImageSet* imSet = GetImageSet(options, true);
00314     for (int i=0 ; i<imSet->NrFiles() ; i++)
00315     {
00316         String path = FileNameConcat("ImageData", imSet->GetAsPath(i));
00317         FileLocator srcLoc(locString1, setName, path);
00318         FileLocator dstLoc(locString2, setName, path);
00319         RepositoryInFileSystem::GetInstance().CopyFile(srcLoc, dstLoc);
00320     }
00321     delete imSet;
00322 }
00323 
00324 // ImageSetSpecial part
00325 
00326 ImageSetLocator
00327 GetImageSetLocator(CmdOptions& options, bool getSrcLoc)
00328 {
00329     ILOG_VAR(Impala.Application.Repository.GetImageSetLocator);
00330 
00331     int nrArg = 3;
00332     if (!getSrcLoc)
00333         nrArg++;
00334     if (options.GetNrArg() < nrArg)
00335     {
00336         ILOG_ERROR("Need at least " << nrArg << " parameters");
00337     }
00338 
00339     int a = 1;
00340     String locString = options.GetArg(a++);
00341     String videoSetName = options.GetArg(a++);
00342     String imageSetName = options.GetArg(a++);
00343     if (!getSrcLoc)
00344         locString = options.GetArg(a++);
00345     return ImageSetLocator(locString, videoSetName, imageSetName);
00346 }
00347 
00348 void
00349 DoDumpImageSetSpecial()
00350 {
00351     ILOG_VAR(Impala.Application.Repository.DoDumpImageSetSpecial);
00352     CmdOptions& options = CmdOptions::GetInstance();
00353 
00354     ImageSetLocator loc = GetImageSetLocator(options, true);
00355     ImageSet* imSet = ImageSetRepository().Get(loc);
00356     imSet->Dump(0, -1, options.GetInt("start"), options.GetInt("end"));
00357     delete imSet;
00358 }
00359 
00360 void
00361 DoDiffImageSetSpecial()
00362 {
00363     ILOG_VAR(Impala.Application.Repository.DoDiffImageSetSpecial);
00364     CmdOptions& options = CmdOptions::GetInstance();
00365 
00366     ImageSetLocator loc1 = GetImageSetLocator(options, true);
00367     ImageSet* imSet1 = ImageSetRepository().Get(loc1);
00368     ImageSetLocator loc2 = GetImageSetLocator(options, false);
00369     ImageSet* imSet2 = ImageSetRepository().Get(loc2);
00370 
00371     imSet1->Diff(imSet2);
00372 
00373     delete imSet2;
00374     delete imSet1;
00375 }
00376 
00377 void
00378 DoCopyImageSetSpecial()
00379 {
00380     ILOG_VAR(Impala.Application.Repository.DoCopyImageSetSpecial);
00381     CmdOptions& options = CmdOptions::GetInstance();
00382 
00383     ImageSetLocator loc1 = GetImageSetLocator(options, true);
00384     ImageSet* imSet = ImageSetRepository().Get(loc1);
00385 
00386     ImageSetLocator loc2 = GetImageSetLocator(options, false);
00387     ImageSetRepository().Add(loc2, imSet);
00388     delete imSet;
00389 }
00390 
00391 void
00392 DoDeleteImageSetSpecial()
00393 {
00394     ILOG_VAR(Impala.Application.Repository.DoDeleteImageSetSpecial);
00395     CmdOptions& options = CmdOptions::GetInstance();
00396 
00397     ImageSetLocator loc = GetImageSetLocator(options, true);
00398     ImageSetRepository().Delete(loc);
00399 }
00400 
00401 // VideoSet part
00402 
00403 void
00404 DoDumpVideoSet()
00405 {
00406     ILOG_VAR(Impala.Application.Repository.DoDumpVideoSet);
00407     CmdOptions& options = CmdOptions::GetInstance();
00408 
00409     VideoSet* vidSet = GetVideoSet(options, true);
00410     vidSet->Dump(0, -1, options.GetInt("start"), options.GetInt("end"));
00411     delete vidSet;
00412 }
00413 
00414 void
00415 DoDiffVideoSet()
00416 {
00417     ILOG_VAR(Impala.Application.Repository.DoDiffVideoSet);
00418     CmdOptions& options = CmdOptions::GetInstance();
00419 
00420     VideoSet* vidSet1 = GetVideoSet(options, true);
00421     VideoSet* vidSet2 = GetVideoSet(options, true, false);
00422     vidSet1->Diff(vidSet2);
00423     delete vidSet2;
00424     delete vidSet1;
00425 }
00426 
00427 void
00428 DoCopyVideoSet()
00429 {
00430     ILOG_VAR(Impala.Application.Repository.DoCopyVideoSet);
00431     CmdOptions& options = CmdOptions::GetInstance();
00432 
00433     String locString1 = options.GetArg(1);
00434     String setName = options.GetArg(2);
00435     String locString2 = options.GetArg(3);
00436     VideoSet* vidSet = GetVideoSet(options, true);
00437     Locator setLoc2(locString2, setName);
00438     if (options.GetBool("sync"))
00439         VideoSetRepository().Sync(setLoc2, vidSet);
00440     else
00441         VideoSetRepository().Add(setLoc2, vidSet);
00442     delete vidSet;
00443 }
00444 
00445 void
00446 DoDeleteVideoSet()
00447 {
00448     ILOG_VAR(Impala.Application.Repository.DoDeleteVideoSet);
00449     CmdOptions& options = CmdOptions::GetInstance();
00450 
00451     String locString = options.GetArg(1);
00452     String setName = options.GetArg(2);
00453     Locator loc(locString, setName);
00454     VideoSetRepository().Delete(loc);
00455 }
00456 
00457 void
00458 DoSyncVideoFiles()
00459 {
00460     ILOG_VAR(Impala.Application.Repository.DoSyncVideoFiles);
00461     CmdOptions& options = CmdOptions::GetInstance();
00462 
00463     String locString1 = options.GetArg(1);
00464     String setName = options.GetArg(2);
00465     bool doInfoFiles = StringToBool(options.GetArg(3));
00466     String locString2 = options.GetArg(4);
00467 
00468     VideoSet* vidSet = GetVideoSet(options, true);
00469     for (int i=0 ; i<vidSet->NrFiles() ; i++)
00470     {
00471         String path = FileNameConcat("VideoData", vidSet->GetAsPath(i));
00472         FileLocator srcLoc(locString1, setName, path);
00473         FileLocator dstLoc(locString2, setName, path);
00474         RepositoryInFileSystem::GetInstance().CopyFile(srcLoc, dstLoc);
00475         if (doInfoFiles)
00476         {
00477             String path = FileNameConcat("VideoData",
00478                                          vidSet->GetAsPath(i) + ".info");
00479             FileLocator srcLoc(locString1, setName, path);
00480             FileLocator dstLoc(locString2, setName, path);
00481             RepositoryInFileSystem::GetInstance().CopyFile(srcLoc, dstLoc);
00482         }
00483     }
00484     delete vidSet;
00485 }
00486 
00487 // Function is not consistent with others, awaiting RgbDataSrc refactoring
00488 void
00489 DoDeleteVideoInfoFiles()
00490 {
00491     ILOG_VAR(Impala.Application.Repository.DoDeleteVideoInfoFiles);
00492     CmdOptions& options = CmdOptions::GetInstance();
00493 
00494     VideoSet* vidSet = GetVideoSet(options, false);
00495     if (vidSet)
00496     {
00497         for (int i=0 ; i<vidSet->NrFiles() ; i++)
00498             vidSet->DeleteVideoInfoFile(i);
00499         delete vidSet;
00500     }
00501 }
00502 
00503 // frame hashes part
00504 
00505 void
00506 DoDumpFrameHashes()
00507 {
00508     ILOG_VAR(Impala.Application.Repository.DoDumpFrameHashes);
00509     CmdOptions& options = CmdOptions::GetInstance();
00510 
00511     Locator vidSetLocator = GetDataSetLocator(options, true);
00512     VideoSet* vidSet = GetVideoSet(options, true);
00513     if (vidSet == 0)
00514         return;
00515     int nrOfVideos = vidSet->NrFiles();
00516     for (int i = 0; i < nrOfVideos; i++)
00517     {
00518         FrameHashesLocator fhLoc(vidSetLocator, vidSet->GetContainer(i));
00519         Core::VideoSet::FrameHashes* hashTable = 
00520             FrameHashesRepository().Get(fhLoc);
00521         if (hashTable != 0)
00522         {
00523             hashTable->Dump();
00524             delete hashTable;
00525         }
00526     }
00527     delete vidSet;
00528 }
00529 
00530 void
00531 DoDiffFrameHashes()
00532 {
00533     ILOG_VAR(Impala.Application.Repository.DoDiffFrameHashes);
00534     CmdOptions& options = CmdOptions::GetInstance();
00535 
00536     Locator vs1Loc = GetDataSetLocator(options, true);
00537     Locator vs2Loc = GetDataSetLocator(options, false);
00538     VideoSet* vidSet1 = GetVideoSet(options, true, true);
00539     if (vidSet1 == 0)
00540         return;
00541     VideoSet* vidSet2 = GetVideoSet(options, true, false);
00542     if (vidSet2 == 0)
00543     {
00544         delete vidSet1;
00545         return;
00546     }
00547     int nrOfVideos1 = vidSet1->NrFiles();
00548     int nrOfVideos2 = vidSet2->NrFiles();
00549     if (nrOfVideos1 != nrOfVideos2)
00550     {
00551         ILOG_ERROR("Different file counts: " << nrOfVideos1 <<
00552             " vs. " << nrOfVideos2);
00553         delete vidSet1;
00554         delete vidSet2;
00555         return;
00556     }
00557     for (int i = 0; i < nrOfVideos1; i++)
00558     {
00559         FrameHashesLocator fh1Loc(vs1Loc, vidSet1->GetContainer(i));
00560         Core::VideoSet::FrameHashes* hashTable1 = 
00561             FrameHashesRepository().Get(fh1Loc);
00562         FrameHashesLocator fh2Loc(vs2Loc, vidSet2->GetContainer(i));
00563         Core::VideoSet::FrameHashes* hashTable2 = 
00564             FrameHashesRepository().Get(fh2Loc);
00565         if (hashTable1 != 0 && hashTable2 != 0)
00566             if (hashTable1->Diff(hashTable2) != 0)
00567                 ILOG_ERROR("Found difference for: " << vidSet1->GetContainer(i));
00568         if (hashTable1 != 0)
00569             delete hashTable1;
00570         if (hashTable2 != 0)
00571             delete hashTable2;
00572     }
00573     delete vidSet2;
00574     delete vidSet1;
00575 }
00576 
00577 void
00578 DoCopyFrameHashes()
00579 {
00580     ILOG_VAR(Impala.Application.Repository.DoCopyFrameHashes);
00581     CmdOptions& options = CmdOptions::GetInstance();
00582 
00583     ILOG_ERROR("Not yet implemented")
00584 }
00585 
00586 // Segmentation part
00587 
00588 SegmentationLocator
00589 GetSegmentationLocator(CmdOptions& options, bool getSrcLoc)
00590 {
00591     ILOG_VAR(Impala.Application.Repository.GetSegmentationLocator);
00592 
00593     int nrArg = 2;
00594     if (!getSrcLoc)
00595         nrArg++;
00596     if (options.GetNrArg() < nrArg)
00597     {
00598         ILOG_ERROR("Need at least " << nrArg << " parameters");
00599     }
00600 
00601     int a = 1;
00602     String locString = options.GetArg(a++);
00603     String setName = options.GetArg(a++);
00604     if (!getSrcLoc)
00605         locString = options.GetArg(a++);
00606     return SegmentationLocator(locString, setName, "segmentation");
00607 }
00608 
00609 void
00610 DoDumpSegmentation()
00611 {
00612     ILOG_VAR(Impala.Application.Repository.DoDumpSegmentation);
00613     CmdOptions& options = CmdOptions::GetInstance();
00614 
00615     SegmentationLocator loc = GetSegmentationLocator(options, true);
00616     VideoSet* vidSet = GetVideoSet(options, true);
00617     Segmentation* seg = SegmentationRepository().Get(loc, vidSet);
00618     ILOG_INFO("nrVideos = " << seg->GetNrVideos());
00619     ILOG_INFO("nrShots = " << seg->GetNrShots());
00620     ILOG_INFO("nrFrames = " << seg->GetTotalNrFrames());
00621     if (options.GetInt("end") == 0)
00622         return;
00623     int minNr = 10000000;
00624     int maxNr = 0;
00625     for (int i=0 ; i<seg->GetNrVideos() ; i++)
00626     {
00627         int nrFrames = seg->GetNrFramesVideo(i);
00628         std::cout << "  vid " << i << " has " << seg->GetNrShotsVideo(i)
00629                   << " shots and " << nrFrames << " frames" << std::endl;
00630         if (nrFrames < minNr)
00631             minNr = nrFrames;
00632         if (nrFrames > maxNr)
00633             maxNr = nrFrames;
00634     }
00635     std::cout << "  min nr frames = " << minNr << ", max nr = " << maxNr
00636               << std::endl;
00637     seg->Dump(options.GetInt("start"), options.GetInt("end"));
00638     delete seg;
00639     delete vidSet;
00640 }
00641 
00642 void
00643 DoDiffSegmentation()
00644 {
00645     ILOG_VAR(Impala.Application.Repository.DoDiffSegmentation);
00646     CmdOptions& options = CmdOptions::GetInstance();
00647 
00648     SegmentationLocator loc1 = GetSegmentationLocator(options, true);
00649     VideoSet* vidSet1 = GetVideoSet(options, true);
00650     Segmentation* seg1 = SegmentationRepository().Get(loc1, vidSet1);
00651 
00652     SegmentationLocator loc2 = GetSegmentationLocator(options, false);
00653     VideoSet* vidSet2 = VideoSetRepository().Get(loc2);
00654     Segmentation* seg2 = SegmentationRepository().Get(loc2, vidSet2);
00655 
00656     seg1->Diff(seg2);
00657 
00658     delete seg2;
00659     delete seg1;
00660     delete vidSet2;
00661     delete vidSet1;
00662 }
00663 
00664 void
00665 DoCopySegmentation()
00666 {
00667     ILOG_VAR(Impala.Application.Repository.DoCopySegmentation);
00668     CmdOptions& options = CmdOptions::GetInstance();
00669 
00670     SegmentationLocator loc1 = GetSegmentationLocator(options, true);
00671     VideoSet* vidSet = GetVideoSet(options, true);
00672     Segmentation* seg = SegmentationRepository().Get(loc1, vidSet);
00673 
00674     SegmentationLocator loc2 = GetSegmentationLocator(options, false);
00675     if (options.GetBool("sync"))
00676         SegmentationRepository().Sync(loc2, seg);
00677     else
00678         SegmentationRepository().Add(loc2, seg);
00679     delete seg;
00680     delete vidSet;
00681 }
00682 
00683 void
00684 DoDeleteSegmentation()
00685 {
00686     ILOG_VAR(Impala.Application.Repository.DoDeleteSegmentation);
00687     CmdOptions& options = CmdOptions::GetInstance();
00688 
00689     SegmentationLocator loc = GetSegmentationLocator(options, true);
00690     SegmentationRepository().Delete(loc);
00691 }
00692 
00693 // Keyframes part
00694 
00695 KeyframesLocator
00696 GetKeyframesLocator(CmdOptions& options, bool getSrcLoc)
00697 {
00698     ILOG_VAR(Impala.Application.Repository.GetKeyframesLocator);
00699 
00700     int nrArg = 2;
00701     if (!getSrcLoc)
00702         nrArg++;
00703     if (options.GetNrArg() < nrArg)
00704     {
00705         ILOG_ERROR("Need at least " << nrArg << " parameters");
00706     }
00707 
00708     int a = 1;
00709     String locString = options.GetArg(a++);
00710     String setName = options.GetArg(a++);
00711     if (!getSrcLoc)
00712         locString = options.GetArg(a++);
00713     return KeyframesLocator(locString, setName, "keyframes");
00714 }
00715 
00716 void
00717 DoDumpKeyframes()
00718 {
00719     ILOG_VAR(Impala.Application.Repository.DoDumpKeyframes);
00720     CmdOptions& options = CmdOptions::GetInstance();
00721 
00722     KeyframesLocator loc = GetKeyframesLocator(options, true);
00723     VideoSet* vidSet = GetVideoSet(options, true);
00724     Keyframes* keys = KeyframesRepository().Get(loc, vidSet);
00725 
00726     ILOG_INFO("nrVideos = " << keys->GetNrVideos());
00727     ILOG_INFO("nrShots = " << keys->GetNrShots());
00728     ILOG_INFO("nrKeyframes = " << keys->GetNrKeyframes());
00729     if (options.GetInt("end") == 0)
00730         return;
00731     for (int i=0 ; i<keys->GetNrVideos() ; i++)
00732         std::cout << "  vid " << i << " has " << keys->GetNrKeyframesVideo(i)
00733                   << " keyframes" << std::endl;
00734     //keys.DumpGroups();
00735     keys->Dump(options.GetInt("start"), options.GetInt("end"));
00736     delete keys;
00737     delete vidSet;
00738 }
00739 
00740 void
00741 DoDiffKeyframes()
00742 {
00743     ILOG_VAR(Impala.Application.Repository.DoDiffKeyframes);
00744     CmdOptions& options = CmdOptions::GetInstance();
00745 
00746     KeyframesLocator loc1 = GetKeyframesLocator(options, true);
00747     VideoSet* vidSet1 = GetVideoSet(options, true);
00748     Keyframes* keys1 = KeyframesRepository().Get(loc1, vidSet1);
00749 
00750     KeyframesLocator loc2 = GetKeyframesLocator(options, false);
00751     VideoSet* vidSet2 = VideoSetRepository().Get(loc2);
00752     Keyframes* keys2 = KeyframesRepository().Get(loc2, vidSet2);
00753 
00754     keys1->Diff(keys2);
00755 
00756     delete keys2;
00757     delete keys1;
00758     delete vidSet2;
00759     delete vidSet1;
00760 }
00761 
00762 void
00763 DoCopyKeyframes()
00764 {
00765     ILOG_VAR(Impala.Application.Repository.DoCopyKeyframes);
00766     CmdOptions& options = CmdOptions::GetInstance();
00767 
00768     KeyframesLocator loc1 = GetKeyframesLocator(options, true);
00769     VideoSet* vidSet = GetVideoSet(options, true);
00770     Keyframes* keys = KeyframesRepository().Get(loc1, vidSet);
00771 
00772     KeyframesLocator loc2 = GetKeyframesLocator(options, false);
00773     if (options.GetBool("sync"))
00774         KeyframesRepository().Sync(loc2, keys);
00775     else
00776         KeyframesRepository().Add(loc2, keys);
00777     delete keys;
00778     delete vidSet;
00779 }
00780 
00781 void
00782 DoDeleteKeyframes()
00783 {
00784     ILOG_VAR(Impala.Application.Repository.DoDeleteKeyframes);
00785     CmdOptions& options = CmdOptions::GetInstance();
00786 
00787     KeyframesLocator loc = GetKeyframesLocator(options, true);
00788     KeyframesRepository().Delete(loc);
00789 }
00790 
00791 // Stills part
00792 
00793 StillsLocator
00794 GetStillsLocator(CmdOptions& options, bool getSrcLoc)
00795 {
00796     ILOG_VAR(Impala.Application.Repository.GetStillsLocator);
00797 
00798     int nrArg = 2;
00799     if (!getSrcLoc)
00800         nrArg++;
00801     if (options.GetNrArg() < nrArg)
00802     {
00803         ILOG_ERROR("Need at least " << nrArg << " parameters");
00804     }
00805 
00806     int a = 1;
00807     String locString = options.GetArg(a++);
00808     String setName = options.GetArg(a++);
00809     if (!getSrcLoc)
00810         locString = options.GetArg(a++);
00811     return StillsLocator(locString, setName, "stills");
00812 }
00813 
00814 void
00815 DoDumpStills()
00816 {
00817     ILOG_VAR(Impala.Application.Repository.DoDumpStills);
00818     CmdOptions& options = CmdOptions::GetInstance();
00819 
00820     StillsLocator loc = GetStillsLocator(options, true);
00821     VideoSet* vidSet = GetVideoSet(options, true);
00822     Stills* stills = StillsRepository().Get(loc, vidSet);
00823 
00824     ILOG_INFO("nrVideos = " << stills->GetNrVideos());
00825     ILOG_INFO("nrShots = " << stills->GetNrShots());
00826     ILOG_INFO("nrStills = " << stills->GetNrStills());
00827     //stills->DumpGroups();
00828     stills->Dump(options.GetInt("start"), options.GetInt("end"));
00829     delete stills;
00830     delete vidSet;
00831 }
00832 
00833 void
00834 DoDiffStills()
00835 {
00836     ILOG_VAR(Impala.Application.Repository.DoDiffStills);
00837     CmdOptions& options = CmdOptions::GetInstance();
00838 
00839     StillsLocator loc1 = GetStillsLocator(options, true);
00840     VideoSet* vidSet1 = GetVideoSet(options, true);
00841     Stills* stills1 = StillsRepository().Get(loc1, vidSet1);
00842 
00843     StillsLocator loc2 = GetStillsLocator(options, false);
00844     VideoSet* vidSet2 = VideoSetRepository().Get(loc2);
00845     Stills* stills2 = StillsRepository().Get(loc2, vidSet2);
00846 
00847     stills1->Diff(stills2);
00848 
00849     delete stills2;
00850     delete stills1;
00851     delete vidSet2;
00852     delete vidSet1;
00853 }
00854 
00855 void
00856 DoCopyStills()
00857 {
00858     ILOG_VAR(Impala.Application.Repository.DoCopyStills);
00859     CmdOptions& options = CmdOptions::GetInstance();
00860 
00861     StillsLocator loc1 = GetStillsLocator(options, true);
00862     VideoSet* vidSet = GetVideoSet(options, true);
00863     Stills* stills = StillsRepository().Get(loc1, vidSet);
00864 
00865     StillsLocator loc2 = GetStillsLocator(options, false);
00866     if (options.GetBool("sync"))
00867         StillsRepository().Sync(loc2, stills);
00868     else
00869         StillsRepository().Add(loc2, stills);
00870     delete stills;
00871     delete vidSet;
00872 }
00873 
00874 void
00875 DoDeleteStills()
00876 {
00877     ILOG_VAR(Impala.Application.Repository.DoDeleteStills);
00878     CmdOptions& options = CmdOptions::GetInstance();
00879 
00880     StillsLocator loc = GetStillsLocator(options, true);
00881     StillsRepository().Delete(loc);
00882 }
00883 
00884 // QuidTable part
00885 
00886 QuidTableLocator
00887 GetQuidTableLocator(CmdOptions& options, bool getSrcLoc)
00888 {
00889     ILOG_VAR(Impala.Application.Repository.GetQuidTableLocator);
00890 
00891     int nrArg = 5;
00892     if (!getSrcLoc)
00893         nrArg++;
00894     if (options.GetNrArg() < nrArg)
00895     {
00896         ILOG_ERROR("Need at least " << nrArg << " parameters");
00897     }
00898 
00899     int a = 1;
00900     String locString = options.GetArg(a++);
00901     String setName = options.GetArg(a++);
00902     String dir = options.GetArg(a++);
00903     String name = options.GetArg(a++);
00904     if (!getSrcLoc)
00905         locString = options.GetArg(a++);
00906     return QuidTableLocator(locString, setName, dir, name);
00907 }
00908 
00909 void
00910 DoDumpQuidTable()
00911 {
00912     ILOG_VAR(Impala.Application.Repository.DoDumpQuidTable);
00913     CmdOptions& options = CmdOptions::GetInstance();
00914 
00915     QuidTableLocator loc = GetQuidTableLocator(options, true);
00916     QuidTable* tab = QuidTableRepository().Get(loc);
00917     if (tab == 0)
00918         return;
00919     RawDataSet* dataSet = GetRawDataSet(options, false);
00920     tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00921     delete tab;
00922     if (dataSet)
00923         delete dataSet;
00924 }
00925 
00926 void
00927 DoDiffQuidTable()
00928 {
00929     ILOG_VAR(Impala.Application.Repository.DoDiffQuidTable);
00930     CmdOptions& options = CmdOptions::GetInstance();
00931 
00932     QuidTableLocator loc1 = GetQuidTableLocator(options, true);
00933     QuidTable* tab1 = QuidTableRepository().Get(loc1);
00934     if (tab1 == 0)
00935         return;
00936     QuidTableLocator loc2 = GetQuidTableLocator(options, false);
00937     QuidTable* tab2 = QuidTableRepository().Get(loc2);
00938     tab1->Diff(tab2);
00939     delete tab2;
00940     delete tab1;
00941 }
00942 
00943 void
00944 DoCopyQuidTable()
00945 {
00946     ILOG_VAR(Impala.Application.Repository.DoCopyQuidTable);
00947     CmdOptions& options = CmdOptions::GetInstance();
00948 
00949     QuidTableLocator loc1 = GetQuidTableLocator(options, true);
00950     QuidTable* tab = QuidTableRepository().Get(loc1);
00951     if (tab == 0)
00952         return;
00953     QuidTableLocator loc2 = GetQuidTableLocator(options, false);
00954     QuidTableRepository().Add(loc2, tab);
00955     delete tab;
00956 }
00957 
00958 void
00959 DoDeleteQuidTable()
00960 {
00961     ILOG_VAR(Impala.Application.Repository.DoDeleteQuidTable);
00962     CmdOptions& options = CmdOptions::GetInstance();
00963 
00964     QuidTableLocator loc = GetQuidTableLocator(options, true);
00965     QuidTableRepository().Delete(loc);
00966 }
00967 
00968 // Mpeg7Doc part
00969 
00970 Mpeg7DocLocator
00971 GetMpeg7ShotLocator(CmdOptions& options, bool getSrcLoc)
00972 {
00973     ILOG_VAR(Impala.Application.Repository.GetMpeg7ShotLocator);
00974 
00975     int nrArg = 4;
00976     if (!getSrcLoc)
00977         nrArg++;
00978     if (options.GetNrArg() < nrArg)
00979     {
00980         ILOG_ERROR("Need at least " << nrArg << " parameters");
00981     }
00982 
00983     int a = 1;
00984     String locString = options.GetArg(a++);
00985     String setName = options.GetArg(a++);
00986     String container = options.GetArg(a++);
00987     if (!getSrcLoc)
00988         locString = options.GetArg(a++);
00989     return Mpeg7DocLocator(locString, setName, Mpeg7DocLocator::MPEG7_SHOT,
00990                            container, "dummy");
00991 }
00992 
00993 void
00994 DoDumpMpeg7Shot()
00995 {
00996     ILOG_VAR(Impala.Application.Repository.DoDumpMpeg7Shot);
00997     CmdOptions& options = CmdOptions::GetInstance();
00998 
00999     Mpeg7DocLocator loc = GetMpeg7ShotLocator(options, true);
01000     VideoSet* videoSet = GetVideoSet(options, true);
01001     String container = loc.GetContainer();
01002     int nrDocs = (container == "ALL") ? videoSet->GetNrContainers() : 1;
01003     for (int i=0 ; i<nrDocs ; i++)
01004     {
01005         String cur = (container == "ALL") ? videoSet->GetContainer(i) : container;
01006         loc.SetContainer(cur);
01007         String name = FileNameBase(cur) + ".xml";
01008         loc.SetName(name);
01009         Mpeg7Doc* doc = Mpeg7DocRepository().Get(loc);
01010         doc->Dump(options.GetInt("start"), options.GetInt("end"));
01011         delete doc;
01012     }
01013     delete videoSet;
01014 }
01015 
01016 void
01017 DoDiffMpeg7Shot()
01018 {
01019     ILOG_VAR(Impala.Application.Repository.DoDiffMpeg7Shot);
01020     CmdOptions& options = CmdOptions::GetInstance();
01021 
01022     Mpeg7DocLocator loc1 = GetMpeg7ShotLocator(options, true);
01023     Mpeg7DocLocator loc2 = GetMpeg7ShotLocator(options, false);
01024     VideoSet* videoSet = GetVideoSet(options, true);
01025     String container = loc1.GetContainer();
01026     int nrDocs = (container == "ALL") ? videoSet->GetNrContainers() : 1;
01027     for (int i=0 ; i<nrDocs ; i++)
01028     {
01029         String cur = (container == "ALL") ? videoSet->GetContainer(i) : container;
01030         String name = FileNameBase(cur) + ".xml";
01031         ILOG_INFO("Checking " << i << " = " << cur);
01032         RgbDataSrc* src = videoSet->GetVideo(i);
01033         loc1.SetContainer(cur);
01034         loc1.SetName(name);
01035         loc1.SetFrameRateNum(src->FrameRateNum());
01036         loc1.SetFrameRateDen(src->FrameRateDen());
01037         Mpeg7Doc* doc1 = Mpeg7DocRepository().Get(loc1);
01038         loc2.SetContainer(cur);
01039         loc2.SetName(name);
01040         loc2.SetFrameRateNum(src->FrameRateNum());
01041         loc2.SetFrameRateDen(src->FrameRateDen());
01042         Mpeg7Doc* doc2 = Mpeg7DocRepository().Get(loc2);
01043         delete src;
01044         doc1->Diff(doc2);
01045         delete doc2;
01046         delete doc1;
01047     }
01048     delete videoSet;
01049 }
01050 
01051 void
01052 DoCopyMpeg7Shot()
01053 {
01054     ILOG_VAR(Impala.Application.Repository.DoCopyMpeg7Shot);
01055     CmdOptions& options = CmdOptions::GetInstance();
01056 
01057     /*
01058     Mpeg7DocLocator loc1 = GetMpeg7ShotLocator(options, true);
01059     Mpeg7DocLocator loc2 = GetMpeg7ShotLocator(options, false);
01060     VideoSet* videoSet = GetVideoSet(options, true);
01061     String container = loc1.GetContainer();
01062     int nrDocs = (container == "ALL") ? videoSet->GetNrContainers() : 1;
01063     for (int i=0 ; i<nrDocs ; i++)
01064     {
01065         String cur = (container == "ALL") ? videoSet->GetContainer(i) : container;
01066         Quid quid = GetQuidVideo(videoSet, container);
01067         loc1.RawDataSetContainer(cur);
01068         loc1.SetQuid(quid);
01069         Mpeg7Doc* doc = Mpeg7DocRepository().Get(loc1);
01070         loc2.SetContainer(cur);
01071         loc2.SetQuid(quid);
01072         Mpeg7DocRepository().Add(loc2, doc);
01073         delete doc;
01074     }
01075     delete videoSet;
01076     */
01077 }
01078 
01079 void
01080 DoDeleteMpeg7Shot()
01081 {
01082     ILOG_VAR(Impala.Application.Repository.DoDeleteMpeg7Shot);
01083     CmdOptions& options = CmdOptions::GetInstance();
01084 
01085     Mpeg7DocLocator loc = GetMpeg7ShotLocator(options, true);
01086     if (loc.GetContainer() == "ALL") // This is a bit rude, use with care
01087         return Mpeg7DocRepository().Delete(loc);
01088     VideoSet* videoSet = GetVideoSet(options, false);
01089     if (!videoSet)
01090         return;
01091 
01092     int nrDocs = videoSet->GetNrContainers();
01093     for (int i=0 ; i<nrDocs ; i++)
01094     {
01095         String cur = videoSet->GetContainer(i);
01096         loc.SetContainer(cur);
01097         String name = FileNameBase(cur) + ".xml";
01098         loc.SetName(name);
01099         Mpeg7DocRepository().Delete(loc);
01100     }
01101     delete videoSet;
01102 }
01103 
01104 void
01105 DoDeleteMpeg7Annotation()
01106 {
01107     ILOG_VAR(Impala.Application.Repository.DoDeleteMpeg7Annotation);
01108     CmdOptions& options = CmdOptions::GetInstance();
01109 
01110     Mpeg7DocLocator loc = GetMpeg7ShotLocator(options, true);
01111     loc.SetDocType(Mpeg7DocLocator::MPEG7_ANNOTATION);
01112     if (loc.GetContainer() == "ALL") // This is a bit rude, use with care
01113         return Mpeg7DocRepository().Delete(loc);
01114 
01115     ILOG_ERROR("Not fully implemented yet");
01116 }
01117 
01118 void
01119 DoDeleteMpeg7Concept()
01120 {
01121     ILOG_VAR(Impala.Application.Repository.DoDeleteMpeg7Concept);
01122     CmdOptions& options = CmdOptions::GetInstance();
01123 
01124     Mpeg7DocLocator loc = GetMpeg7ShotLocator(options, true);
01125     loc.SetDocType(Mpeg7DocLocator::MPEG7_CONCEPT);
01126     if (loc.GetContainer() == "ALL") // This is a bit rude, use with care
01127         return Mpeg7DocRepository().Delete(loc);
01128 
01129     ILOG_ERROR("Not fully implemented yet");
01130 }
01131 
01132 // ImageArchive part
01133 
01134 ImageArchiveLocator
01135 GetImageArchiveLocator(CmdOptions& options, bool getSrcLoc)
01136 {
01137     ILOG_VAR(Impala.Application.Repository.GetImageArchiveLocator);
01138 
01139     int nrArg = 6;
01140     if (!getSrcLoc)
01141         nrArg++;
01142     if (options.GetNrArg() < nrArg)
01143     {
01144         ILOG_ERROR("Need at least " << nrArg << " parameters");
01145     }
01146 
01147     int a = 1;
01148     String locString = options.GetArg(a++);
01149     String setName = options.GetArg(a++);
01150     bool frames = StringToBool(options.GetArg(a++));
01151     String container = options.GetArg(a++);
01152     String name = options.GetArg(a++);
01153     if (!getSrcLoc)
01154         locString = options.GetArg(a++);
01155     return ImageArchiveLocator(locString, setName, frames, container, name, 0);
01156 }
01157 
01158 Quid
01159 GetQuidVideo(RawDataSet* dataSet, String container)
01160 {
01161     if (dataSet->IsImageSet())
01162         return QUID_CLASS_UNKNOWN;
01163     VideoSet* vidSet = dynamic_cast<VideoSet*>(dataSet);
01164     int v = vidSet->GetFileId(container);
01165     Quid quid = (v != -1) ? vidSet->GetQuidVideo(v, false) : QUID_CLASS_UNKNOWN;
01166     return quid;
01167 }
01168 
01169 void
01170 DoDumpImageArchive()
01171 {
01172     ILOG_VAR(Impala.Application.Repository.DoDumpImageArchive);
01173     CmdOptions& options = CmdOptions::GetInstance();
01174 
01175     ImageArchiveLocator loc = GetImageArchiveLocator(options, true);
01176     RawDataSet* dataSet = GetRawDataSet(options, true);
01177     String container = loc.GetContainer();
01178     int nrArchives = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01179     for (int i=0 ; i<nrArchives ; i++)
01180     {
01181         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01182         loc.SetContainer(cur);
01183         Quid quid = GetQuidVideo(dataSet, container);
01184         loc.SetQuid(quid);
01185         ImageArchive* archive = ImageArchiveRepository().Get(loc);
01186         std::cout << loc << " has " << archive->NrImages() << " images"
01187                   << std::endl;
01188         if (archive->NrImages() > 0)
01189         {
01190             Core::Array::Array2dVec3UInt8* im = archive->ReadImage(0);
01191             std::cout << "ImageSize = " << im->CW() << "x" << im->CH()
01192                       << std::endl;
01193             delete im;
01194         }
01195         delete archive;
01196     }
01197     delete dataSet;
01198 }
01199 
01200 void
01201 DoDiffImageArchive()
01202 {
01203     ILOG_VAR(Impala.Application.Repository.DoDiffImageArchive);
01204     CmdOptions& options = CmdOptions::GetInstance();
01205 
01206     ImageArchiveLocator loc1 = GetImageArchiveLocator(options, true);
01207     ImageArchiveLocator loc2 = GetImageArchiveLocator(options, false);
01208     RawDataSet* dataSet = GetRawDataSet(options, true);
01209     String container = loc1.GetContainer();
01210     int nrArchives = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01211     for (int i=0 ; i<nrArchives ; i++)
01212     {
01213         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01214         ILOG_INFO("Checking " << i << " = " << cur);
01215         Quid quid = GetQuidVideo(dataSet, container);
01216         loc1.SetContainer(cur);
01217         loc1.SetQuid(quid);
01218         ImageArchive* archive1 = ImageArchiveRepository().Get(loc1);
01219         loc2.SetContainer(cur);
01220         loc2.SetQuid(quid);
01221         ImageArchive* archive2 = ImageArchiveRepository().Get(loc2);
01222         archive1->Diff(archive2);
01223         delete archive2;
01224         delete archive1;
01225     }
01226     delete dataSet;
01227 }
01228 
01229 void
01230 DoCopyImageArchive()
01231 {
01232     ILOG_VAR(Impala.Application.Repository.DoCopyImageArchive);
01233     CmdOptions& options = CmdOptions::GetInstance();
01234 
01235     ImageArchiveLocator loc1 = GetImageArchiveLocator(options, true);
01236     ImageArchiveLocator loc2 = GetImageArchiveLocator(options, false);
01237     RawDataSet* dataSet = GetRawDataSet(options, true);
01238     String container = loc1.GetContainer();
01239     int nrArchives = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01240     for (int i=0 ; i<nrArchives ; i++)
01241     {
01242         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01243         Quid quid = GetQuidVideo(dataSet, container);
01244         loc1.SetContainer(cur);
01245         loc1.SetQuid(quid);
01246         ImageArchive* archive = ImageArchiveRepository().Get(loc1);
01247         loc2.SetContainer(cur);
01248         loc2.SetQuid(quid);
01249         if (options.GetBool("sync"))
01250             ImageArchiveRepository().Sync(loc2, archive);
01251         else
01252             ImageArchiveRepository().Add(loc2, archive);
01253         delete archive;
01254     }
01255     delete dataSet;
01256 }
01257 
01258 void
01259 DoDeleteImageArchive()
01260 {
01261     ILOG_VAR(Impala.Application.Repository.DoDeleteImageArchive);
01262     CmdOptions& options = CmdOptions::GetInstance();
01263 
01264     ImageArchiveLocator loc = GetImageArchiveLocator(options, true);
01265     RawDataSet* dataSet = GetRawDataSet(options, false);
01266     if (!dataSet)
01267         return;
01268     String container = loc.GetContainer();
01269     int nrArchives = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01270     for (int i=0 ; i<nrArchives ; i++)
01271     {
01272         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01273         loc.SetContainer(cur);
01274         Quid quid = GetQuidVideo(dataSet, container);
01275         loc.SetQuid(quid);
01276         ImageArchiveRepository().Delete(loc);
01277     }
01278     delete dataSet;
01279 }
01280 
01281 // ImageArchiveSpecial part
01282 
01283 ImageArchiveLocator
01284 GetImageArchiveSpecialLocator(CmdOptions& options, bool getSrcLoc)
01285 {
01286     ILOG_VAR(Impala.Application.Repository.GetImageArchiveSpecialLocator);
01287 
01288     int nrArg = 6;
01289     if (!getSrcLoc)
01290         nrArg++;
01291     if (options.GetNrArg() < nrArg)
01292     {
01293         ILOG_ERROR("Need at least " << nrArg << " parameters");
01294     }
01295 
01296     int a = 1;
01297     String locString = options.GetArg(a++);
01298     String setName = options.GetArg(a++);
01299     bool frames = false;
01300     a++; // This is the imageset.txt, not needed for this locator
01301     String container = options.GetArg(a++);
01302     String name = options.GetArg(a++);
01303     if (!getSrcLoc)
01304         locString = options.GetArg(a++);
01305     return ImageArchiveLocator(locString, setName, frames, container, name, 0);
01306 }
01307 
01308 void
01309 DoDumpImageArchiveSpecial()
01310 {
01311     ILOG_VAR(Impala.Application.Repository.DoDumpImageArchiveSpecial);
01312     CmdOptions& options = CmdOptions::GetInstance();
01313 
01314     ImageArchiveLocator loc = GetImageArchiveSpecialLocator(options, true);
01315     ImageSetLocator imSetLoc = GetImageSetLocator(options, true);
01316     ImageSet* imSet = ImageSetRepository().Get(imSetLoc);
01317     String container = loc.GetContainer();
01318     int nrArchives = (container == "ALL") ? imSet->GetNrContainers() : 1;
01319     for (int i=0 ; i<nrArchives ; i++)
01320     {
01321         String cur = (container == "ALL") ? imSet->GetContainer(i) : container;
01322         loc.SetContainer(cur);
01323         ImageArchive* archive = ImageArchiveRepository().Get(loc);
01324         std::cout << loc << " has " << archive->NrImages() << " images"
01325                   << std::endl;
01326         if (archive->NrImages() > 0)
01327         {
01328             Core::Array::Array2dVec3UInt8* im = archive->ReadImage(0);
01329             std::cout << "ImageSize = " << im->CW() << "x" << im->CH()
01330                       << std::endl;
01331             delete im;
01332         }
01333         delete archive;
01334     }
01335     delete imSet;
01336 }
01337 
01338 void
01339 DoDiffImageArchiveSpecial()
01340 {
01341     ILOG_VAR(Impala.Application.Repository.DoDiffImageArchiveSpecial);
01342     CmdOptions& options = CmdOptions::GetInstance();
01343 
01344     ImageArchiveLocator loc1 = GetImageArchiveSpecialLocator(options, true);
01345     ImageArchiveLocator loc2 = GetImageArchiveSpecialLocator(options, false);
01346     ImageSetLocator imSetLoc = GetImageSetLocator(options, true);
01347     ImageSet* imSet = ImageSetRepository().Get(imSetLoc);
01348     String container = loc1.GetContainer();
01349     int nrArchives = (container == "ALL") ? imSet->GetNrContainers() : 1;
01350     for (int i=0 ; i<nrArchives ; i++)
01351     {
01352         String cur = (container == "ALL") ? imSet->GetContainer(i) : container;
01353         ILOG_INFO("Checking " << i << " = " << cur);
01354         loc1.SetContainer(cur);
01355         ImageArchive* archive1 = ImageArchiveRepository().Get(loc1);
01356         loc2.SetContainer(cur);
01357         ImageArchive* archive2 = ImageArchiveRepository().Get(loc2);
01358         archive1->Diff(archive2);
01359         delete archive2;
01360         delete archive1;
01361     }
01362     delete imSet;
01363 }
01364 
01365 void
01366 DoCopyImageArchiveSpecial()
01367 {
01368     ILOG_VAR(Impala.Application.Repository.DoCopyImageArchiveSpecial);
01369     CmdOptions& options = CmdOptions::GetInstance();
01370 
01371     ImageArchiveLocator loc1 = GetImageArchiveSpecialLocator(options, true);
01372     ImageArchiveLocator loc2 = GetImageArchiveSpecialLocator(options, false);
01373     ImageSetLocator imSetLoc = GetImageSetLocator(options, true);
01374     ImageSet* imSet = ImageSetRepository().Get(imSetLoc);
01375     String container = loc1.GetContainer();
01376     int nrArchives = (container == "ALL") ? imSet->GetNrContainers() : 1;
01377     for (int i=0 ; i<nrArchives ; i++)
01378     {
01379         String cur = (container == "ALL") ? imSet->GetContainer(i) : container;
01380         loc1.SetContainer(cur);
01381         ImageArchive* archive = ImageArchiveRepository().Get(loc1);
01382         loc2.SetContainer(cur);
01383         ImageArchiveRepository().Add(loc2, archive);
01384         delete archive;
01385     }
01386     delete imSet;
01387 }
01388 
01389 void
01390 DoDeleteImageArchiveSpecial()
01391 {
01392     ILOG_VAR(Impala.Application.Repository.DoDeleteImageArchiveSpecial);
01393     CmdOptions& options = CmdOptions::GetInstance();
01394 
01395     ImageArchiveLocator loc = GetImageArchiveSpecialLocator(options, true);
01396     ImageSetLocator imSetLoc = GetImageSetLocator(options, true);
01397     if (!ImageSetRepository().Exists(imSetLoc))
01398         return;
01399 
01400     ImageSet* imSet = ImageSetRepository().Get(imSetLoc);
01401     String container = loc.GetContainer();
01402     int nrArchives = (container == "ALL") ? imSet->GetNrContainers() : 1;
01403     for (int i=0 ; i<nrArchives ; i++)
01404     {
01405         String cur = (container == "ALL") ? imSet->GetContainer(i) : container;
01406         loc.SetContainer(cur);
01407         ImageArchiveRepository().Delete(loc);
01408     }
01409     delete imSet;
01410 }
01411 
01412 // FeatureTable part
01413 
01414 FeatureLocator
01415 GetFeatureLocator(CmdOptions& options, bool getSrcLoc)
01416 {
01417     ILOG_VAR(Impala.Application.Repository.GetFeatureLocator);
01418 
01419     int nrArg = 8;
01420     if (!getSrcLoc)
01421         nrArg++;
01422     if (options.GetNrArg() < nrArg)
01423     {
01424         ILOG_ERROR("Need at least " << nrArg << " parameters");
01425     }
01426 
01427     int a = 1;
01428     String locString = options.GetArg(a++);
01429     String setName = options.GetArg(a++);
01430     bool isCodebook = StringToBool(options.GetArg(a++));
01431     bool isIndex = StringToBool(options.GetArg(a++));
01432     String walkType = options.GetArg(a++);
01433     String feature = options.GetArg(a++);
01434     String container = options.GetArg(a++);
01435     if (!getSrcLoc)
01436         locString = options.GetArg(a++);
01437     return FeatureLocator(locString, setName, isCodebook, isIndex, walkType,
01438                           feature, container);
01439 }
01440 
01441 void
01442 DoDumpFeatureTable()
01443 {
01444     ILOG_VAR(Impala.Application.Repository.DoDumpFeatureTable);
01445     CmdOptions& options = CmdOptions::GetInstance();
01446 
01447     FeatureLocator loc = GetFeatureLocator(options, true);
01448     RawDataSet* dataSet = GetRawDataSet(options, true);
01449     String container = loc.GetContainer();
01450     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01451     for (int i=0 ; i<nrContainers ; i++)
01452     {
01453         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01454         loc.SetContainer(cur);
01455         FeatureTable* tab = FeatureTableRepository().Get(loc);
01456         tab->Dump(0, options.GetInt("start"), options.GetInt("end"));
01457         delete tab;
01458     }
01459 }
01460 
01461 void
01462 DoDiffFeatureTable()
01463 {
01464     ILOG_VAR(Impala.Application.Repository.DoDiffFeatureTable);
01465     CmdOptions& options = CmdOptions::GetInstance();
01466 
01467     FeatureLocator loc1 = GetFeatureLocator(options, true);
01468     FeatureLocator loc2 = GetFeatureLocator(options, false);
01469     RawDataSet* dataSet = GetRawDataSet(options, true);
01470     String container = loc1.GetContainer();
01471     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01472     for (int i=0 ; i<nrContainers ; i++)
01473     {
01474         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01475         ILOG_INFO("Checking " << i << " = " << cur);
01476         loc1.SetContainer(cur);
01477         FeatureTable* tab1 = FeatureTableRepository().Get(loc1);
01478         loc2.SetContainer(cur);
01479         FeatureTable* tab2 = FeatureTableRepository().Get(loc2);
01480         tab1->Diff(tab2);
01481         delete tab2;
01482         delete tab1;
01483     }
01484 }
01485 
01486 void
01487 DoCopyFeatureTable()
01488 {
01489     ILOG_VAR(Impala.Application.Repository.DoCopyFeatureTable);
01490     CmdOptions& options = CmdOptions::GetInstance();
01491 
01492     FeatureLocator loc1 = GetFeatureLocator(options, true);
01493     FeatureLocator loc2 = GetFeatureLocator(options, false);
01494     RawDataSet* dataSet = GetRawDataSet(options, true);
01495     String container = loc1.GetContainer();
01496     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01497     for (int i=0 ; i<nrContainers ; i++)
01498     {
01499         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01500         loc1.SetContainer(cur);
01501         FeatureTable* tab = FeatureTableRepository().Get(loc1);
01502         loc2.SetContainer(cur);
01503         if (options.GetBool("sync"))
01504             FeatureTableRepository().Sync(loc2, tab);
01505         else
01506             FeatureTableRepository().Add(loc2, tab);
01507         delete tab;
01508     }
01509 }
01510 
01511 void
01512 DoDeleteFeatureTable()
01513 {
01514     ILOG_VAR(Impala.Application.Repository.DoDeleteFeatureTable);
01515     CmdOptions& options = CmdOptions::GetInstance();
01516 
01517     FeatureLocator loc = GetFeatureLocator(options, true);
01518     if (loc.GetFeatureName() == "ALL") // This is a bit rude, use with care
01519         return FeatureTableRepository().Delete(loc);
01520     RawDataSet* dataSet = GetRawDataSet(options, false);
01521     if (!dataSet)
01522         return;
01523 
01524     String container = loc.GetContainer();
01525     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01526     for (int i=0 ; i<nrContainers ; i++)
01527     {
01528         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01529         loc.SetContainer(cur);
01530         FeatureTableRepository().Delete(loc);
01531     }
01532 }
01533 
01534 void
01535 DoSetQuidSetFeatureTable()
01536 {
01537     ILOG_VAR(Impala.Application.Repository.DoSetQuidSetFeatureTable);
01538     CmdOptions& options = CmdOptions::GetInstance();
01539 
01540     int a = 8;
01541     if (options.GetNrArg() < a + 1)
01542     {
01543         ILOG_ERROR("Need at least " << a + 1 << " parameters");
01544     }
01545     int setId = atol(options.GetArg(a));
01546     ILOG_INFO("Setting id to " << setId);
01547 
01548     FeatureLocator loc = GetFeatureLocator(options, true);
01549     RawDataSet* dataSet = GetRawDataSet(options, true);
01550     String container = loc.GetContainer();
01551     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
01552     for (int i=0 ; i<nrContainers ; i++)
01553     {
01554         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
01555         ILOG_INFO("Doing i=" << i << ", cur=" << cur);
01556         loc.SetContainer(cur);
01557         FeatureTable* tab = FeatureTableRepository().Get(loc);
01558         SetQuidSet(tab, setId);
01559         FeatureTableRepository().Add(loc, tab); // Should be Replace
01560         delete tab;
01561     }
01562 }
01563 
01564 // KeywordList part
01565 
01566 KeywordListLocator
01567 GetKeywordListLocator(CmdOptions& options, bool getSrcLoc)
01568 {
01569     ILOG_VAR(Impala.Application.Repository.GetKeywordListLocator);
01570 
01571     int nrArg = 3;
01572     if (!getSrcLoc)
01573         nrArg++;
01574     if (options.GetNrArg() < nrArg)
01575     {
01576         ILOG_ERROR("Need at least " << nrArg << " parameters");
01577     }
01578 
01579     int a = 1;
01580     String locString = options.GetArg(a++);
01581     String setName = options.GetArg(a++);
01582     String conceptSet = options.GetArg(a++);
01583     if (!getSrcLoc)
01584         locString = options.GetArg(a++);
01585     return KeywordListLocator(locString, setName, conceptSet);
01586 }
01587 
01588 void
01589 DoDumpKeywordList()
01590 {
01591     ILOG_VAR(Impala.Application.Repository.DoDumpKeywordList);
01592     CmdOptions& options = CmdOptions::GetInstance();
01593 
01594     KeywordListLocator loc = GetKeywordListLocator(options, true);
01595     KeywordList keyList = *(KeywordListRepository().Get(loc));
01596     for (int i=0 ; i<keyList.size() ; i++)
01597         std::cout << keyList[i] << std::endl;
01598 }
01599 
01600 void
01601 DoDiffKeywordList()
01602 {
01603     ILOG_VAR(Impala.Application.Repository.DoDiffKeywordList);
01604     CmdOptions& options = CmdOptions::GetInstance();
01605 
01606     KeywordListLocator loc1 = GetKeywordListLocator(options, true);
01607     KeywordList keyList1 = *(KeywordListRepository().Get(loc1));
01608     KeywordListLocator loc2 = GetKeywordListLocator(options, false);
01609     KeywordList keyList2 = *(KeywordListRepository().Get(loc2));
01610     Core::Table::KeywordListDiff(keyList1, keyList2);    
01611 }
01612 
01613 void
01614 DoCopyKeywordList()
01615 {
01616     ILOG_VAR(Impala.Application.Repository.DoCopyKeywordList);
01617     CmdOptions& options = CmdOptions::GetInstance();
01618 
01619     KeywordListLocator loc1 = GetKeywordListLocator(options, true);
01620     KeywordList* keyList = KeywordListRepository().Get(loc1);
01621     KeywordListLocator loc2 = GetKeywordListLocator(options, false);
01622     if (options.GetBool("sync"))
01623         KeywordListRepository().Sync(loc2, keyList);
01624     else
01625         KeywordListRepository().Add(loc2, keyList);
01626     delete keyList;
01627 }
01628 
01629 // AnnotationTable part
01630 
01631 AnnotationTableLocator
01632 GetAnnotationTableLocator(CmdOptions& options, bool getSrcLoc)
01633 {
01634     ILOG_VAR(Impala.Application.Repository.GetAnnotationTableLocator);
01635 
01636     int nrArg = 6;
01637     if (!getSrcLoc)
01638         nrArg++;
01639     if (options.GetNrArg() < nrArg)
01640     {
01641         ILOG_ERROR("Need at least " << nrArg << " parameters");
01642     }
01643 
01644     int a = 1;
01645     String locString = options.GetArg(a++);
01646     String setName = options.GetArg(a++);
01647     int quidClass = StringToQuidClass(options.GetArg(a++));
01648     String conceptSet = options.GetArg(a++);
01649     String keyword = options.GetArg(a++);
01650     if (!getSrcLoc)
01651         locString = options.GetArg(a++);
01652     return AnnotationTableLocator(locString, setName, quidClass, conceptSet,
01653                                   keyword);
01654 }
01655 
01656 void
01657 DoDumpAnnotationTable()
01658 {
01659     ILOG_VAR(Impala.Application.Repository.DoDumpAnnotationTable);
01660     CmdOptions& options = CmdOptions::GetInstance();
01661 
01662     AnnotationTableLocator loc = GetAnnotationTableLocator(options, true);
01663     AnnotationTable* tab = AnnotationTableRepository().Get(loc);
01664     if (tab == 0)
01665         return;
01666     RawDataSet* dataSet = GetRawDataSet(options, false);
01667     tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
01668     tab->DumpSummary();
01669     delete tab;
01670     if (dataSet)
01671         delete dataSet;
01672 }
01673 
01674 void
01675 DoDiffAnnotationTable()
01676 {
01677     ILOG_VAR(Impala.Application.Repository.DoDiffAnnotationTable);
01678     CmdOptions& options = CmdOptions::GetInstance();
01679 
01680     AnnotationTableLocator loc1 = GetAnnotationTableLocator(options, true);
01681     AnnotationTable* tab1 = AnnotationTableRepository().Get(loc1);
01682     if (tab1 == 0)
01683         return;
01684     AnnotationTableLocator loc2 = GetAnnotationTableLocator(options, false);
01685     AnnotationTable* tab2 = AnnotationTableRepository().Get(loc2);
01686     tab1->Diff(tab2);
01687     delete tab2;
01688     delete tab1;
01689 }
01690 
01691 void
01692 DoCopyAnnotationTable()
01693 {
01694     ILOG_VAR(Impala.Application.Repository.DoCopyAnnotationTable);
01695     CmdOptions& options = CmdOptions::GetInstance();
01696 
01697     AnnotationTableLocator loc1 = GetAnnotationTableLocator(options, true);
01698     AnnotationTable* tab = AnnotationTableRepository().Get(loc1);
01699     if (tab == 0)
01700         return;
01701     AnnotationTableLocator loc2 = GetAnnotationTableLocator(options, false);
01702     AnnotationTableRepository().Add(loc2, tab);
01703     delete tab;
01704 }
01705 
01706 void
01707 DoDeleteAnnotationTable()
01708 {
01709     ILOG_VAR(Impala.Application.Repository.DoDeleteAnnotationTable);
01710     CmdOptions& options = CmdOptions::GetInstance();
01711 
01712     AnnotationTableLocator loc = GetAnnotationTableLocator(options, true);
01713     AnnotationTableRepository().Delete(loc);
01714 }
01715 
01716 // Merges two annotation tables on the same dataset into a new table.
01717 // The new concept is positive if either one of the input tables is positive
01718 void
01719 DoMergeAnnotationTable()
01720 {
01721     ILOG_VAR(Impala.Application.Repository.DoMergeAnnotationTable);
01722     CmdOptions& options = CmdOptions::GetInstance();
01723 
01724     AnnotationTableLocator loc = GetAnnotationTableLocator(options, true);
01725     String outputKeyword = loc.GetKeyword();
01726     AnnotationTable* res = 0;
01727     int a = 6;
01728     while (a < options.GetNrArg())
01729     {
01730         String inputKeyword = options.GetArg(a++);
01731         ILOG_INFO("Merging " << inputKeyword);
01732         loc.SetKeyword(inputKeyword);
01733         AnnotationTable* tab = AnnotationTableRepository().Get(loc);
01734         if (tab == 0)
01735             return;
01736         if (res == 0)
01737         {
01738             res = tab;
01739             res->SetLabel(outputKeyword);
01740         }
01741         else
01742         {
01743             res->Merge(tab);
01744             delete tab;
01745         }
01746 
01747         ILOG_INFO("Merged " << loc << " : ");
01748         res->DumpSummary();
01749     }
01750     loc.SetKeyword(outputKeyword);
01751     AnnotationTableRepository().Add(loc, res);
01752     delete res;
01753 }
01754 
01755 // AnnotationTableSet part
01756 
01757 AnnotationTableSetLocator
01758 GetAnnotationTableSetLocator(CmdOptions& options, bool getSrcLoc)
01759 {
01760     ILOG_VAR(Impala.Application.Repository.GetAnnotationTableSetLocator);
01761 
01762     int nrArg = 5;
01763     if (!getSrcLoc)
01764         nrArg++;
01765     if (options.GetNrArg() < nrArg)
01766     {
01767         ILOG_ERROR("Need at least " << nrArg << " parameters");
01768     }
01769 
01770     int a = 1;
01771     String locString = options.GetArg(a++);
01772     String setName = options.GetArg(a++);
01773     int quidClass = StringToQuidClass(options.GetArg(a++));
01774     String conceptSet = options.GetArg(a++);
01775     if (!getSrcLoc)
01776         locString = options.GetArg(a++);
01777     return AnnotationTableSetLocator(locString, setName, quidClass, conceptSet);
01778 }
01779 
01780 void
01781 DoDumpAnnotationTableSet()
01782 {
01783     ILOG_VAR(Impala.Application.Repository.DoDumpAnnotationTableSet);
01784     CmdOptions& options = CmdOptions::GetInstance();
01785 
01786     int a = 5;
01787     bool dumpTable = atol(options.GetArg(a++)) != 0;
01788     int maxV = -1;
01789     if (options.GetNrArg() > a)
01790         maxV = atol(options.GetArg(a++));
01791     int maxP = -1;
01792     if (options.GetNrArg() > a)
01793         maxP = atol(options.GetArg(a++));
01794     int maxN = -1;
01795     if (options.GetNrArg() > a)
01796         maxN = atol(options.GetArg(a++));
01797 
01798     AnnotationTableSetLocator loc = GetAnnotationTableSetLocator(options, true);
01799     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc);
01800     if (tSet == 0)
01801         return;
01802     RawDataSet* dataSet = GetRawDataSet(options, false);
01803 
01804     for (int i=0 ; i<tSet->Size() ; i++)
01805     {
01806         AnnotationTable* tab = tSet->GetTable(i);
01807         tab->DumpSummary();
01808         //tab->DumpSummaryObject();
01809         if (dumpTable)
01810             tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
01811         if (maxV != -1)
01812         {
01813             tab->SelectQuidObjectMaxId(maxV);
01814             tab->SetLabel(tab->GetLabel() + "_maxV_" + MakeString(maxV));
01815             tab->DumpSummary();
01816             tab->DumpSummaryObject();
01817         }
01818         if (maxP != -1)
01819         {
01820             tab->SelectQuidObjectMaxPositive(maxP);
01821             tab->SetLabel(tab->GetLabel() + "_maxP_" + MakeString(maxP));
01822             tab->DumpSummary();
01823             tab->DumpSummaryObject();
01824         }
01825         if (maxN != -1)
01826         {
01827             tab->SelectQuidObjectMaxNegative(maxN);
01828             tab->SetLabel(tab->GetLabel() + "_maxN_" + MakeString(maxN));
01829             tab->DumpSummary();
01830             tab->DumpSummaryObject();
01831         }
01832     }
01833 
01834     delete tSet;
01835     if (dataSet)
01836         delete dataSet;
01837 }
01838 
01839 void
01840 DoDiffAnnotationTableSet()
01841 {
01842     ILOG_VAR(Impala.Application.Repository.DoDiffAnnotationTableSet);
01843     CmdOptions& options = CmdOptions::GetInstance();
01844 
01845     AnnotationTableSetLocator loc1 = GetAnnotationTableSetLocator(options, true);
01846     AnnotationTableSet* tSet1 = AnnotationTableSetRepository().Get(loc1);
01847     if (tSet1 == 0)
01848         return;
01849     AnnotationTableSetLocator loc2 = GetAnnotationTableSetLocator(options, false);
01850     AnnotationTableSet* tSet2 = AnnotationTableSetRepository().Get(loc2);
01851     tSet1->Diff(tSet2);
01852     delete tSet2;
01853     delete tSet1;
01854 }
01855 
01856 void
01857 DoCopyAnnotationTableSet()
01858 {
01859     ILOG_VAR(Impala.Application.Repository.DoCopyAnnotationTableSet);
01860     CmdOptions& options = CmdOptions::GetInstance();
01861 
01862     AnnotationTableSetLocator loc1 = GetAnnotationTableSetLocator(options, true);
01863     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc1);
01864     if (tSet == 0)
01865         return;
01866     AnnotationTableSetLocator loc2 = GetAnnotationTableSetLocator(options, false);
01867     if (options.GetBool("sync"))
01868         AnnotationTableSetRepository().Sync(loc2, tSet);
01869     else
01870         AnnotationTableSetRepository().Add(loc2, tSet);
01871     delete tSet;
01872 }
01873 
01874 void
01875 DoDeleteAnnotationTableSet()
01876 {
01877     ILOG_VAR(Impala.Application.Repository.DoDeleteAnnotationTableSet);
01878     CmdOptions& options = CmdOptions::GetInstance();
01879 
01880     AnnotationTableSetLocator loc = GetAnnotationTableSetLocator(options, true);
01881     AnnotationTableSetRepository().Delete(loc);
01882 }
01883 
01884 // Merges annotations from different data sets by appending existing tables.
01885 void
01886 DoMergeAnnotationTableSet()
01887 {
01888     ILOG_VAR(Impala.Application.Repository.DoMergeAnnotationTableSet);
01889     CmdOptions& options = CmdOptions::GetInstance();
01890 
01891     AnnotationTableSet* res = 0;
01892     int a = 1;
01893     while (a < options.GetNrArg())
01894     {
01895         if (a + 4 > options.GetNrArg())
01896         {
01897             ILOG_ERROR("Incorrect number of parameters");
01898             return;
01899         }
01900         String locString = options.GetArg(a++);
01901         String setName = options.GetArg(a++);
01902         int quidClass = StringToQuidClass(options.GetArg(a++));
01903         String conceptSet = options.GetArg(a++);
01904         AnnotationTableSetLocator loc(locString, setName, quidClass, conceptSet);
01905 
01906         if (a == options.GetNrArg())
01907         {
01908             ILOG_INFO("Saving result in " << loc);
01909             AnnotationTableSetRepository().Add(loc, res);
01910             delete res;
01911             return;
01912         }
01913 
01914         AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc);
01915         if (tSet == 0)
01916             return;
01917         if (res == 0)
01918         {
01919             res = tSet;
01920         }
01921         else
01922         {
01923             res->Merge(tSet);
01924             delete tSet;
01925         }
01926 
01927         ILOG_INFO("Merged " << loc << " : ");
01928         for (int i=0 ; i<res->Size() ; i++)
01929         {
01930             AnnotationTable* tab = res->GetTable(i);
01931             tab->DumpSummary();
01932         }
01933     }
01934 }
01935 
01936 void
01937 DoCorrectAnnotationTableSet()
01938 {
01939     ILOG_VAR(Impala.Application.Repository.DoCorrectAnnotationTableSet);
01940     CmdOptions& options = CmdOptions::GetInstance();
01941 
01942     int nrArg = 7;
01943     if (options.GetNrArg() < nrArg)
01944     {
01945         ILOG_ERROR("Need at least " << nrArg << " parameters");
01946     }
01947 
01948     AnnotationTableSetLocator loc = GetAnnotationTableSetLocator(options, true);
01949     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc);
01950     if (tSet == 0)
01951         return;
01952 
01953     int a = 5;
01954     String corrSetName = options.GetArg(a++);
01955     String resSetName = options.GetArg(a++);
01956     loc.SetConceptSet(corrSetName);
01957     AnnotationTableSet* corrSet = AnnotationTableSetRepository().Get(loc);
01958     if (corrSet == 0)
01959         return;
01960 
01961     tSet->Correct(corrSet);
01962     delete corrSet;
01963     loc.SetConceptSet(resSetName);
01964     ILOG_INFO("Saving result in " << loc);
01965     AnnotationTableSetRepository().Add(loc, tSet);
01966     delete tSet;
01967 }
01968 
01969 void
01970 DoSelectAnnotationTableSet()
01971 {
01972     ILOG_VAR(Impala.Application.Repository.DoSelectAnnotationTableSet);
01973     CmdOptions& options = CmdOptions::GetInstance();
01974 
01975     int nrArg = 7;
01976     if (options.GetNrArg() < nrArg)
01977     {
01978         ILOG_ERROR("Need at least " << nrArg << " parameters");
01979     }
01980 
01981     AnnotationTableSetLocator loc = GetAnnotationTableSetLocator(options, true);
01982     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc);
01983     if (tSet == 0)
01984         return;
01985 
01986     int a = 5;
01987     String concept = options.GetArg(a++);
01988     String iteration = options.GetArg(a++);
01989     AnnotationTable* src = tSet->GetTable(concept);
01990     if (!src)
01991     {
01992         ILOG_ERROR("No annotations for " << concept);
01993         return;
01994     }
01995 
01996     std::vector<String> labels;
01997     labels.push_back(concept);
01998     AnnotationTableSet resSet(labels, 0);
01999     AnnotationTable* res = resSet.GetTable(concept);
02000     Copy(res, src);
02001     res->SelectQuidObjectMaxPositive(5 * atol(iteration));
02002     res->SelectQuidObjectMaxNegative(5 * atol(iteration));
02003     res->SelectQuidObjectMaxSkip(0);
02004 
02005     String resSetName = FileNameBase(loc.GetConceptSet()) + "_" + concept + "_"
02006         + iteration + ".txt";
02007     loc.SetConceptSet(resSetName);
02008     ILOG_INFO("Saving result in " << loc);
02009     AnnotationTableSetRepository().Add(loc, &resSet);
02010     delete tSet;
02011 }
02012 
02013 void
02014 DoIndexAnnotatedFeatures()
02015 {
02016     ILOG_VAR(Impala.Application.Repository.DoIndexAnnotatedFeatures);
02017     CmdOptions& options = CmdOptions::GetInstance();
02018 
02019     AnnotationTableSetLocator aLoc = GetAnnotationTableSetLocator(options, true);
02020     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(aLoc);
02021     if (tSet == 0)
02022         return;
02023 
02024     int a = 5;
02025     String featureDef = options.GetArg(a++);
02026     ILOG_INFO("FeatureDef = " << featureDef);
02027 
02028     QuidTable* quids = tSet->GetUniqueQuids();
02029     ILOG_INFO("Read " << quids->Size() << " quids, starting sort...");
02030     Sort(quids, 1, true);
02031     ILOG_INFO("Found " << quids->Size() << " unique quids");
02032 
02033     int lastClassId = -1;
02034     int lastSetId = -1;
02035     int lastContainerNr = -1;
02036     RawDataSet* dataSet = 0;
02037     FeatureLocator fLoc;
02038     FeatureTable* features = 0;
02039     FeatureTable* result = 0;
02040     String locString = aLoc.GetProtocolAndHost();
02041     for (int i=0 ; i<quids->Size() ; i++)
02042     {
02043         Quid q = quids->Get1(i);
02044         if ((lastClassId != QuidClass(q)) || (lastSetId != QuidSet(q)))
02045         {
02046             if (dataSet)
02047                 delete dataSet;
02048             lastClassId = QuidClass(q);
02049             lastSetId = QuidSet(q);
02050             dataSet = Core::Database::MakeRawDataSet(locString, q);
02051             ILOG_INFO("i=" << i << ": new dataset " << dataSet->GetSetName());
02052             String walk = (QuidClass(q) == QUID_CLASS_IMAGE) ? "" : "Keyframes";
02053             fLoc = FeatureLocator(dataSet->GetLocator(), false,
02054                                   false, walk, featureDef, "<empty>");
02055             lastContainerNr = -1;
02056         }
02057 
02058         int containerNr = dataSet->GetContainerNrOfQuid(q);
02059         if (lastContainerNr != containerNr)
02060         {
02061             lastContainerNr = containerNr;
02062             String container = dataSet->GetContainer(lastContainerNr);
02063             ILOG_INFO("i=" << i << ": new container " << container);
02064             fLoc.SetContainer(container);
02065             if (features)
02066                 delete features;
02067             features = FeatureTableRepository().Get(fLoc);
02068         }
02069         FeatureTable::VectorReal64 vec = features->FindFeature(q);
02070         if (result == 0)
02071         {
02072             result = new FeatureTable(features->GetFeatureDefinition(),
02073                                       quids->Size(), vec.Size());
02074         }
02075         result->Add(q, vec);
02076     }
02077     if (features)
02078         delete features;
02079     if (dataSet)
02080         delete dataSet;
02081     if (result == 0)
02082     {
02083         ILOG_ERROR("No features found");
02084         return;
02085     }
02086     if (result->Size() != quids->Size())
02087     {
02088         ILOG_ERROR("Found " << result->Size() << " features for " <<
02089                    quids->Size() << " quids");
02090     }
02091     delete quids;
02092 
02093     FeatureLocator rLoc(aLoc, false, true, aLoc.GetConceptSet(), featureDef, "");
02094     FeatureTableRepository().Add(rLoc, result);
02095     delete result;
02096 }
02097 
02098 // Fold part
02099 
02100 FoldLocator
02101 GetFoldLocator(CmdOptions& options, bool getSrcLoc)
02102 {
02103     ILOG_VAR(Impala.Application.Repository.GetFoldLocator);
02104 
02105     int nrArg = 8;
02106     if (!getSrcLoc)
02107         nrArg++;
02108     if (options.GetNrArg() < nrArg)
02109     {
02110         ILOG_ERROR("Need at least " << nrArg << " parameters");
02111     }
02112 
02113     int a = 1;
02114     String locString = options.GetArg(a++);
02115     String setName = options.GetArg(a++);
02116     int quidClass = StringToQuidClass(options.GetArg(a++));
02117     String conceptSet = options.GetArg(a++);
02118     String keyword = options.GetArg(a++);
02119     String foldType = options.GetArg(a++);
02120     int foldNr = atol(options.GetArg(a++));
02121     if (!getSrcLoc)
02122         locString = options.GetArg(a++);
02123     return FoldLocator(locString, setName, quidClass, conceptSet, keyword,
02124                        foldType, foldNr);
02125 }
02126 
02127 void
02128 DoDumpFold()
02129 {
02130     ILOG_VAR(Impala.Application.Repository.DoDumpFold);
02131     CmdOptions& options = CmdOptions::GetInstance();
02132 
02133     FoldLocator loc = GetFoldLocator(options, true);
02134     QuidTable* tab = FoldRepository().Get(loc);
02135     if (tab == 0)
02136         return;
02137     RawDataSet* dataSet = GetRawDataSet(options, false);
02138     tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
02139     delete tab;
02140     if (dataSet)
02141         delete dataSet;
02142 }
02143 
02144 void
02145 DoDiffFold()
02146 {
02147     ILOG_VAR(Impala.Application.Repository.DoDiffFold);
02148     CmdOptions& options = CmdOptions::GetInstance();
02149 
02150     FoldLocator loc1 = GetFoldLocator(options, true);
02151     QuidTable* tab1 = FoldRepository().Get(loc1);
02152     if (tab1 == 0)
02153         return;
02154     FoldLocator loc2 = GetFoldLocator(options, false);
02155     QuidTable* tab2 = FoldRepository().Get(loc2);
02156     tab1->Diff(tab2);
02157     delete tab2;
02158     delete tab1;
02159 }
02160 
02161 void
02162 DoCopyFold()
02163 {
02164     ILOG_VAR(Impala.Application.Repository.DoCopyFold);
02165     CmdOptions& options = CmdOptions::GetInstance();
02166 
02167     FoldLocator loc1 = GetFoldLocator(options, true);
02168     QuidTable* tab = FoldRepository().Get(loc1);
02169     if (tab == 0)
02170         return;
02171     FoldLocator loc2 = GetFoldLocator(options, false);
02172     FoldRepository().Add(loc2, tab);
02173     delete tab;
02174 }
02175 
02176 void
02177 DoDeleteFold()
02178 {
02179     ILOG_VAR(Impala.Application.Repository.DoDeleteFold);
02180     CmdOptions& options = CmdOptions::GetInstance();
02181 
02182     FoldLocator loc = GetFoldLocator(options, true);
02183     FoldRepository().Delete(loc);
02184 }
02185 
02186 // SimilarityTableSet part
02187 
02188 SimilarityTableSetLocator
02189 GetSimilarityTableSetLocator(CmdOptions& options, bool getSrcLoc)
02190 {
02191     ILOG_VAR(Impala.Application.Repository.GetSimilarityTableSetLocator);
02192 
02193     int nrArg = 9;
02194     if (!getSrcLoc)
02195         nrArg++;
02196     if (options.GetNrArg() < nrArg)
02197     {
02198         ILOG_ERROR("Need at least " << nrArg << " parameters");
02199     }
02200 
02201     int a = 1;
02202     String locString = options.GetArg(a++);
02203     String setName = options.GetArg(a++);
02204     bool inIndex = StringToBool(options.GetArg(a++));
02205     String walkType = options.GetArg(a++);
02206     String conceptSet = options.GetArg(a++);
02207     String model = options.GetArg(a++);
02208     String feature = options.GetArg(a++);
02209     String container = options.GetArg(a++);
02210     if (!getSrcLoc)
02211         locString = options.GetArg(a++);
02212     return SimilarityTableSetLocator(locString, setName, inIndex, walkType,
02213                                      conceptSet, model, feature, container);
02214 }
02215 
02216 void
02217 DoDumpSimilarityTableSet()
02218 {
02219     ILOG_VAR(Impala.Application.Repository.DoDumpSimilarityTableSet);
02220     CmdOptions& options = CmdOptions::GetInstance();
02221 
02222     bool doMatrix = false;
02223     if (options.GetNrArg() > 9)
02224         doMatrix = StringToBool(options.GetArg(9));
02225     bool dumpQuid = false;
02226     if (options.GetNrArg() > 10)
02227         dumpQuid = StringToBool(options.GetArg(10));
02228 
02229     SimilarityTableSetLocator loc = GetSimilarityTableSetLocator(options, true);
02230     RawDataSet* dataSet = GetRawDataSet(options, true);
02231     String container = loc.GetContainer();
02232     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02233     for (int i=0 ; i<nrContainers ; i++)
02234     {
02235         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02236         loc.SetContainer(cur);
02237         SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc);
02238         if (doMatrix)
02239         {
02240             simSet->DumpMatrix(dataSet, dumpQuid);
02241         }
02242         else
02243         {
02244             simSet->DumpRanking(dataSet, options.GetInt("start"),
02245                                 options.GetInt("end"));
02246         }
02247         delete simSet;
02248     }
02249 }
02250 
02251 void
02252 DoDiffSimilarityTableSet()
02253 {
02254     ILOG_VAR(Impala.Application.Repository.DoDiffSimilarityTableSet);
02255     CmdOptions& options = CmdOptions::GetInstance();
02256 
02257     SimilarityTableSetLocator loc1 = GetSimilarityTableSetLocator(options, true);
02258     SimilarityTableSetLocator loc2 = GetSimilarityTableSetLocator(options, false);
02259     RawDataSet* dataSet = GetRawDataSet(options, true);
02260     String container = loc1.GetContainer();
02261     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02262     for (int i=0 ; i<nrContainers ; i++)
02263     {
02264         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02265         ILOG_INFO("Checking " << i << " = " << cur);
02266         loc1.SetContainer(cur);
02267         SimilarityTableSet* simSet1 = SimilarityTableSetRepository().Get(loc1);
02268 
02269         loc2.SetContainer(cur);
02270         SimilarityTableSet* simSet2 = SimilarityTableSetRepository().Get(loc2);
02271         simSet1->Diff(simSet2);
02272         delete simSet2;
02273         delete simSet1;
02274     }
02275 }
02276 
02277 void
02278 DoCopySimilarityTableSet()
02279 {
02280     ILOG_VAR(Impala.Application.Repository.DoCopySimilarityTableSet);
02281     CmdOptions& options = CmdOptions::GetInstance();
02282 
02283     SimilarityTableSetLocator loc1 = GetSimilarityTableSetLocator(options, true);
02284     SimilarityTableSetLocator loc2 = GetSimilarityTableSetLocator(options, false);
02285     RawDataSet* dataSet = GetRawDataSet(options, true);
02286     String container = loc1.GetContainer();
02287     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02288     for (int i=0 ; i<nrContainers ; i++)
02289     {
02290         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02291         loc1.SetContainer(cur);
02292         SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc1);
02293 
02294         loc2.SetContainer(cur);
02295         SimilarityTableSetRepository().Add(loc2, simSet);
02296         delete simSet;
02297     }
02298 }
02299 
02300 void
02301 DoDeleteSimilarityTableSet()
02302 {
02303     ILOG_VAR(Impala.Application.Repository.DoDeleteSimilarityTableSet);
02304     CmdOptions& options = CmdOptions::GetInstance();
02305 
02306     SimilarityTableSetLocator loc = GetSimilarityTableSetLocator(options, true);
02307     if (loc.GetConceptSet() == "ALL") // This is a bit rude, use with care
02308         return SimilarityTableSetRepository().Delete(loc);
02309     RawDataSet* dataSet = GetRawDataSet(options, false);
02310     if (!dataSet)
02311         return;
02312 
02313     String container = loc.GetContainer();
02314     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02315     for (int i=0 ; i<nrContainers ; i++)
02316     {
02317         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02318         loc.SetContainer(cur);
02319         SimilarityTableSetRepository().Delete(loc);
02320     }
02321 }
02322 
02323 void
02324 DoMergeSimilarityTableSet()
02325 {
02326     ILOG_VAR(Impala.Application.Repository.DoMergeSimilarityTableSet);
02327     CmdOptions& options = CmdOptions::GetInstance();
02328 
02329     SimilarityTableSetLocator dstLoc =
02330         GetSimilarityTableSetLocator(options, true);
02331     RawDataSet* dataSet = GetRawDataSet(options, true);
02332     std::vector<String> srcSets;
02333     for (int a=9 ; a<options.GetNrArg() ; a++)
02334     {
02335         srcSets.push_back(options.GetArg(a));
02336     }
02337 
02338     String container = dstLoc.GetContainer();
02339     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02340     for (int i=0 ; i<nrContainers ; i++)
02341     {
02342         SimilarityTableSet* dstSet = 0;
02343         SimilarityTableSetLocator srcLoc = dstLoc;
02344         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02345         srcLoc.SetContainer(cur);
02346         for (int c=0 ; c<srcSets.size() ; c++)
02347         {
02348             srcLoc.SetConceptSet(srcSets[c]);
02349             ILOG_INFO("Merging " << i << " = " << cur << " for " << srcSets[c]);
02350             SimilarityTableSet* s = SimilarityTableSetRepository().Get(srcLoc);
02351 
02352             //s->DumpRanking(0, options.GetInt("start"), options.GetInt("end"));
02353             if (dstSet == 0)
02354             {
02355                 dstSet = s;
02356             }
02357             else
02358             {
02359                 dstSet->Merge(s);
02360                 delete s;
02361             }
02362         }
02363         dstLoc.SetContainer(cur);
02364         SimilarityTableSetRepository().Add(dstLoc, dstSet);
02365         delete dstSet;
02366     }
02367 }
02368 
02369 // Model part
02370 
02371 ModelLocator
02372 GetModelLocator(CmdOptions& options, bool getSrcLoc)
02373 {
02374     ILOG_VAR(Impala.Application.Repository.GetModelLocator);
02375 
02376     int nrArg = 7;
02377     if (!getSrcLoc)
02378         nrArg++;
02379     if (options.GetNrArg() < nrArg)
02380     {
02381         ILOG_ERROR("Need at least " << nrArg << " parameters");
02382     }
02383 
02384     int a = 1;
02385     String locString = options.GetArg(a++);
02386     String setName = options.GetArg(a++);
02387     String conceptSet = options.GetArg(a++);
02388     String model = options.GetArg(a++);
02389     String feature = options.GetArg(a++);
02390     String concept = options.GetArg(a++);
02391     if (!getSrcLoc)
02392         locString = options.GetArg(a++);
02393     return ModelLocator(locString, setName, conceptSet, model, feature, concept);
02394 }
02395 
02396 KeywordList
02397 GetModelKeywordList(const ModelLocator& modelLoc)
02398 {
02399     ILOG_VAR(Impala.Application.Repository.GetModelKeywordList);
02400 
02401     KeywordList res;
02402     String concept = modelLoc.GetConcept();
02403     if (concept == "ALL")
02404     {
02405         KeywordListLocator keyLoc(modelLoc, modelLoc.GetConceptSet());
02406         KeywordList* list = KeywordListRepository().Get(keyLoc);
02407         if(list)
02408         {
02409             res = *list;
02410             delete list;
02411             if (res.size() == 0)
02412                 ILOG_ERROR("No keywords found");
02413         }
02414         else
02415         {
02416             ILOG_ERROR("keyword list not found");
02417         }
02418     }
02419     else
02420     {
02421         res.push_back(concept);
02422     }
02423     return res;
02424 }
02425 
02426 void
02427 DoDumpBestFile()
02428 {
02429     ILOG_VAR(Impala.Application.Repository.DoDumpBestFile);
02430 
02431     CmdOptions& options = CmdOptions::GetInstance();
02432     ModelLocator loc = GetModelLocator(options, true);
02433     KeywordList concepts = GetModelKeywordList(loc);
02434     for (int i=0 ; i<concepts.size() ; i++)
02435     {
02436         loc.SetConcept(concepts[i]);
02437         Util::PropertySet* bestFile = BestFileRepository().Get(loc);
02438         if (bestFile)
02439         {
02440             bestFile->Print(std::cout);
02441             std::cout << std::endl;
02442             delete bestFile;
02443         }
02444     }
02445 }
02446 
02447 void
02448 DoDiffBestFile()
02449 {
02450     ILOG_VAR(Impala.Application.Repository.DoDiffBestFile);
02451     CmdOptions& options = CmdOptions::GetInstance();
02452 
02453     ModelLocator loc1 = GetModelLocator(options, true);
02454     ModelLocator loc2 = GetModelLocator(options, false);
02455     KeywordList concepts = GetModelKeywordList(loc1);
02456     for (int i=0 ; i<concepts.size() ; i++)
02457     {
02458         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02459         loc1.SetConcept(concepts[i]);
02460         Util::PropertySet* bestFile1 = BestFileRepository().Get(loc1);
02461         loc2.SetConcept(concepts[i]);
02462         Util::PropertySet* bestFile2 = BestFileRepository().Get(loc2);
02463         Core::Training::BestFileReferenceDiff(bestFile1, bestFile2);
02464         delete bestFile1;
02465         delete bestFile2;
02466     }
02467 }
02468 
02469 void
02470 DoCopyBestFile()
02471 {
02472     ILOG_VAR(Impala.Application.Repository.DoCopyDiffBestFile);
02473     CmdOptions& options = CmdOptions::GetInstance();
02474 
02475     ModelLocator loc1 = GetModelLocator(options, true);
02476     ModelLocator loc2 = GetModelLocator(options, false);
02477     KeywordList concepts = GetModelKeywordList(loc1);
02478     for (int i=0 ; i<concepts.size() ; i++)
02479     {
02480         loc1.SetConcept(concepts[i]);
02481         Util::PropertySet* bestFile = BestFileRepository().Get(loc1);
02482         loc2.SetConcept(concepts[i]);
02483         BestFileRepository().Add(loc2, bestFile);
02484         delete bestFile;
02485     }
02486 }
02487 
02488 void
02489 DoDumpSvmProblem()
02490 {
02491     ILOG_VAR(Impala.Application.Repository.DoDumpSvmProblem);
02492 
02493     CmdOptions& options = CmdOptions::GetInstance();
02494     ModelLocator loc = GetModelLocator(options, true);
02495     KeywordList concepts = GetModelKeywordList(loc);
02496     for (int i=0 ; i<concepts.size() ; i++)
02497     {
02498         loc.SetConcept(concepts[i]);
02499         svm_problem* problem = SvmProblemRepository().Get(loc);
02500         if (problem)
02501         {
02502             Dump(problem, -1, 10, std::cout);
02503             DestroySvmProblem(problem);
02504         }
02505     }
02506 }
02507 
02508 void
02509 DoDiffSvmProblem()
02510 {
02511     ILOG_VAR(Impala.Application.Repository.DoDiffSvmProblem);
02512     CmdOptions& options = CmdOptions::GetInstance();
02513 
02514     ModelLocator loc1 = GetModelLocator(options, true);
02515     ModelLocator loc2 = GetModelLocator(options, false);
02516     KeywordList concepts = GetModelKeywordList(loc1);
02517     for (int i=0 ; i<concepts.size() ; i++)
02518     {
02519         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02520         loc1.SetConcept(concepts[i]);
02521         svm_problem* problem1 = SvmProblemRepository().Get(loc1);
02522         loc2.SetConcept(concepts[i]);
02523         svm_problem* problem2 = SvmProblemRepository().Get(loc2);
02524         SvmProblemDiff(problem1, problem2);
02525         DestroySvmProblem(problem1);
02526         DestroySvmProblem(problem2);
02527     }
02528 }
02529 
02530 void
02531 DoCopySvmProblem()
02532 {
02533     ILOG_VAR(Impala.Application.Repository.DoCopyDiffSvmProblem);
02534     CmdOptions& options = CmdOptions::GetInstance();
02535 
02536     ModelLocator loc1 = GetModelLocator(options, true);
02537     ModelLocator loc2 = GetModelLocator(options, false);
02538     KeywordList concepts = GetModelKeywordList(loc1);
02539     for (int i=0 ; i<concepts.size() ; i++)
02540     {
02541         loc1.SetConcept(concepts[i]);
02542         svm_problem* problem = SvmProblemRepository().Get(loc1);
02543         loc2.SetConcept(concepts[i]);
02544         SvmProblemRepository().Add(loc2, problem);
02545         delete problem;
02546     }
02547 }
02548 
02549 void
02550 DoDeleteSvmProblem()
02551 {
02552     ILOG_VAR(Impala.Application.Repository.DoDeleteSvmProblem);
02553 
02554     CmdOptions& options = CmdOptions::GetInstance();
02555     ModelLocator loc = GetModelLocator(options, true);
02556     KeywordList concepts = GetModelKeywordList(loc);
02557     for (int i=0 ; i<concepts.size() ; i++)
02558     {
02559         loc.SetConcept(concepts[i]);
02560         SvmProblemRepository().Delete(loc);
02561     }
02562 }
02563 
02564 void
02565 DoDumpModel()
02566 {
02567     ILOG_VAR(Impala.Application.Repository.DoDumpModel);
02568     CmdOptions& options = CmdOptions::GetInstance();
02569 
02570     ModelLocator loc = GetModelLocator(options, true);
02571     KeywordList concepts = GetModelKeywordList(loc);
02572     for (int i=0 ; i<concepts.size() ; i++)
02573     {
02574         loc.SetConcept(concepts[i]);
02575         Svm* svm = SvmRepository().Get(loc);
02576         Dump(svm->GetModel(), -1);
02577         delete svm;
02578     }
02579 }
02580 
02581 void
02582 DoDiffModel()
02583 {
02584     ILOG_VAR(Impala.Application.Repository.DoDiffModel);
02585     CmdOptions& options = CmdOptions::GetInstance();
02586 
02587     ModelLocator loc1 = GetModelLocator(options, true);
02588     ModelLocator loc2 = GetModelLocator(options, false);
02589     KeywordList concepts = GetModelKeywordList(loc1);
02590     for (int i=0 ; i<concepts.size() ; i++)
02591     {
02592         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02593         loc1.SetConcept(concepts[i]);
02594         Svm* svm1 = SvmRepository().Get(loc1);
02595         loc2.SetConcept(concepts[i]);
02596         Svm* svm2 = SvmRepository().Get(loc2);
02597         svm1->ReferenceDiff(svm2);
02598         delete svm1;
02599         delete svm2;
02600     }
02601 }
02602 
02603 void
02604 DoCopyModel()
02605 {
02606     ILOG_VAR(Impala.Application.Repository.DoCopyDiffModel);
02607     CmdOptions& options = CmdOptions::GetInstance();
02608 
02609     ModelLocator loc1 = GetModelLocator(options, true);
02610     ModelLocator loc2 = GetModelLocator(options, false);
02611     KeywordList concepts = GetModelKeywordList(loc1);
02612     for (int i=0 ; i<concepts.size() ; i++)
02613     {
02614         loc1.SetConcept(concepts[i]);
02615         Svm* svm = SvmRepository().Get(loc1);
02616         loc2.SetConcept(concepts[i]);
02617         SvmRepository().Add(loc2, svm);
02618         delete svm;
02619     }
02620 }
02621 
02622 void
02623 DoDeleteModel()
02624 {
02625     ILOG_VAR(Impala.Application.Repository.DoDeleteModel);
02626     CmdOptions& options = CmdOptions::GetInstance();
02627 
02628     ModelLocator loc = GetModelLocator(options, true);
02629     if (loc.GetConceptSet() == "ALL") // This is a bit rude, use with care
02630         return SvmRepository().Delete(loc);
02631 
02632     KeywordList concepts = GetModelKeywordList(loc);
02633     for (int i=0 ; i<concepts.size() ; i++)
02634     {
02635         loc.SetConcept(concepts[i]);
02636         SvmRepository().Delete(loc);
02637     }
02638 }
02639 
02640 void
02641 DoDiffAllParameterFile()
02642 {
02643     typedef Util::PropertySet PropertySet;
02644     ILOG_VAR(Impala.Application.Repository.DoDiffAllParameterFile);
02645     CmdOptions& options = CmdOptions::GetInstance();
02646 
02647     ModelLocator loc1 = GetModelLocator(options, true);
02648     ModelLocator loc2 = GetModelLocator(options, false);
02649     KeywordList concepts = GetModelKeywordList(loc1);
02650     for (int i=0 ; i<concepts.size() ; i++)
02651     {
02652         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02653         loc1.SetConcept(concepts[i]);
02654         std::vector<PropertySet*> v1 = *(AllParameterFileRepository().Get(loc1));
02655         loc2.SetConcept(concepts[i]);
02656         std::vector<PropertySet*> v2 = (*AllParameterFileRepository().Get(loc2));
02657         for (int p=0 ; p<v1.size() ; p++)
02658         {
02659             v1[p]->Diff(v2[p]);
02660             delete v1[p];
02661             delete v2[p];
02662         }
02663     }
02664 }
02665 
02666 void
02667 DoDiffScoreFile()
02668 {
02669     ILOG_VAR(Impala.Application.Repository.DoDiffScoreFile);
02670     CmdOptions& options = CmdOptions::GetInstance();
02671 
02672     ModelLocator loc1 = GetModelLocator(options, true);
02673     ModelLocator loc2 = GetModelLocator(options, false);
02674     KeywordList concepts = GetModelKeywordList(loc1);
02675     for (int i=0 ; i<concepts.size() ; i++)
02676     {
02677         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02678         loc1.SetConcept(concepts[i]);
02679         Util::PropertySet* scoreFile1 = ScoreFileRepository().Get(loc1);
02680         loc2.SetConcept(concepts[i]);
02681         Util::PropertySet* scoreFile2 = ScoreFileRepository().Get(loc2);
02682         scoreFile1->Diff(scoreFile2);
02683         delete scoreFile1;
02684         delete scoreFile2;
02685     }
02686 }
02687 
02688 void
02689 DoDumpFikSvm()
02690 {
02691     ILOG_VAR(Impala.Application.Repository.DoDumpFikSvm);
02692     CmdOptions& options = CmdOptions::GetInstance();
02693 
02694     ModelLocator loc = GetModelLocator(options, true);
02695     KeywordList concepts = GetModelKeywordList(loc);
02696     for (int i=0 ; i<concepts.size() ; i++)
02697     {
02698         loc.SetConcept(concepts[i]);
02699         FikSvm* svm = FikSvmRepository().Get(loc);
02700         svm->Dump(i, 3);
02701         delete svm;
02702     }
02703 }
02704 
02705 void
02706 DoDiffFikSvm()
02707 {
02708     ILOG_VAR(Impala.Application.Repository.DoDiffFikSvm);
02709     CmdOptions& options = CmdOptions::GetInstance();
02710 
02711     ModelLocator loc1 = GetModelLocator(options, true);
02712     ModelLocator loc2 = GetModelLocator(options, false);
02713     KeywordList concepts = GetModelKeywordList(loc1);
02714     for (int i=0 ; i<concepts.size() ; i++)
02715     {
02716         ILOG_INFO("Checking " << i << " = " << concepts[i]);
02717         loc1.SetConcept(concepts[i]);
02718         FikSvm* svm1 = FikSvmRepository().Get(loc1);
02719         loc2.SetConcept(concepts[i]);
02720         FikSvm* svm2 = FikSvmRepository().Get(loc2);
02721         svm1->Diff(svm2);
02722         delete svm1;
02723         delete svm2;
02724     }
02725 }
02726 
02727 // KernelMatrix part, work in progress...
02728 
02729 KernelMatrixLocator
02730 GetKernelMatrixLocator(CmdOptions& options, bool getSrcLoc)
02731 {
02732     ILOG_VAR(Impala.Application.Repository.GetKernelMatrixLocator);
02733 
02734     int nrArg = 9;
02735     if (!getSrcLoc)
02736         nrArg++;
02737     if (options.GetNrArg() < nrArg)
02738     {
02739         ILOG_ERROR("Need at least " << nrArg << " parameters");
02740     }
02741 
02742     int a = 1;
02743     String locString = options.GetArg(a++);
02744     String setName = options.GetArg(a++);
02745     bool isIndex = StringToBool(options.GetArg(a++));
02746     String walkType = options.GetArg(a++);
02747     String annoSet = options.GetArg(a++);
02748     String model = options.GetArg(a++);
02749     String feature = options.GetArg(a++);
02750     String container = options.GetArg(a++);
02751     if (!getSrcLoc)
02752         locString = options.GetArg(a++);
02753     if ((annoSet == "nil") || (annoSet == "empty"))
02754         annoSet = "";
02755     KernelMatrixLocator loc(locString, setName, isIndex, walkType, annoSet,
02756                             model, feature, container);
02757     loc.SetStartNode(0);
02758     loc.SetNodeCount(1);
02759     return loc;
02760 }
02761 
02762 void
02763 DoDumpKernelMatrix()
02764 {
02765     ILOG_VAR(Impala.Application.Repository.DoDumpKernelMatrix);
02766     CmdOptions& options = CmdOptions::GetInstance();
02767 
02768     KernelMatrixLocator loc = GetKernelMatrixLocator(options, true);
02769     RawDataSet* dataSet = GetRawDataSet(options, true);
02770     String container = loc.GetContainer();
02771     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02772     for (int i=0 ; i<nrContainers ; i++)
02773     {
02774         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02775         loc.SetContainer(cur);
02776         KernelMatrix* mat = KernelMatrixRepository().Get(loc);
02777         mat->Dump(0, options.GetInt("start"), options.GetInt("end"));
02778         delete mat;
02779     }
02780 }
02781 
02782 void
02783 DoDiffKernelMatrix()
02784 {
02785     ILOG_VAR(Impala.Application.Repository.DoDiffKernelMatrix);
02786     CmdOptions& options = CmdOptions::GetInstance();
02787 
02788     KernelMatrixLocator loc1 = GetKernelMatrixLocator(options, true);
02789     KernelMatrixLocator loc2 = GetKernelMatrixLocator(options, false);
02790     int a = 10;
02791     if (options.GetNrArg() > a)
02792     {
02793         String walkType2 = options.GetArg(a++);
02794         ILOG_INFO("walkType2 = " << walkType2);
02795         loc2.SetWalkType(walkType2);
02796     }
02797     RawDataSet* dataSet = GetRawDataSet(options, true);
02798     String container = loc1.GetContainer();
02799     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02800     for (int i=0 ; i<nrContainers ; i++)
02801     {
02802         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02803         ILOG_INFO("Checking " << i << " = " << cur);
02804         loc1.SetContainer(cur);
02805         KernelMatrix* mat1 = KernelMatrixRepository().Get(loc1);
02806         loc2.SetContainer(cur);
02807         KernelMatrix* mat2 = KernelMatrixRepository().Get(loc2);
02808         mat1->Diff(mat2);
02809         delete mat2;
02810         delete mat1;
02811     }
02812 }
02813 
02814 void
02815 DoCopyKernelMatrix()
02816 {
02817     ILOG_VAR(Impala.Application.Repository.DoCopyKernelMatrix);
02818     CmdOptions& options = CmdOptions::GetInstance();
02819 
02820     KernelMatrixLocator loc1 = GetKernelMatrixLocator(options, true);
02821     KernelMatrixLocator loc2 = GetKernelMatrixLocator(options, false);
02822     int a = 10;
02823     if (options.GetNrArg() > a)
02824     {
02825         String walkType2 = options.GetArg(a++);
02826         ILOG_INFO("walkType2 = " << walkType2);
02827         loc2.SetWalkType(walkType2);
02828     }
02829     if (options.GetNrArg() > a)
02830     {
02831         bool writeMerged = StringToBool(options.GetArg(a++));
02832         ILOG_INFO("writeMerged = " << writeMerged);
02833         if (writeMerged)
02834             loc2.SetDoParts(3);
02835     }
02836     RawDataSet* dataSet = GetRawDataSet(options, true);
02837     String container = loc1.GetContainer();
02838     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02839     for (int i=0 ; i<nrContainers ; i++)
02840     {
02841         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02842         ILOG_INFO("Checking " << i << " = " << cur);
02843         loc1.SetContainer(cur);
02844         KernelMatrix* mat = KernelMatrixRepository().Get(loc1);
02845         loc2.SetContainer(cur);
02846         if (options.GetBool("sync"))
02847             KernelMatrixRepository().Sync(loc2, mat);
02848         else
02849             KernelMatrixRepository().Add(loc2, mat);
02850         delete mat;
02851     }
02852 }
02853 
02854 void
02855 DoDeleteKernelMatrix()
02856 {
02857     ILOG_VAR(Impala.Application.Repository.DoDeleteKernelMatrix);
02858     CmdOptions& options = CmdOptions::GetInstance();
02859 
02860     KernelMatrixLocator loc = GetKernelMatrixLocator(options, true);
02861     if (loc.GetFeature() == "ALL") // This is a bit rude, use with care
02862         return KernelMatrixRepository().Delete(loc);
02863     RawDataSet* dataSet = GetRawDataSet(options, false);
02864     if (!dataSet)
02865         return;
02866 
02867     String container = loc.GetContainer();
02868     int nrContainers = (container == "ALL") ? dataSet->GetNrContainers() : 1;
02869     for (int i=0 ; i<nrContainers ; i++)
02870     {
02871         String cur = (container == "ALL") ? dataSet->GetContainer(i) : container;
02872         loc.SetContainer(cur);
02873         KernelMatrixRepository().Delete(loc);
02874     }
02875 }
02876 
02877 void
02878 DoKernelMatrix2SimilarityTable()
02879 {
02880     ILOG_VAR(Impala.Application.Repository.DoKernelMatrix2SimilarityTable);
02881     CmdOptions& options = CmdOptions::GetInstance();
02882 
02883     KernelMatrixLocator kLoc = GetKernelMatrixLocator(options, true);
02884     RawDataSet* dataSet = GetRawDataSet(options, true);
02885     KernelMatrix* mat = KernelMatrixRepository().Get(kLoc);
02886     int topN = 100;
02887     int a = 9;
02888     if (options.GetNrArg() > a)
02889     {
02890         topN = atol(options.GetArg(a++));
02891         ILOG_INFO("topN = " << topN);
02892     }
02893     int start = options.GetInt("start");
02894     int end = options.GetInt("end");
02895     if (end == -1)
02896         end = mat->NrRow();
02897 
02898     std::vector<String> names;
02899     for (int i=start ; i<end ; i++)
02900     {
02901         String name = "kernelRow_" + MakeString(i);
02902         names.push_back(name);
02903     }
02904     SimilarityTableSet simSet(names, topN);
02905     QuidTable* quidTab = simSet.GetQuidTable();
02906     for (int i=0 ; i<topN ; i++)
02907         quidTab->Add(0); // quids should not be used!
02908 
02909     std::vector<String> tmpNames;
02910     tmpNames.push_back("tmp");
02911     int rowSize = mat->NrCol();
02912     SimilarityTableSet tmpSet(tmpNames, rowSize);
02913     QuidTable* tmpQuidTab = tmpSet.GetQuidTable();
02914     Core::Table::Copy(tmpQuidTab, mat->GetQuids());
02915     SimilarityTableSet::SimTableType* tmpSimTab = tmpSet.GetSimTable(0);
02916     for (int i=start ; i<end ; i++)
02917     {
02918         Real64* simData = tmpSimTab->GetColumn1()->GetData();
02919         int res = mat->GetRow(i, simData, rowSize);
02920         tmpSimTab->SetSize(res);
02921 
02922         int tabNr = i - start;
02923         SimilarityTableSet::SimTableType* simTab = simSet.GetSimTable(tabNr);
02924         SimilarityTableSet::RankTableType* rankTab = simSet.GetRankTable(tabNr);
02925         simTab->SetSize(topN);
02926         rankTab->SetSize(topN);
02927         Core::Column::SortDescendingTopN(tmpQuidTab->GetColumn1(),
02928                                          tmpSimTab->GetColumn1(),
02929                                          rankTab->GetColumn1(),
02930                                          simTab->GetColumn1());
02931     }
02932     delete mat;
02933 
02934     SimilarityTableSetLocator sLoc(kLoc, kLoc.GetIsIndex(), kLoc.GetWalkType(),
02935                                    "kernel.txt", "direct", kLoc.GetFeature(),
02936                                    kLoc.GetContainer());
02937     SimilarityTableSetRepository().Add(sLoc, &simSet);
02938 }
02939 
02940 void
02941 DoKernelMatrix2Text()
02942 {
02943     ILOG_VAR(Impala.Application.Repository.DoKernelMatrix2Text);
02944     CmdOptions& options = CmdOptions::GetInstance();
02945 
02946     KernelMatrixLocator kLoc = GetKernelMatrixLocator(options, true);
02947     RawDataSet* dataSet = GetRawDataSet(options, true);
02948     KernelMatrix* mat = KernelMatrixRepository().Get(kLoc);
02949     int topN = 100;
02950     int a = 9;
02951     if (options.GetNrArg() > a)
02952     {
02953         topN = atol(options.GetArg(a++));
02954         ILOG_INFO("topN = " << topN);
02955     }
02956     int start = options.GetInt("start");
02957     int end = options.GetInt("end");
02958     if (end == -1)
02959         end = mat->NrRow();
02960 
02961     RepositoryInFileSystem& repFS = RepositoryInFileSystem::GetInstance();
02962     String fName = dataSet->GetSetNameBase() + "_top" + MakeString(topN);
02963     if ((start != 0) || (end != mat->NrRow()))
02964         fName += "_rows" + MakeString(start) + "-" + MakeString(end);
02965     fName += ".txt";
02966     FileLocator loc(fName);
02967     Persistency::File file = repFS.GetFile(loc, true, false);
02968     if (!file.Valid())
02969         return;
02970     Util::IOBuffer* ioBuf = file.GetWriteBuffer();
02971     if (!ioBuf)
02972         return;
02973 
02974     int rowSize = mat->NrCol();
02975     QuidTable* allQuids = mat->GetQuids();
02976     SimilarityTableSet::SimTableType rowSims(rowSize);
02977     QuidTable topQuids(topN);
02978     SimilarityTableSet::SimTableType topSims(topN);
02979     ILOG_INFO("Processing " << start << "-" << end);
02980     for (int i=start ; i<end ; i++)
02981     {
02982         if (i % 100 == 0)
02983             ILOG_INFO("doing row " << i);
02984         Real64* simData = rowSims.GetColumn1()->GetData();
02985         int res = mat->GetRow(i, simData, rowSize);
02986         rowSims.SetSize(res);
02987 
02988         Core::Column::SortDescendingTopN(allQuids->GetColumn1(),
02989                                          rowSims.GetColumn1(),
02990                                          topQuids.GetColumn1(),
02991                                          topSims.GetColumn1());
02992         String s = MakeString(i) + " : ";
02993         for (int j=0 ; j<topN ; j++)
02994         {
02995             Quid q = topQuids.Get1(j);
02996             int fileId = dataSet->GetFileIdOfQuid(q);
02997             String path = dataSet->GetAsPath(fileId);
02998             s += "\"" + path + "\", ";
02999         }
03000         ioBuf->Puts(s);
03001     }
03002     ILOG_INFO("Done");
03003     delete ioBuf;
03004     delete mat;
03005 }
03006 
03007 // misc part
03008 
03009 void
03010 DoSyncFile()
03011 {
03012     ILOG_VAR(Impala.Application.Repository.DoSyncFile);
03013     CmdOptions& options = CmdOptions::GetInstance();
03014 
03015     int nrArg = 4;
03016     if (options.GetNrArg() < nrArg)
03017     {
03018         ILOG_ERROR("Need at least " << nrArg << " parameters");
03019     }
03020 
03021     String locString1 = options.GetArg(1);
03022     String setName = options.GetArg(2);
03023     String fileName = options.GetArg(3);
03024     String locString2 = options.GetArg(4);
03025 
03026     FileLocator srcLoc(locString1, setName, fileName);
03027     FileLocator dstLoc(locString2, setName, fileName);
03028     RepositoryInFileSystem::GetInstance().CopyFile(srcLoc, dstLoc);
03029 }
03030 
03031 int
03032 mainRepository(int argc, char* argv[])
03033 {
03034     CmdOptions& options = CmdOptions::GetInstance();
03035     options.Initialise(true, false, true);
03036     options.AddOption(0, "start", "nr", "0");
03037     options.AddOption(0, "end", "nr", "-1");
03038     options.AddOption(0, "tolerance", "tolerance for difference in double values", "1e-14");
03039     options.AddOption(0, "sync", "", "0");
03040     String usageStr = "cmd = \n\n";
03041     usageStr += "  dumpimagesets\n";
03042     usageStr += "  dumpvideosets\n";
03043     usageStr += "  copyvideosets dstLocation\n";
03044     usageStr += "  dumpimageset location imageset.txt\n";
03045     usageStr += "  diffimageset location1 imageset.txt location2\n";
03046     usageStr += "  copyimageset location1 imageset.txt location2\n";
03047     usageStr += "  deleteimageset location imageset.txt\n";
03048     usageStr += "  syncimagefiles location1 imageset.txt location2\n";
03049     usageStr += "  dumpspecialimageset location videoset.txt imageset.txt\n";
03050     usageStr += "  diffspecialimageset location1 videoset.txt imageset.txt location2\n";
03051     usageStr += "  copyspecialimageset location1 videoset.txt imageset.txt location2\n";
03052     usageStr += "  dumpvideoset location videoset.txt\n";
03053     usageStr += "  diffvideoset location1 videoset.txt location2\n";
03054     usageStr += "  copyvideoset location1 videoset.txt location2\n";
03055     usageStr += "  deletevideoset location videoset.txt\n";
03056     usageStr += "  syncvideofiles location1 videoset.txt doInfoFiles location2\n";
03057     usageStr += "  deletevideoinfofiles location videoset.txt\n";
03058     usageStr += "  dumpframehashes location videoset.txt\n";
03059     usageStr += "  diffframehashes location1 videoset.txt location2\n";
03060     usageStr += "  copyframehashes location1 videoset.txt location2\n";
03061     usageStr += "  dumpsegmentation location videoset.txt\n";
03062     usageStr += "  diffsegmentation location1 videoset.txt location2\n";
03063     usageStr += "  copysegmentation location1 videoset.txt location2\n";
03064     usageStr += "  deletesegmentation location videoset.txt\n";
03065     usageStr += "  dumpkeyframes location videoset.txt\n";
03066     usageStr += "  diffkeyframes location1 videoset.txt location2\n";
03067     usageStr += "  copykeyframes location1 videoset.txt location2\n";
03068     usageStr += "  deletekeyframes location videoset.txt\n";
03069     usageStr += "  dumpstills location videoset.txt\n";
03070     usageStr += "  diffstills location1 videoset.txt location2\n";
03071     usageStr += "  copystills location1 videoset.txt location2\n";
03072     usageStr += "  deletestills location videoset.txt\n";
03073     usageStr += "  dumpquidtable location dataset.txt dir name\n";
03074     usageStr += "  diffquidtable location1 dataset.txt dir name location2\n";
03075     usageStr += "  copyquidtable location1 dataset.txt dir name location2\n";
03076     usageStr += "  deletequidtable location dataset.txt dir name\n";
03077     usageStr += "  dumpmpeg7shot location videoset.txt container\n";
03078     usageStr += "  diffmpeg7shot location1 videoset.txt container location2\n";
03079     usageStr += "  copympeg7shot location1 videoset.txt container location2\n";
03080     usageStr += "  deletempeg7shot location videoset.txt container\n";
03081     usageStr += "  deletempeg7annotation location videoset.txt container\n";
03082     usageStr += "  deletempeg7concept location videoset.txt container\n";
03083     usageStr += "  dumpimagearchive location dataset.txt isFrames container name.raw\n";
03084     usageStr += "  diffimagearchive location1 dataset.txt isFrames container name.raw location2\n";
03085     usageStr += "  copyimagearchive location1 dataset.txt isFrames container name.raw location2\n";
03086     usageStr += "  deleteimagearchive location dataset.txt isFrames container name.raw\n";
03087     usageStr += "  dumpimagearchivespecial location videoset.txt imageset.txt container name.raw\n";
03088     usageStr += "  diffimagearchivespecial location1 videoset.txt imageset.txt container name.raw location2\n";
03089     usageStr += "  copyimagearchivespecial location1 videoset.txt imageset.txt container name.raw location2\n";
03090     usageStr += "  deleteimagearchivespecial location videoset.txt imageset.txt container name.raw\n";
03091     usageStr += "  dumpfeaturetable location dataset.txt isCodebook isIndex walkType feature container\n";
03092     usageStr += "  difffeaturetable location1 dataset.txt isCodebook isIndex walkType feature container location2\n";
03093     usageStr += "  copyfeaturetable location1 dataset.txt isCodebook isIndex walkType feature container location2\n";
03094     usageStr += "  deletefeaturetable location dataset.txt isCodebook isIndex walkType feature container\n";
03095     usageStr += "  setquidsetfeaturetable location dataset.txt isCodebook isIndex walkType feature container setId\n";
03096     usageStr += "  dumpkeywordlist location videoset.txt concepts.txt\n";
03097     usageStr += "  diffkeywordlist location1 videoset.txt concepts.txt location2\n";
03098     usageStr += "  copykeywordlist location1 videoset.txt concepts.txt location2\n";
03099     usageStr += "  dumpannotationtable location dataset.txt quidClass concepts.txt keyword\n";
03100     usageStr += "  diffannotationtable location1 dataset.txt quidClass concepts.txt keyword location2\n";
03101     usageStr += "  copyannotationtable location1 dataset.txt quidClass concepts.txt keyword location2\n";
03102     usageStr += "  deleteannotationtable location dataset.txt quidClass concepts.txt keyword\n";
03103     usageStr += "  mergeannotationtable location dataset.txt quidClass concepts.txt outputkeyword [inputkeyword]+ \n";
03104     usageStr += "  dumpannotationtableset location dataset.txt quidClass concepts.txt doTable [maxVidId maxPos maxNeg]\n";
03105     usageStr += "  diffannotationtableset location1 dataset.txt quidClass concepts.txt location2\n";
03106     usageStr += "  copyannotationtableset location1 dataset.txt quidClass concepts.txt location2\n";
03107     usageStr += "  deleteannotationtableset location dataset.txt quidClass concepts.txt\n";
03108     usageStr += "  mergeannotationtableset [inputlocation inputdataset.txt inputquidClass inputconcepts.txt]+ outputlocation outputdataset.txt outputquidClass outputconcepts.txt \n";
03109     usageStr += "  correctannotationtableset location dataset.txt quidClass conceptsOriginal.txt conceptsCorrections.txt conceptsResult.txt\n";
03110     usageStr += "  selectannotationtableset location dataset.txt quidClass concepts.txt concept iteration\n";
03111     usageStr += "  indexannotatedfeatures location dataset.txt quidClass concepts.txt feature\n";
03112     usageStr += "  dumpfold location dataset.txt quidClass concepts.txt keyword foldType foldNr\n";
03113     usageStr += "  difffold location1 dataset.txt quidClass concepts.txt keyword foldType foldNr location2\n";
03114     usageStr += "  copyfold location1 dataset.txt quidClass concepts.txt keyword foldType foldNr location2\n";
03115     usageStr += "  deletefold location dataset.txt quidClass concepts.txt keyword foldType foldNr\n";
03116     usageStr += "  dumpsimilaritytableset location dataset.txt isIndex walkType conceptSet.txt model feature container [dumpAsMatrix dumpQuid]\n";
03117     usageStr += "  diffsimilaritytableset location1 dataset.txt isIndex walkType conceptSet.txt model feature container location2\n";
03118     usageStr += "  copysimilaritytableset location1 dataset.txt isIndex walkType conceptSet.txt model feature container location2\n";
03119     usageStr += "  deletesimilaritytableset location dataset.txt isIndex walkType conceptSet.txt model feature container\n";
03120     usageStr += "  mergesimilaritytableset location1 dataset.txt isIndex walkType dstConceptSet.txt model feature container srcConceptSet1 srcConceptSet2 [srcConceptSetN]\n";
03121     usageStr += "  dumpbestfile location dataset.txt conceptSet.txt model feature concept\n";
03122     usageStr += "  diffbestfile location1 dataset.txt conceptSet.txt model feature concept location2\n";
03123     usageStr += "  copybestfile location1 dataset.txt conceptSet.txt model feature concept location2\n";
03124     usageStr += "  dumpsvmproblem location dataset.txt conceptSet.txt model feature concept\n";
03125     usageStr += "  diffsvmproblem location1 dataset.txt conceptSet.txt model feature concept location2\n";
03126     usageStr += "  copysvmproblem location1 dataset.txt conceptSet.txt model feature concept location2\n";
03127     usageStr += "  deletesvmproblem location dataset.txt conceptSet.txt model feature concept\n";
03128     usageStr += "  dumpmodel location dataset.txt conceptSet.txt model feature concept\n";
03129     usageStr += "  diffmodel location1 dataset.txt conceptSet.txt model feature concept location2\n";
03130     usageStr += "  copymodel location1 dataset.txt conceptSet.txt model feature concept location2\n";
03131     usageStr += "  deletemodel location dataset.txt conceptSet.txt model feature concept\n";
03132     usageStr += "  diffallparameterfile location1 dataset.txt conceptSet.txt model feature concept location2\n";
03133     usageStr += "  diffscorefile location1 dataset.txt conceptSet.txt model feature concept location2\n";
03134     usageStr += "  dumpfiksvm location dataset.txt conceptSet.txt model feature concept\n";
03135     usageStr += "  difffiksvm location1 dataset.txt conceptSet.txt model feature concept location2\n";
03136     usageStr += "  dumpkernelmatrix location dataset.txt isIndex walkType annoSet.txt model feature container\n";
03137     usageStr += "  diffkernelmatrix location1 dataset.txt isIndex walkType annoSet.txt model feature container location2\n";
03138     usageStr += "  copykernelmatrix location1 dataset.txt isIndex walkType annoSet.txt model feature container location2 [walkType2] [writeMerged2]\n";
03139     usageStr += "  deletekernelmatrix location dataset.txt isIndex walkType annoSet.txt model feature container\n";
03140     usageStr += "  kernelmatrix2similaritytable location dataset.txt isIndex walkType annoSet.txt model feature container [topN]\n";
03141     usageStr += "  kernelmatrix2text location dataset.txt isIndex walkType annoSet.txt model feature container [topN]\n";
03142     usageStr += "  syncfile location1 dataset.txt filename location2\n";
03143     if (! options.ParseArgs(argc, argv, usageStr, 1))
03144         return 1;
03145 
03146     ILOG_VAR(Impala.Application.Repository.mainRepository);
03147 
03148     String cmd = options.GetArg(0);
03149     ILOG_DEBUG("cmd = " << cmd);
03150     if (cmd == "dumpimagesets")
03151         DoDumpImageSets();
03152     else if (cmd == "dumpvideosets")
03153         DoDumpVideoSets();
03154     else if (cmd == "copyvideosets")
03155         DoCopyVideoSets();
03156     else if (cmd == "dumpimageset")
03157         DoDumpImageSet();
03158     else if (cmd == "diffimageset")
03159         DoDiffImageSet();
03160     else if (cmd == "copyimageset")
03161         DoCopyImageSet();
03162     else if (cmd == "deleteimageset")
03163         DoDeleteImageSet();
03164     else if (cmd == "syncimagefiles")
03165         DoSyncImageFiles();
03166     else if (cmd == "dumpimagesetspecial")
03167         DoDumpImageSetSpecial();
03168     else if (cmd == "diffimagesetspecial")
03169         DoDiffImageSetSpecial();
03170     else if (cmd == "copyimagesetspecial")
03171         DoCopyImageSetSpecial();
03172     else if (cmd == "deleteimagesetspecial")
03173         DoDeleteImageSetSpecial();
03174     else if (cmd == "dumpvideoset")
03175         DoDumpVideoSet();
03176     else if (cmd == "diffvideoset")
03177         DoDiffVideoSet();
03178     else if (cmd == "copyvideoset")
03179         DoCopyVideoSet();
03180     else if (cmd == "deletevideoset")
03181         DoDeleteVideoSet();
03182     else if (cmd == "syncvideofiles")
03183         DoSyncVideoFiles();
03184     else if (cmd == "deletevideoinfofiles")
03185         DoDeleteVideoInfoFiles();
03186     else if (cmd == "dumpframehashes")
03187         DoDumpFrameHashes();
03188     else if (cmd == "diffframehashes")
03189         DoDiffFrameHashes();
03190     else if (cmd == "copyframehashes")
03191         DoCopyFrameHashes();
03192     else if (cmd == "dumpsegmentation")
03193         DoDumpSegmentation();
03194     else if (cmd == "diffsegmentation")
03195         DoDiffSegmentation();
03196     else if (cmd == "copysegmentation")
03197         DoCopySegmentation();
03198     else if (cmd == "deletesegmentation")
03199         DoDeleteSegmentation();
03200     else if (cmd == "dumpkeyframes")
03201         DoDumpKeyframes();
03202     else if (cmd == "diffkeyframes")
03203         DoDiffKeyframes();
03204     else if (cmd == "copykeyframes")
03205         DoCopyKeyframes();
03206     else if (cmd == "deletekeyframes")
03207         DoDeleteKeyframes();
03208     else if (cmd == "dumpstills")
03209         DoDumpStills();
03210     else if (cmd == "diffstills")
03211         DoDiffStills();
03212     else if (cmd == "copystills")
03213         DoCopyStills();
03214     else if (cmd == "deletestills")
03215         DoDeleteStills();
03216     else if (cmd == "dumpquidtable")
03217         DoDumpQuidTable();
03218     else if (cmd == "diffquidtable")
03219         DoDiffQuidTable();
03220     else if (cmd == "copyquidtable")
03221         DoCopyQuidTable();
03222     else if (cmd == "deletequidtable")
03223         DoDeleteQuidTable();
03224     else if (cmd == "dumpmpeg7shot")
03225         DoDumpMpeg7Shot();
03226     else if (cmd == "diffmpeg7shot")
03227         DoDiffMpeg7Shot();
03228     else if (cmd == "copympeg7shot")
03229         DoCopyMpeg7Shot();
03230     else if (cmd == "deletempeg7shot")
03231         DoDeleteMpeg7Shot();
03232     else if (cmd == "deletempeg7annotation")
03233         DoDeleteMpeg7Annotation();
03234     else if (cmd == "deletempeg7concept")
03235         DoDeleteMpeg7Concept();
03236     else if (cmd == "dumpimagearchive")
03237         DoDumpImageArchive();
03238     else if (cmd == "diffimagearchive")
03239         DoDiffImageArchive();
03240     else if (cmd == "copyimagearchive")
03241         DoCopyImageArchive();
03242     else if (cmd == "deleteimagearchive")
03243         DoDeleteImageArchive();
03244     else if (cmd == "dumpimagearchivespecial")
03245         DoDumpImageArchiveSpecial();
03246     else if (cmd == "diffimagearchivespecial")
03247         DoDiffImageArchiveSpecial();
03248     else if (cmd == "copyimagearchivespecial")
03249         DoCopyImageArchiveSpecial();
03250     else if (cmd == "deleteimagearchivespecial")
03251         DoDeleteImageArchiveSpecial();
03252     else if (cmd == "dumpfeaturetable")
03253         DoDumpFeatureTable();
03254     else if (cmd == "difffeaturetable")
03255         DoDiffFeatureTable();
03256     else if (cmd == "copyfeaturetable")
03257         DoCopyFeatureTable();
03258     else if (cmd == "deletefeaturetable")
03259         DoDeleteFeatureTable();
03260     else if (cmd == "setquidsetfeaturetable")
03261         DoSetQuidSetFeatureTable();
03262     else if (cmd == "dumpkeywordlist")
03263         DoDumpKeywordList();
03264     else if (cmd == "diffkeywordlist")
03265         DoDiffKeywordList();
03266     else if (cmd == "copykeywordlist")
03267         DoCopyKeywordList();
03268     else if (cmd == "dumpannotationtable")
03269         DoDumpAnnotationTable();
03270     else if (cmd == "diffannotationtable")
03271         DoDiffAnnotationTable();
03272     else if (cmd == "copyannotationtable")
03273         DoCopyAnnotationTable();
03274     else if (cmd == "deleteannotationtable")
03275         DoDeleteAnnotationTable();
03276     else if (cmd == "mergeannotationtable")
03277         DoMergeAnnotationTable();
03278     else if (cmd == "dumpannotationtableset")
03279         DoDumpAnnotationTableSet();
03280     else if (cmd == "diffannotationtableset")
03281         DoDiffAnnotationTableSet();
03282     else if (cmd == "copyannotationtableset")
03283         DoCopyAnnotationTableSet();
03284     else if (cmd == "deleteannotationtableset")
03285         DoDeleteAnnotationTableSet();
03286     else if (cmd == "mergeannotationtableset")
03287         DoMergeAnnotationTableSet();
03288     else if (cmd == "correctannotationtableset")
03289         DoCorrectAnnotationTableSet();
03290     else if (cmd == "selectannotationtableset")
03291         DoSelectAnnotationTableSet();
03292     else if (cmd == "indexannotatedfeatures")
03293         DoIndexAnnotatedFeatures();
03294     else if (cmd == "dumpfold")
03295         DoDumpFold();
03296     else if (cmd == "difffold")
03297         DoDiffFold();
03298     else if (cmd == "copyfold")
03299         DoCopyFold();
03300     else if (cmd == "deletefold")
03301         DoDeleteFold();
03302     else if (cmd == "dumpsimilaritytableset")
03303         DoDumpSimilarityTableSet();
03304     else if (cmd == "diffsimilaritytableset")
03305         DoDiffSimilarityTableSet();
03306     else if (cmd == "copysimilaritytableset")
03307         DoCopySimilarityTableSet();
03308     else if (cmd == "deletesimilaritytableset")
03309         DoDeleteSimilarityTableSet();
03310     else if (cmd == "mergesimilaritytableset")
03311         DoMergeSimilarityTableSet();
03312     else if (cmd == "dumpbestfile")
03313         DoDumpBestFile();
03314     else if (cmd == "diffbestfile")
03315         DoDiffBestFile();
03316     else if (cmd == "copybestfile")
03317         DoCopyBestFile();
03318     else if (cmd == "dumpsvmproblem")
03319         DoDumpSvmProblem();
03320     else if (cmd == "diffsvmproblem")
03321         DoDiffSvmProblem();
03322     else if (cmd == "copysvmproblem")
03323         DoCopySvmProblem();
03324     else if (cmd == "deletesvmproblem")
03325         DoDeleteSvmProblem();
03326     else if (cmd == "dumpmodel")
03327         DoDumpModel();
03328     else if (cmd == "diffmodel")
03329         DoDiffModel();
03330     else if (cmd == "copymodel")
03331         DoCopyModel();
03332     else if (cmd == "deletemodel")
03333         DoDeleteModel();
03334     else if (cmd == "diffallparameterfile")
03335         DoDiffAllParameterFile();
03336     else if (cmd == "diffscorefile")
03337         DoDiffScoreFile();
03338     else if (cmd == "dumpfiksvm")
03339         DoDumpFikSvm();
03340     else if (cmd == "difffiksvm")
03341         DoDiffFikSvm();
03342     else if (cmd == "dumpkernelmatrix")
03343         DoDumpKernelMatrix();
03344     else if (cmd == "diffkernelmatrix")
03345         DoDiffKernelMatrix();
03346     else if (cmd == "copykernelmatrix")
03347         DoCopyKernelMatrix();
03348     else if (cmd == "deletekernelmatrix")
03349         DoDeleteKernelMatrix();
03350     else if (cmd == "kernelmatrix2similaritytable")
03351         DoKernelMatrix2SimilarityTable();
03352     else if (cmd == "kernelmatrix2text")
03353         DoKernelMatrix2Text();
03354     else if (cmd == "syncfile")
03355         DoSyncFile();
03356     else ILOG_ERROR("Unknown cmd : " << cmd);
03357 
03358     int nrOfErrors = ILOG_ERROR_COUNT;
03359     ILOG_INFO_HEADNODE("Done, total nr error = " << nrOfErrors);
03360     return nrOfErrors;
03361 }
03362 
03363 } // namespace Repository
03364 } // namespace Application
03365 } // namespace Impala
03366 
03367 int
03368 main(int argc, char* argv[])
03369 {
03370 
03371 #ifdef NO_DIALOGONCRASH
03372 #ifdef WIN32
03373     DWORD oldMode = ::SetErrorMode(SEM_NOGPFAULTERRORBOX);
03374     ::SetErrorMode(oldMode | SEM_NOGPFAULTERRORBOX);
03375 #endif
03376 #endif
03377 
03378     return Impala::Application::Repository::mainRepository(argc, argv);
03379 }

Generated on Thu Jan 13 09:03:43 2011 for ImpalaSrc by  doxygen 1.5.1