00001 00040 #ifdef HAVE_CONFIG_H 00041 #include <config.h> 00042 #endif 00043 00044 #include <iostream> 00045 #include <fstream> 00046 #include "Apriori.hpp" 00047 using namespace std; 00048 00049 00051 00052 void usage() 00053 { 00054 cerr << "\nUsage: apriori basketfile outcomefile min_supp [min_conf]\n"; 00055 cerr << "\n basketfile\t file, that contains the baskets of itemcodes"; 00056 cerr << "\n outcomefile\t file to write the outcome"; 00057 cerr << "\n min_supp\t support threshold"; 00058 cerr << "\n min_conf\t confidence threshold"; 00059 00060 cerr << "\n\nFile formats:"; 00061 cerr << "\n\nThe basket file is a plan text file. Each row represents a basket. "; 00062 cerr << "A basket is a set of items seperated by a nonnumeric character (for example white space, comma, colon, etc.). "; 00063 cerr << "An item is represented by its code which is an integer number greater than or equal to 0."; 00064 cerr << "\nFor more options please check the configuration file: .apriori_config."; 00065 cerr << "\n\nHave a succesful mining ;-)"; 00066 cerr << "\n\n\n\t\t\t\t\tFerenc Bodon\n\n"; 00067 } 00068 void process_config_file(bool& quiet, bool& store_input, unsigned long& size_threshold) 00069 { 00070 ifstream config_file(".apriori_config"); 00071 quiet=false; 00072 store_input=true; 00073 00074 if( !config_file ) 00075 { 00076 cerr << "Warning: There is no configuration file (.apriori_config)!\n"; 00077 cerr << "Default values are used!"<<flush; 00078 } 00079 else 00080 { 00081 char temp_string[256]; 00082 config_file.getline(temp_string, 256); 00083 config_file.getline(temp_string, 256); 00084 config_file>>quiet; 00085 if( config_file.fail() ) 00086 { 00087 cerr<<"\nWarning: Failed to read in quiet value from the configuration file!"; 00088 cerr<<"\nDefault value (false) is used."; 00089 } 00090 config_file.getline(temp_string, 256); 00091 config_file>>store_input; 00092 if( config_file.fail() ) 00093 { 00094 cerr<<"\nWarning: Failed to read in store_input value from the configuration file!"; 00095 cerr<<"\nDefault value (true) is used."; 00096 } 00097 config_file.getline(temp_string, 256); 00098 config_file>>size_threshold; 00099 if( config_file.fail() ) 00100 { 00101 cerr<<"\nWarning: Failed to read in size_threshold value from the configuration file!"; 00102 cerr<<"\nDefault value (0) is used."; 00103 } 00104 config_file.close(); 00105 } 00106 } 00107 00109 int process_arguments( int argc, char *argv[], ifstream& basket_file, 00110 double& min_supp, double& min_conf ) 00111 { 00112 if ( argc < 4 ) 00113 { 00114 usage(); 00115 cerr<<"\nError! There are 3 mandatory arguments!"<<flush; 00116 return 1; 00117 } 00118 basket_file.open(argv[1]); 00119 if( !basket_file ) 00120 { 00121 usage(); 00122 cerr << "\nError! The basket file can not be read!"<< flush; 00123 return 1; 00124 } 00125 00126 min_supp = atof(argv[3]); 00127 if ( min_supp <= 0 || min_supp > 1 ) 00128 { 00129 usage(); 00130 cerr<<"\nError!\n min_supp should be in the interval (0,1].\n"<<flush; 00131 return 1; 00132 } 00133 00134 if ( argc == 5 ) 00135 { 00136 min_conf = atof(argv[4]); 00137 if ( min_conf <= 0 || min_conf > 1 ) 00138 { 00139 usage(); 00140 cerr << "\nError!\n min_conf should be in the interval (0,1].\n"<<flush; 00141 return 1; 00142 } 00143 } 00144 else min_conf = 0; 00145 return 0; 00146 } 00147 00148 int main( int argc, char *argv[] ) 00149 { 00150 double min_supp, 00151 min_conf; 00152 bool store_input = true, 00153 quiet = false; 00154 unsigned long size_threshold; 00155 ifstream basket_file; 00156 00157 process_config_file(quiet, store_input, size_threshold); 00158 if( process_arguments( argc, argv, basket_file, min_supp, min_conf ) ) return 1; 00159 00160 if( !quiet ) 00161 { 00162 cout << "\n********************************************************************"; 00163 cout << "\n*** ***"; 00164 cout << "\n*** Trie based APRIORI algorithm ***"; 00165 cout << "\n*** version: 2.3.2 ***"; 00166 cout << "\n*** ***"; 00167 cout << "\n*** Implemented by: Ferenc Bodon (bodon@cs.bme.hu) ***"; 00168 cout << "\n*** ***"; 00169 cout << "\n********************************************************************\n\n"; 00170 } 00171 00172 Apriori apriori( basket_file, argv[2], store_input ); 00173 apriori.APRIORI_alg( min_supp, min_conf, quiet, size_threshold ); 00174 basket_file.close(); 00175 return 0; 00176 } 00177