operaindice.cpp

Ir a la documentación de este archivo.
00001 // vim: set expandtab tabstop=8 shiftwidth=8 foldmethod=marker:
00037 #include <iostream>
00038 #include <iomanip>
00039 #include <list>
00040 #include <vector>
00041 #include <fstream>
00042 #include <istream>
00043 
00044 using namespace std;
00045 
00046 #include "RamDisco.hpp"
00047 #include "Operaciones.hpp"
00048 
00049 bool metainformacion=true;
00050 
00051 int main(int argc, char *argv[])
00052 {
00053         if (argc < 2) {
00054                 cerr<<"Se esperaba operación y parámetros" << endl;
00055                 cerr<<"Las operaciones posibles y sus parámetros son:" << endl;
00056                 cerr << endl;
00057                 cerr << "eliminadoc is i n" << endl;
00058                 cerr << "       Elimina el n-esimo documento del índice i (n>=1) produciendo is" << endl;
00059 
00060                 cerr << "grafo i" << endl;
00061                 cerr << "       Generar árbol en formato dotty" << endl;
00062                 cerr << "lista i" << endl;
00063                 cerr << "       Lista palabras de un índice con frecuencia" << endl;
00064                 cerr << "mezclaram is i1 i2 ... i_n" << endl;
00065                 cerr << "       Mezcla en ram índices i1 e i2 produciendo is" << endl;
00066                 cerr << "mezcladisco is i1 i2 [n]" << endl;
00067                 cerr << "       Mezcla en disco. Análogo a mezclaram, aunque el parametro opcional n " << endl;
00068                 cerr << "       índica la posición en medio de documentos referenciados por i1, " << endl;
00069                 cerr << "       en la que se insertarán documentos referenciados " << endl;
00070                 cerr << "       por i2. Si no se especifica se insertan después de los de i1. " << endl;
00071                 cerr << "       Puede ser entre 1 y el total de documentos de i1 más 1"  << endl;
00072                 cerr << "agregadoc is i1 pref d [n]" << endl;
00073                 cerr << "       Usando como prefijo para URL pref, indexa el documento d en RAM y " << endl;
00074                 cerr << "       lo mezcla con el índice i1, dejando el índice resultante en is." << endl;
00075                 cerr << "       El parámetro n es como en mezcladisco " << endl;
00076 
00077                 exit(1);
00078         }
00079         char noma[1000];
00080         char nrel[MAXLURL];
00081 
00082 
00083         if (((strcmp(argv[1], "lista") == 0 ||
00084                         strcmp(argv[1], "grafo") == 0) &&
00085                         argc != 3) ||
00086                         (strcmp(argv[1], "eliminadoc") == 0 && argc != 5) ||
00087                         (strcmp(argv[1], "mezclaram") == 0 && argc < 5) ||
00088                         (strcmp(argv[1], "agregadoc") == 0 &&
00089                          argc != 6 && argc != 7) ||
00090                         (strcmp(argv[1], "mezcladisco") == 0 &&
00091                          (argc < 5 || argc>6))) {
00092                 cerr << "Cantidad de parámetros incorrecta" << endl;
00093                 exit(1);
00094         }
00095         if (strcmp(argv[1], "eliminadoc") == 0) {
00096                 snprintf(noma, 1000, "%s", argv[2]);
00097                 long nd = atoi(argv[4]);
00098                 if (nd <= 0) {
00099                         cerr << "n debe ser mayor o igual a 1" << endl;
00100                         exit(1);
00101                 }
00102                 try {
00103                         eliminaDoc(noma, argv[3], (long)nd);
00104                 } catch (std::string s) {
00105                         cerr << s << endl;
00106                         exit(1);
00107                 }
00108         } else if (strcmp(argv[1], "grafo") == 0) {
00109                 snprintf(noma, 1000, "%s", argv[2]);
00110                 verificaNombre(argv[2], nrel);
00111                 vector<Doc> docs1;
00112                 NodoTrieS *r = leePlano(noma, nrel, docs1);
00113                 r->aDotty(cout);
00114         } else if (strcmp(argv[1], "lista") == 0) {
00115                 snprintf(noma, 1000, "%s", argv[2]);
00116                 verificaNombre(argv[2], nrel);
00117                 listaPalabras(noma, nrel);
00118         } else if (strcmp(argv[1], "mezclaram") == 0) {
00119 
00120                 NodoTrieS *t = NULL;
00121 
00122                 snprintf(noma, 1000, "%s", argv[2]);
00123                 //cerr<<"noma="<<noma<<endl;
00124 
00125                 vector<Doc> docs2;
00126                 for (int i = 3; i < argc; i++) {
00127                         vector<Doc> docs1; // Documentos en i-esimo índ.
00128                         verificaNombre(argv[i], nrel);
00129                         NodoTrieS *r = leePlano(argv[i], nrel, docs1);
00130                         // Renumera los del r
00131                         // Mezcla docs1 en docs2
00132                         vector<long> renum =
00133                                 mezclaDocs(docs1, docs2);
00134                         r->renumeraDocs(renum);
00135                         NodoTrieS *t2=mezcla(t, r);
00136                         t = t2;
00137                         r = NULL;
00138                 }
00139                 //cerr<<"idocs.size="<<idocs.size()<<endl;
00140                 verificaNombre(noma, nrel);
00141                 escribePlano(*t, docs2, noma, nrel);
00142         } else if (strcmp(argv[1], "mezcladisco") == 0) {
00143 
00144                 /* Mezcla 2 tries en disco */
00145                 long nd = 0;
00146                 if (argc == 6) {
00147                         nd = atoi(argv[5]);
00148                         if (nd < 1) {
00149                                 cerr << "n debe ser mayor o igual a 1" << endl;
00150                                 exit(1);
00151                         }
00152                 }
00153                 mezclaDosDisco(argv[2], argv[3], argv[4], nd);
00154 
00155         } else if (strcmp(argv[1], "agregadoc") == 0) {
00156                 long nd = 0;
00157                 if (argc == 7) {
00158                         nd = atoi(argv[6]);
00159                         if (nd < 1) {
00160                                 cerr << "n debe ser mayor o igual a 1" << endl;
00161                                 exit(1);
00162                         }
00163                 }
00164 
00165                 try {
00166                         agregaDoc(argv[2], argv[3], argv[5],
00167                                   metainformacion, argv[4], nd);
00168                 } catch (std::string s) {
00169                         cerr << s << endl;
00170                         exit(1);
00171                 }
00172         } else {
00173                 cerr << "operación desconocida " << argv[1] << endl;
00174                 return 1;
00175         }
00176         return 0;
00177 }
00178 
00179 
00180 

Generado el Wed Jan 6 06:58:22 2010 para Mt77 por  doxygen 1.5.4