00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #ifndef PHIMBL_H
00026 #define PHIMBL_H
00027
00028 using namespace std;
00029
00030 #include <iostream>
00031 #include <string>
00032 #include <vector>
00033 #include <map>
00034 #include <fstream>
00035 #include <sstream>
00036 #include "boss_utility/boss_types.h"
00037
00038 namespace BOSS
00039 {
00040 class Phimbl
00041 {
00042 protected:
00043 struct t_Node
00044 {
00045 t_Node* parent;
00046 int Class;
00047
00048 map <int,int> count;
00049 struct t_Child
00050 {
00051 int Feature;
00052 t_Node* node;
00053 };
00054 vector <t_Child*> child;
00055 t_Node(){parent = NULL;}
00056 };
00057
00058 public:
00059 struct t_Data
00060 {
00061 t_Node* currentNode;
00062 t_Node* root;
00063 vector <int> permutation;
00064 vector <string> classes;
00065 vector <string> features;
00066 t_Data(){currentNode = root = NULL;}
00067 };
00068
00069 protected:
00070 struct t_classes
00071 {
00072 string class_string;
00073 int count;
00074 vector <string> features;
00075 };
00076
00077 struct t_features
00078 {
00079 string feature_string;
00080 int count;
00081 };
00082
00083 vector <t_classes> classes;
00084 vector <vector <t_features> > features;
00085 vector <t_features> allfeatures;
00086 int feature_count;
00087 int line_count;
00088 string seperator;
00089 t_Node* tree;
00090 t_Data Data;
00091
00092 int find_str(string & str, vector <t_classes> & data);
00093 int find_str(string & str, vector <t_features> & data);
00094
00095 void ReduceTree(t_Node * node);
00096 void DeleteNode(t_Node * node);
00097 void SaveTree(t_Node * node, fstream & out);
00098 bool Load(string filename);
00099 void Calculate_Permutation();
00100 void Bulid_Tree(string filename);
00101 void ClassCount(t_Node * node);
00102 bool Save(string outfile);
00103 void Print_Permutation();
00104 void AddChild(t_Node* parent, string & str, int pos, t_Data & Data);
00105
00106 public:
00107 Phimbl();
00108 ~Phimbl();
00109
00110 vector <int> permutation;
00111 bool Learn(const string & filename);
00112 bool Write(const string & filename);
00113 bool Classify(const BOSS::t_SVector & str, string & res, const t_Data & Data) const;
00114 bool operator () (string & filename);
00115 bool LoadTree(const char* filename, t_Data & Data);
00116 void DeleteData(t_Data & Data);
00117 };
00118 }
00119
00120 #endif