Example #1
0
        public void Read()
        {
            terms.Clear();
            errors.Clear();
            if (filepaths == null)
            {
                return;
            }

            string        line, linePrevious = "", name, content, error;
            List <string> seeAlso, refs, refs2;
            int           count = 0, level;
            FileInfo      fileinfo             = null;
            Term          currentTerm          = null;
            TermInfo      currentTermInfo      = null;
            int           currentTermInfoIndex = -1;

            if (progressBar != null)
            {
                progressBar.Value   = 0;
                progressBar.Maximum = filepaths.Length;
            }
            if (logTextBox != null)
            {
                logTextBox.Text = "";
            }

            for (int f = 0; f < filepaths.Length; f++)
            {
                fileinfo = new FileInfo(filepaths[f]);
                StreamReader stream = new StreamReader(filepaths[f]);

                count = 0;
                currentTermInfoIndex = -1;

                while ((line = stream.ReadLine()) != null)
                {
                    if (!line.StartsWith(comment))
                    {
                        if (line != "" && linePrevious == "")
                        {
                            name    = ExtractName(line);
                            seeAlso = ExtractSeeAlso(line);
                            refs    = ExtractReferences(line);
                            if (name != "" && seeAlso != null && refs != null)
                            {
                                currentTerm = new Term(name, seeAlso, refs);
                                terms.Add(currentTerm);
                            }
                            else
                            {
                                if (name == "")
                                {
                                    error = String.Format(errorString, fileinfo.Name,
                                                          count, "No se pudo extraer el nombre del término");
                                    errors.Add(error);
                                    if (logTextBox != null)
                                    {
                                        logTextBox.AppendText(error + "\r\n");
                                    }
                                }
                                if (seeAlso == null)
                                {
                                    error = String.Format(errorString, fileinfo.Name, count,
                                                          "No se pudo extraer los 'Vea también' del término");
                                    errors.Add(error);
                                    if (logTextBox != null)
                                    {
                                        logTextBox.AppendText(error + "\r\n");
                                    }
                                }
                                if (refs == null)
                                {
                                    error = String.Format(errorString, fileinfo.Name, count,
                                                          "No se pudo extraer las referencias del término");
                                    errors.Add(error);
                                    if (logTextBox != null)
                                    {
                                        logTextBox.AppendText(error + "\r\n");
                                    }
                                }
                            }
                        }
                        else if (line != "" && currentTerm != null)
                        {
                            content = ExtractContent(line);
                            refs2   = ExtractReferences(line);
                            level   = ExtractLevel(line);
                            if (content != "" && refs2 != null)
                            {
                                currentTermInfo      = new TermInfo(content, level, refs2);
                                currentTermInfoIndex = currentTerm.AddInfo(currentTermInfo);
                            }
                            else
                            {
                                if (content == "")
                                {
                                    error = String.Format(errorString, fileinfo.Name, count,
                                                          "No se pudo extraer el contenido de la información");
                                    errors.Add(error);
                                    if (logTextBox != null)
                                    {
                                        logTextBox.AppendText(error + "\r\n");
                                    }
                                }
                            }
                        }
                        else if (line == "" && currentTerm != null)
                        {
                            currentTerm = null;
                        }
                        linePrevious = line;
                    }
                    count++;
                }
                stream.Close();
                if (progressBar != null)
                {
                    progressBar.Value = f + 1;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Añade una nueva información al término.
 /// </summary>
 /// <param name="info">Información a añadir.</param>
 /// <returns>Índice que ocupa la nueva información en la lista.</returns>
 public int AddInfo(TermInfo info)
 {
     infos.Add(info);
     return(infos.Count - 1);
 }
Example #3
0
        /// <summary>
        /// Procesa todos los términos y escribe un fichero estilo Wiki
        /// por cada uno de ellos.
        /// </summary>
        /// <param name="folder">Carpeta de salida.</param>
        public void WriteAsWiki(string folder)
        {
            Term            term = null;
            TermInfo        ti = null;
            int             numSubinfo = 0;
            List <TermInfo> infos = null;
            string          filename = null, filepath = null, abb = null;

            if (progressBar != null)
            {
                progressBar.Value   = 0;
                progressBar.Maximum = GetTermLength();
            }

            //Bucle por todos los términos
            for (int n = 0; n < GetTermLength(); n++)
            {
                term     = terms[n];
                infos    = term.Infos;
                abb      = term.GetAbbreviation();
                filename = term.Name.Replace(" ", "_") + ".wiki";
                filepath = Path.Combine(folder, filename);
                StreamWriter stream = new StreamWriter(filepath);

                //Primero escribimos el nivel cero y los que tengan pocas
                //entradas en el nivel 1
                for (int t = 0; t < infos.Count; t++)
                {
                    ti = infos[t];
                    //Falta traduccir de inglés a español
                    //TODO Traducir a español

                    //Falta reemplazar términos cuando aparecen dentro de una info
                    //por un enlace interno a la wiki
                    //TODO Reemplazar ocurrencias de términos por enlaces

                    numSubinfo = term.GetSubinfoLength(t);
                    if (ti.Level == 0 && numSubinfo < 4)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(ti.ToWiki(abb, term.Name));
                        if (numSubinfo > 0)
                        {
                            sb.Append(": ");
                            for (int s = 1; s <= numSubinfo; s++)
                            {
                                if (s != 1)
                                {
                                    sb.Append(" ");
                                }
                                sb.Append(infos[t + s].ToWiki(abb, term.Name) + ".");
                            }
                            t += numSubinfo;
                        }
                        else
                        {
                            sb.Append(".");
                        }
                        stream.WriteLine(sb.ToString());
                    }
                }

                //Segundo escribimos el nivel 1 con muchas entradas,
                //cada uno como una sección
                //TODO Añadir secciones

                //Finalizamos añadiendo la sección de referencias
                stream.WriteLine("");
                stream.WriteLine("== Referencias ==");
                stream.WriteLine("<references/>");

                //Añadimos la sección de Enlaces (See also)
                if (term.SeeAlso.Count > 0)
                {
                    stream.WriteLine("");
                    stream.WriteLine("== Enlaces ==");
                    foreach (string sa in term.SeeAlso)
                    {
                        stream.WriteLine("[[" + sa + "]]");
                    }
                }

                stream.Close();
                if (logTextBox != null)
                {
                    logTextBox.AppendText(term.Name +
                                          " convertido a " + filename + "\r\n");
                }
                if (progressBar != null)
                {
                    progressBar.Value = n + 1;
                }
            }
        }