private void Btn30Duc2005ExcelClick(object sender, EventArgs e) { var appSettings = ConfigurationManager.AppSettings; var d1 = new DUCDataSet("DUC2001", appSettings["DUC2001-dirRouge"], appSettings["DUC2001-dirMatrix"]); var d2 = new DUCDataSet("DUC2002", appSettings["DUC2002-dirRouge"], appSettings["DUC2002-dirMatrix"]); switch (lsbDataSet.SelectedItem.ToString()) { case "DUC2001": _chosenDUC = d1; break; case "DUC2002": _chosenDUC = d2; break; } _totalRepetitions = int.Parse((string)lsbTotalEjecuciones.SelectedItem); _experimentId = int.Parse((string)lsbIdExperimento.SelectedItem); _weight = (TFIDFWeight)Enum.Parse(typeof(TFIDFWeight), (string)lsbModelos.SelectedItem); _docRep = (DocumentRepresentation)Enum.Parse(typeof(DocumentRepresentation), (string)lsbDocRep.SelectedItem); _normalized = bool.Parse((string)lstNormalized.SelectedItem); _algorithm = (string)lsAlgorithm.SelectedItem; btn30DUC2001excel.Enabled = false; backgroundWorker1.RunWorkerAsync(); }
public void Ejecutar(DUCDataSet midataset, SummaryParameters myParameters, int idEjecution, int maxRepetitions, string theAlgorithm) { //Se establece el Identification de la ejecucion y se crea el directorio de salida var directorioDeSalida = midataset.RougeRootDirectory + @"experimentos\" + idEjecution.ToString("0000"); Directory.CreateDirectory(directorioDeSalida); //Se define el nombre del archivo en el que se colocaran los resultados por medio de los parámetros de ejecución. var theDate = DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Day.ToString("00") + "-" + DateTime.Now.Hour.ToString("00") + "-" + DateTime.Now.Minute.ToString("00"); var outputFileName = theDate + "-Exp-" + maxRepetitions + "-" + myParameters + ".xlsx"; outputFileName = outputFileName.Replace(",", "."); var directoryList = new List <string>(); directoryList.AddRange(Directory.GetDirectories(midataset.RougeRootDirectory + "documents")); //Tiene la ruta de cada documento directoryList.Sort(); var fileAccount = 0; var allFullNews = new List <string>(); foreach (var fullDirectory in directoryList) //Recorre cada directorio de documentos y hace ... { var lasNoticiasFull = Directory.GetFiles(fullDirectory); allFullNews.AddRange(lasNoticiasFull); } foreach (var fullNews in allFullNews) { fileAccount++; var theFullNews = fullNews; var x = new FileInfo(theFullNews); var thisNews = x.Name; //Deja solo el nombre de la noticia Debug.WriteLine(thisNews + " " + fileAccount); var nombreArchivosCache = midataset.MatricesRootDirectory + thisNews + "-" + myParameters.MyTDMParameters.MinimumFrequencyThresholdOfTermsForPhrase + "-" + myParameters.MyTDMParameters.MinimumThresholdForTheAcceptanceOfThePhrase + "-" + myParameters.MyTDMParameters.TheTFIDFWeight + "-" + myParameters.MyTDMParameters.TheDocumentRepresentation; nombreArchivosCache = nombreArchivosCache.Replace(",", "."); Parallel.For(0, maxRepetitions, repetition => //for (var repetition=0; repetition < maxRepetitions; repetition++) { //if (laNoticia != "LA042190-0060") // continue; // Create the experiment folder If it does not exists var directorioExperimento = directorioDeSalida + @"\" + repetition.ToString("000"); if (!Directory.Exists(directorioExperimento)) { Directory.CreateDirectory(directorioExperimento); } directorioExperimento += @"\systems"; if (!Directory.Exists(directorioExperimento)) { Directory.CreateDirectory(directorioExperimento); } SummarizerAlgorithm summarizer = null; switch (theAlgorithm) { case "ContinuousLexRank": summarizer = new ContinuousLexRank(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; case "DegreeCentralityLexRank": summarizer = new DegreeCentralityLexRank(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; case "LexRankWithThreshold": summarizer = new LexRankWithThreshold(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; case "FSP": ((FSPParameters)myParameters).RandomGenerator = new Random(repetition); summarizer = new FSP(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; case "GBHS": ((GBHSParameters)myParameters).RandomGenerator = new Random(repetition); summarizer = new GBHS(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; case "SFLA": ((SFLAParameters)myParameters).RandomGenerator = new Random(repetition); summarizer = new SFLA(); summarizer.Summarize(myParameters, theFullNews, nombreArchivosCache); break; } if (summarizer != null) { var contenidoResumenFinal = summarizer.TextSummary; File.WriteAllText(directorioExperimento + @"\" + thisNews, contenidoResumenFinal); } Debug.Write(repetition + ", "); //} // Fin de for }); // Fin de Parallel.For Debug.WriteLine(""); Debug.WriteLine("THREAD :" + Thread.CurrentThread.ManagedThreadId + " NEWS " + thisNews); } Debug.WriteLine("--- EVALUATING ---"); // Se realizan los Calculus de ROUGE para todos los experimentos de la segunda forma (segun normas exactas de DUC 2005) Parallel.For(0, maxRepetitions, experimento => { var directorioExperimento = directorioDeSalida + @"\" + experimento.ToString("000"); Rouge.EvaluateAnExperimentWithAllNewsPartA(midataset.RougeRootDirectory, directorioExperimento); }); var salidaExperimentos = "Exp.\tR1R\tR1P\tR1F\tR2R\tR2P\tR2F\tRLR\tRLP\tRLF\tRSU4R\tRSU4P\tRSU4F\r\n"; var resumenTodosExperimentos = new double[12]; var subtotalesPorGrupoEvaluador = new SubTotalsByDataSet(); for (var experimento = 0; experimento < maxRepetitions; experimento++) { var directorioExperimento = directorioDeSalida + @"\" + experimento.ToString("000"); var resultadoEstaNoticia = new double[12]; Rouge.EvaluateAnExperimentWithAllNewsPartB(midataset.RougeRootDirectory, directorioExperimento, ref resultadoEstaNoticia, ref subtotalesPorGrupoEvaluador); salidaExperimentos += experimento.ToString("00") + "\t"; for (var i = 0; i < 12; i++) { salidaExperimentos += resultadoEstaNoticia[i] + "\t"; resumenTodosExperimentos[i] += resultadoEstaNoticia[i]; } salidaExperimentos += "\r\n"; } salidaExperimentos += "TOTAL\t"; var salidaGlobal = outputFileName + "\t"; for (var i = 0; i < 12; i++) { resumenTodosExperimentos[i] = resumenTodosExperimentos[i] / maxRepetitions; salidaExperimentos += resumenTodosExperimentos[i] + "\t"; salidaGlobal += resumenTodosExperimentos[i] + "\t"; } salidaExperimentos += "\r\n"; salidaGlobal += "\r\n"; File.AppendAllText(@"D:\SalidaGlobal.txt", salidaGlobal); //Thread.Sleep(2000); //GrabarEnExcelExperimentosPorNoticia(midataset.DirectorioRaizRouge, nombreArchivoDeSalida, "TodoExp", salidaExperimentos, true); //foreach (SubTotalsByDataSet.GrupoEvaluadorRow fila in subtotalesPorGrupoEvaluador.GrupoEvaluador.Rows) //{ // fila.Recall = decimal.Divide(fila.Recall, fila.Contador); // fila.Precision = decimal.Divide(fila.Precision, fila.Contador); // fila.Fmeasure = decimal.Divide(fila.Fmeasure, fila.Contador); //} //var listaRouges = new[] { "ROUGE-1", "ROUGE-2", "ROUGE-SU4" }; //foreach (var elRouge in listaRouges) //{ // var salida = "Grupo\tRecall\tPrecision\tFmeasure\r\n"; // foreach (var dataRow in subtotalesPorGrupoEvaluador.GrupoEvaluador.Select("Rouge = '" + elRouge + "'")) // { // var fila = (SubTotalsByDataSet.GrupoEvaluadorRow)dataRow; // salida += fila.Name + "\t" + fila.Recall + "\t" + fila.Precision + "\t" + fila.Fmeasure + "\r\n"; // } // Thread.Sleep(2000); // GrabarEnExcelExperimentosPorNoticia(midataset.DirectorioRaizRouge, nombreArchivoDeSalida, elRouge, salida, true); //} }