indexador.cpp

Ir a la documentación de este archivo.
00001 // vim: set expandtab tabstop=8 shiftwidth=8 foldmethod=marker:
00013 #include <iostream>
00014 #include <iomanip>
00015 #include <list>
00016 #include <vector>
00017 #include <fstream>
00018 #include <istream>
00019 #include <unistd.h>
00020 
00021 
00022 using namespace std;
00023 
00024 #include "Operaciones.hpp"
00025 
00026 
00027 
00028 
00029 unsigned long MAXG = 50000000;
00030 
00031 bool metainformacion=true;
00032 
00033 int main(int argc, char *argv[])
00034 {
00035         if (argc < 5) {
00036                 cerr<<"Se esperaban al menos 4 argumentos, el primero indice por crear, indice temporal, dominio por agregar como prefijo y los siguientes textos por leer"<<endl;
00037                 exit(1);
00038         }
00039         vector<Doc> idocs;
00040         char noma[1024], nomt[1024], nomrel[1024], pref[1024];
00041 
00042         verificaNombre(argv[1], nomrel);
00043         snprintf(noma, 1000, "%s", argv[1]);
00044         snprintf(nomt, 1000, "%s", argv[2]);
00045         snprintf(pref, 1024, "%s", argv[3]);
00046         //cerr<<"noma="<<noma<<endl;
00047 
00048         char *cm = getenv("MT77MAXG");
00049         if (cm != NULL) {
00050                 MAXG = atol(cm);
00051         }
00052         if (MAXG <= 10) {
00053                 cerr<<"El valor de MT77MAXG no es aceptable" << endl;
00054                 exit(1);
00055         }
00056         if (strcmp(nomt, noma) == 0) {
00057                 cerr<<"Indice por crear y temporal deben ser diferentes" << endl;
00058                 exit(1);
00059         }
00060         vector<unsigned int> grupo; // Índice donde termina cada grupo en idocs
00061         unsigned long tg = 0 ; // Tamaño del grupo actual
00062         for (int i = 4; i < argc; i++) {
00063                 FILE *f = NULL;
00064                 if ((f = fopen (argv[i],  "rb")) == NULL) {
00065                         cerr << "No existe el archivo '" << argv[i] <<
00066                         "'" << endl;
00067                 } else  {
00068                         fseek(f, 0L, SEEK_END);
00069                         unsigned long sz = ftell(f);
00070                         fclose(f);
00071                         //clog << "i=" << i << ", argv[i]=" << argv[i] << ", sz=" << sz << endl;
00072                         if (sz > MAXG) {
00073                                 cerr << "El archivo " << argv[i] << " es demasiado grande (" << sz << " bytes), no se indexará." << endl;
00074                         } else {
00075                                 idocs.push_back(Doc(argv[i], "", "1960-01-01"));
00076                                 if (tg + sz > MAXG) {
00077                                         grupo.push_back(idocs.size()-2);
00078                                         tg = sz;
00079                                 } else {
00080                                         tg += sz;
00081                                 }
00082                         }
00083                         //clog << "tg=" << tg << endl;
00084                 }
00085         }
00086         if (idocs.size() > 0) {
00087                 grupo.push_back(idocs.size() - 1);
00088         }
00089 
00090         char *nomi[2];  // Nombres de indice y de temporal en el orden correcto para que en la última iteración el índice generado quede en el del indice
00091         if (grupo.size() % 2 == 1) {
00092                 nomi[0] = noma;
00093                 nomi[1] = nomt;
00094         } else {
00095                 nomi[0] = nomt;
00096                 nomi[1] = noma;
00097         }
00098 
00099         string tipo = "otro";
00100         string formato;
00101         NodoTrieS *t;
00102         unsigned int nd = 0; // indice del documento procesado
00103         try {
00104                 for (unsigned int g = 0; g < grupo.size(); g++) {
00105                         //clog << "OJO indexando grupo g=" << g << " que termina en " << grupo[g] << endl;
00106                         t = new NodoTrieS();
00107                         while (nd <= grupo[g]) {
00108                                 //clog << "OJO indexando nd=" << nd << endl;
00109                                 indexa(idocs[nd], nd + 1, metainformacion, pref,
00110                                        *t, tipo, formato);
00111                                 nd++;
00112                         }
00113                         //cerr<<"idocs.size="<<idocs.size()<<endl;
00114 
00115                         if (g == 0) {
00116                                 //clog << "OJO escribiendo primer grupo en " << nomi[g % 2] << endl;
00117                                 fstream os(nomi[g % 2], ios_base::out);
00118                                 os << MARCAIND << endl;
00119                                 escribePlanoStream(t, os);
00120                                 os.close();
00121                         } else {
00122                                 //clog << "OJO escribiendo grupo g=" << g << " en " << nomi[g % 2] << endl;
00123                                 fstream os(nomi[g % 2], ios_base::out);
00124                                 fstream is1(nomi[(g + 1) % 2], ios_base::in);
00125 
00126                                 verificaIndice(is1);
00127                                 is1.clear();
00128 
00129                                 os << MARCAIND << endl;
00130                                 mezclaDiscoRam(is1, t, 0, os, true, true,
00131                                                NULL, NULL);
00132                                 is1.close();
00133                                 os.close();
00134                         }
00135                         delete t;
00136                 }
00137                 if (grupo.size() > 0) {
00138                         //clog << "OJO escribiendo relacion de documentos" << endl;
00139                         escribeRelacion(nomrel, idocs, NULL);
00140                 }
00141         } catch (string m) {
00142                 cerr << noma << ":" << m;
00143                 exit(1);
00144         }
00145 
00146         return 0;
00147 }
00148 

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