COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/DataColumn.h
Go to the documentation of this file.
00001 #ifndef SSFOSSIL_DATACOLUMN
00002 #define SSFOSSIL_DATACOLUMN
00003 
00004 #include <coopy/DataSheet.h>
00005 
00006 namespace coopy {
00007   namespace cmp {
00008     class Vote;
00009     class Nature;
00010     class DataColumn;
00011     class DataColumnPair;
00012   }
00013 }
00014 
00015 class coopy::cmp::Vote {
00016 public:
00017   int votes;
00018   float confidence;
00019   float yes;
00020   float no;
00021 
00022   Vote() {
00023     clear();
00024   }
00025 
00026   void clear() {
00027     votes = 0;
00028     confidence = 0;
00029     yes = no = 0;
00030   }
00031 
00032   void vote(float vote, float confidence, bool forward=true) {
00033     if (confidence>1) confidence = 1;
00034     if (confidence<0) confidence = 0;
00035     float vote2 = vote;
00036     if (!forward) vote2*=-1;
00037     if (vote>0) yes += vote2*confidence;
00038     if (vote<0) no += vote2*confidence;
00039     this->confidence += confidence;
00040     if (forward) votes++; else votes--;
00041   }
00042 
00043   float result() {
00044     float v = yes+no;
00045     if (votes>0) {
00046       v /= votes;
00047     }
00048     return v;
00049   }
00050 };
00051 
00052 class coopy::cmp::Nature {
00053 public:
00054   Vote web;
00055   Vote email;
00056   Vote text;
00057   Vote number;
00058   Vote type_integer;
00059   Vote nully;
00060   Vote cappy;
00061   Vote lowy;
00062 
00063   void evaluate(const char *txt, bool forward = true);  
00064 
00065   float compare(const std::string& txt, bool forward, int x);
00066 
00067   //float uncompare(const char *txt, int x) {
00068   //return compare(txt,false,x);
00069   //}
00070 
00071   float confidence();
00072 
00073   void clear() {
00074     web.clear();
00075     email.clear();
00076     text.clear();
00077     number.clear();
00078     type_integer.clear();
00079     nully.clear();
00080     cappy.clear();
00081     lowy.clear();
00082   }
00083 
00084   void show();
00085 
00086   bool couldBeInteger() {
00087     return (type_integer.yes>0.5) && (type_integer.no>-0.5);
00088   }
00089 };
00090 
00091 class coopy::cmp::DataColumn {
00092 private:
00093   const coopy::store::DataSheet *sheet;
00094   int index;
00095   Nature nmean;
00096   int hh;
00097 public:
00098   DataColumn(const coopy::store::DataSheet& owner, int index, int height) {
00099     sheet = &owner;
00100     this->index = index;
00101     hh = height;
00102   }
00103 
00104   void evaluate();
00105 
00106   void unevaluate(int top);
00107   
00108   Nature getNature() { return nmean; }
00109 
00110   int height() {
00111     return hh;
00112   }
00113 
00114   int size() {
00115     return hh;
00116   }
00117 
00118   std::string cell(int x) {
00119     return sheet->cellString(index,x);
00120   }
00121 };
00122 
00123 class coopy::cmp::DataColumnPair {
00124 private:
00125 public:
00126   void compare(DataColumn& a, DataColumn& b);
00127 };
00128 
00129 
00130 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines