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

AnnotationTableSet.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Table_AnnotationTableSet_h
00002 #define Impala_Core_Table_AnnotationTableSet_h
00003 
00004 #include <vector>
00005 #include "Core/Table/KeywordList.h"
00006 #include "Core/Table/AnnotationTable.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Table
00013 {
00014 
00015 
00016 // basically a wrapper around std::vector of AnnotationTables.
00017 class AnnotationTableSet
00018 {
00019 public:
00020 
00021     AnnotationTableSet()
00022     {
00023     }
00024 
00025     AnnotationTableSet(KeywordList labels, int tableSize)
00026     {
00027         for (size_t i=0 ; i<labels.size() ; i++)
00028         {
00029             AnnotationTable* tab = new AnnotationTable(labels[i], 0);
00030             Add(tab);
00031         }
00032     }
00033 
00034     ~AnnotationTableSet()
00035     {
00036         // no destruction of elements, as std::vector doesn't do it either
00037         //for (int i=0 ; i<mTables.size() ; i++)
00038         //    delete mTables[i];
00039     }
00040 
00041 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00042     static AnnotationTableSet*
00043     MakeFromFile(Database::RawDataSet* dataSet, CString labelSet,
00044                  bool readTables, int quidClass)
00045     {
00046         String fName = dataSet->GetFilePathAnnotation(labelSet, false, false);
00047         if (fName.empty())
00048         {
00049             ILOG_ERROR("Unable to read labels");
00050             return 0;
00051         }
00052         Util::Database* db = dataSet->GetDatabase();
00053         std::vector<String> labels;
00054         Util::DatabaseReadStrings(labels, fName, db);
00055 
00056         AnnotationTableSet* res = new AnnotationTableSet();
00057         int nrRead = 0;
00058         for (int i=0 ; i<labels.size() ; i++)
00059         {
00060             AnnotationTable* table = 0;
00061             if (readTables)
00062             {
00063                 fName = dataSet->GetFilePathAnnotation(quidClass, labelSet,
00064                                                        labels[i] + ".tab",
00065                                                        false, true);
00066                 if (! fName.empty())
00067                 {
00068                     table = AnnotationTable::MakeFromFile(labels[i], fName, db);
00069                     nrRead++;
00070                 }
00071             }
00072             if (table == 0)
00073             {
00074                 table = new AnnotationTable(labels[i], 0);
00075             }
00076             res->Add(table);
00077         }
00078         if (readTables && (nrRead == 0))
00079             ILOG_ERROR("No tables found");
00080         return res;
00081     }
00082 #endif // REPOSITORY_USED
00083 
00084     void
00085     Delete() // requires "explicit call to destructor"
00086     {
00087         for (int i=0 ; i<mTables.size() ; i++)
00088             delete mTables[i];
00089         mTables.clear();
00090     }
00091 
00092     int
00093     Size()
00094     {
00095         return mTables.size();
00096     }
00097 
00098     void
00099     Add(AnnotationTable* table)
00100     {
00101         mTables.push_back(table);
00102     }
00103 
00104     KeywordList
00105     GetLabels() const
00106     {
00107         KeywordList res;
00108         for (int i=0 ; i<mTables.size() ; i++)
00109             res.push_back(GetLabel(i));
00110         return res;
00111     }
00112 
00113     String
00114     GetLabel(int i) const
00115     {
00116         return mTables[i]->GetLabel();
00117     }
00118 
00119     AnnotationTable*
00120     GetTable(int i) const
00121     {
00122         return mTables[i];
00123     }
00124 
00125     // return table with given label
00126     AnnotationTable*
00127     GetTable(CString label)
00128     {
00129         for (int i=0 ; i<mTables.size() ; i++)
00130             if (GetLabel(i) == label)
00131                 return mTables[i];
00132         return 0;
00133     }
00134 
00135     int
00136     Diff(AnnotationTableSet* arg)
00137     {
00138         if (Size() != arg->Size())
00139         {
00140             ILOG_ERROR("Diff: Size differs: " << Size() << " vs " <<
00141                        arg->Size());
00142             return 1;
00143         }
00144         int nDiff = 0;
00145         for (int i=0 ; i<Size() ; i++)
00146         {
00147             if (GetLabel(i) != arg->GetLabel(i))
00148             {
00149                 ILOG_DEBUG("Label " << i << " differs " << GetLabel(i) <<
00150                            " vs " << arg->GetLabel(i));
00151                 nDiff++;
00152             }
00153             else if (GetTable(i)->Diff(arg->GetTable(i)) > 0)
00154             {
00155                 ILOG_DEBUG("Table " << i << " differs ");
00156                 nDiff++;
00157             }
00158         }
00159         if (nDiff > 0)
00160             ILOG_ERROR("Found " << nDiff << " differences");
00161         return nDiff;
00162     }
00163 
00164 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00165     bool
00166     SaveTables(Database::RawDataSet* dataSet, String conceptSet, bool report)
00167     {
00168         bool ok = true;
00169         for (int i=0 ; i<Size() ; i++)
00170         {
00171             AnnotationTable* annoTable = GetTable(i);
00172             if (annoTable->Size() == 0)
00173                 continue;
00174             int qClass = annoTable->GetQuidClass();
00175             String fName = dataSet->GetFilePathAnnotation(qClass, conceptSet,
00176                                                           GetLabel(i) + ".tab",
00177                                                           true, false);
00178             if (fName.empty())
00179             {
00180                 ok = false;
00181                 continue;
00182             }
00183             Write(annoTable, fName, dataSet->GetDatabase(), true);
00184             if (report)
00185                 annoTable->DumpSummary();
00186         }
00187         return ok;
00188     }
00189 #endif // REPOSITORY_USED
00190 
00191     void
00192     Dump(bool doTable)
00193     {
00194         for (int i=0 ; i<mTables.size() ; i++)
00195         {
00196             std::cout << "AnnotationTable " << i << ", label = " << GetLabel(i)
00197                       << std::endl;
00198             if (doTable)
00199                 GetTable(i)->Dump();
00200         }
00201     }
00202 
00203 private:
00204 
00205     std::vector<AnnotationTable*> mTables;
00206 
00207     ILOG_VAR_DEC;
00208 };
00209 
00210 ILOG_VAR_INIT(AnnotationTableSet, Impala.Core.Table);
00211 
00212 } // namespace Table
00213 } // namespace Core
00214 } // namespace Impala
00215 
00216 #endif

Generated on Fri Mar 19 09:31:19 2010 for ImpalaSrc by  doxygen 1.5.1