Beispiel #1
0
        private void ConvertirAWiki()
        {
            //Obtener el input
            string[] topicFiles = null;
            try {
                topicFiles = CommonTasks.GetFiles(txtTopicFolder.Text, "*.txt");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }

            //Obtener el output
            string folder = txtWikiFolder.Text;

            if (folder == "")
            {
                MessageBox.Show("Selecciona la carpeta de salida");
                return;
            }

            //Leer ficheros LaTeX
            TopicIndex topicIndex = new TopicIndex(topicFiles);

            topicIndex.ProgressBar = progressBar1;
            topicIndex.LogTextBox  = txtResultLog;
            topicIndex.Read();

            //Convertir a ficheros wiki
            topicIndex.WriteAsWiki(folder);
        }
Beispiel #2
0
        private void ExtractID()
        {
            string extract = CommonTasks.Extract(content, idStart, commonEnd);

            if (extract != null)
            {
                id = extract;
            }
        }
Beispiel #3
0
        private void ExtractOldID()
        {
            string extract = CommonTasks.Extract(otherContent, oldidStart, oldidEnd);

            if (extract != null)
            {
                oldid = extract;
            }
        }
Beispiel #4
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            lblNumResult.Text = "0";

            //Obtener el input
            string[] latexFiles = null;
            try {
                latexFiles = CommonTasks.GetFiles(txtLatexFolder.Text, "*.tex");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }

            string searchText = txtSearchText.Text;

            if (searchText.Length == 0)
            {
                MessageBox.Show("Introduce texto de búsqueda.");
                return;
            }
            bool hayexclusion = (txtExcluded.Text != string.Empty);

            string[] exclusiones = new string[] { };
            if (hayexclusion)
            {
                exclusiones = txtExcluded.Text.Split(new char[] { ',' });
                for (int i = 0; i < exclusiones.Length; i++)
                {
                    exclusiones[i] = exclusiones[i].Trim();
                    if (exclusiones[i].IndexOf(searchText) == -1)
                    {
                        MessageBox.Show("La cadena de exclusión " + exclusiones[i] +
                                        " no contiene la cadena " + searchText + ".");
                        return;
                    }
                }
            }

            //Leer ficheros LaTeX
            Book           book     = new Book(latexFiles, progressBar1);
            List <Excerpt> excerpts = book.Search(searchText, exclusiones);

            //Presentar resultados
            StringBuilder sb  = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            for (int n = 0; n < excerpts.Count; n++)
            {
                sb.Append(excerpts[n].Reference + (n == excerpts.Count - 1 ? "" : ", "));
                sb2.Append(excerpts[n].Reference + "   " + excerpts[n].Extract + "\r\n");
            }

            this.lblNumResult.Text  = excerpts.Count.ToString();
            this.txtResultados.Text = CommonTasks.ReduceRefs(sb.ToString());
            this.txtLog.Text        = sb2.ToString();
        }
Beispiel #5
0
        /// <summary>
        /// Devuelve una lista de extractos con las referencias y los fragmentos en las que se 
        /// encuentra el texto de búsqueda pero sin que sea en la forma de ninguna de la exclusiones.
        /// </summary>
        /// <param name="searchText">Texto de búsqueda.</param>
        /// <param name="excluded">Un array de textos que contienen el texto de búsqueda.</param>
        /// <returns>Lista de extractos.</returns>
        public List<Excerpt> Search(string searchText, string[] excluded)
        {
            List<Excerpt> result = new List<Excerpt>();
            if (GetParLength() == 0) return result;
            for (int p = 0; p < GetParLength(); p++) {
                Par par = GetPar(p);
                string refer = par.GetID();
                string content = par.GetContentCleaned();

                //Buscar recursivamente
                List<Position> found = CommonTasks.IndexesOf(content, searchText);

                List<Position> found2 = new List<Position>();
                if (found.Count > 0) {
                    if (excluded.Length > 0) {
                        List<Position> foundExcluded = new List<Position>();
                        for (int i = 0; i < excluded.Length; i++) {
                            List<Position> fExcluded = CommonTasks.IndexesOf(content, excluded[i]);
                            for (int j = 0; j < fExcluded.Count; j++) {
                                Position pos = new Position();
                                pos.Start = fExcluded[j].Start;
                                pos.End = fExcluded[j].End;
                                foundExcluded.Add(pos);
                            }
                        }
                        for (int i = 0; i < found.Count; i++) {
                            bool toExclude = false;
                            for (int j = 0; j < foundExcluded.Count; j++) {
                                if (found[i].Start >= foundExcluded[j].Start &&
                                    found[i].End <= foundExcluded[j].End) {
                                    toExclude = true;
                                }
                            }
                            if (!toExclude) {
                                found2.Add(found[i]);
                            }
                        }
                    } else {
                        for (int i = 0; i < found.Count; i++) {
                            found2.Add(found[i]);
                        }
                    }

                    //Obtener la posición mínima y máxima
                    int min = content.Length - 1, max = 0;
                    for (int i = 0; i < found2.Count; i++) {
                        if (found2[i].Start < min) min = found2[i].Start;
                        if (found2[i].End > max) max = found2[i].End;
                    }
                    Excerpt excerpt = GetExcerpt(content, refer, min, max);
                    result.Add(excerpt);
                }
            }
            return result;
        }
Beispiel #6
0
        private void btnSelTopicFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description = "Selecciona carpeta con ficheros TXT";
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                txtTopicFolder.Text = fbd.SelectedPath;
                //Comprobamos si hay ficheros
                try {
                    CommonTasks.GetFiles(txtTopicFolder.Text, "*.txt");
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Convierte esta información a formato wiki.
        /// Si aparece el nombre del término en forma de abreviatura
        /// se reemplaza por el nombre del término.
        /// </summary>
        /// <param name="abb">Abreviatura del término.</param>
        /// <param name="name">Nombre del término.</param>
        /// <returns></returns>
        public string ToWiki(string abb, string name)
        {
            StringBuilder sb       = new StringBuilder();
            string        content2 = content.Replace(abb, name);

            sb.Append(content2);

            if (References.Count > 0)
            {
                for (int n = 0; n < References.Count; n++)
                {
                    sb.Append(CommonTasks.RefToWiki(References[n]));
                    if (n > 0 && n != References.Count - 1)
                    {
                        sb.Append(" ");
                    }
                }
            }
            return(sb.ToString());
        }
Beispiel #8
0
        private void BuscarCitasIncorrectas()
        {
            //Buscar todos los párrafos con footnotes donde las abreviaturas biblicas se repiten

            //Obtener el input
            string[] latexFiles = null;
            try {
                latexFiles = CommonTasks.GetFiles(txtLatexFolder.Text, "*.tex");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                return;
            }

            //Leer fichero LateX
            List <string> resultados = new List <string>();

            for (int f = 0; f < latexFiles.Length; f++)
            {
                resultados.Add(latexFiles[f]);
                Book book = new Book(latexFiles, this.progressBar1);
                if (book.GetParLength() > 0)
                {
                    for (int p = 0; p < book.GetParLength(); p++)
                    {
                        Par    par   = book.GetPar(p);
                        string refer = par.GetID();
                        bool   isOK  = true;
                        if (par.GetFootnotesLength() > 0)
                        {
                            for (int n = 0; n < par.GetFootnotesLength(); n++)
                            {
                                Footnote footnote = par.GetFootnote(n);
                                for (int m = 0; m < footnote.GetFootnotePartsLength(); m++)
                                {
                                    if (footnote.GetFootnotePart(m).HasReferenceRepeated())
                                    {
                                        isOK = false;
                                        break;
                                    }
                                }
                                if (!isOK)
                                {
                                    break;
                                }
                            }
                        }
                        if (!isOK)
                        {
                            resultados.Add(refer);
                        }
                    }
                }
            }

            //Presentar resultados
            StringBuilder sb = new StringBuilder();

            for (int n = 0; n < resultados.Count; n++)
            {
                sb.Append(resultados[n] + "\r\n");
            }
            this.txtResultLog.Text = sb.ToString();
        }
Beispiel #9
0
        private void Read()
        {
            pars.Clear();
            errors.Clear();
            if (filepaths == null) return;

            string line, linePrevious = "", extract;
            int count = 0, linePreviousPos = 0;
            Paper currentChapter = null;
            int currentChapterIndex = -1;
            Section currentSection = null;
            int currentSectionIndex = -1;
            string currentSectionID = "";
            Par currentPar = null;
            FileInfo fileinfo = null;

            progressBar.Value = 0;
            progressBar.Maximum = filepaths.Length;

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

                count = 0;
                linePreviousPos = 0;
                currentChapterIndex = -1;
                currentSectionIndex = -1;
                currentSectionID = "";

                while ((line = stream.ReadLine()) != null) {
                    if (line.StartsWith(paperStart)) {
                        //Si es un documento
                        extract = CommonTasks.Extract(line, paperStart, commonEnd);
                        if (extract == null) {
                            errors.Add(String.Format(errorString, fileinfo.Name, count,
                                "No se pudo extraer el inicio de documento"));
                        } else {
                            currentChapterIndex++;
                            currentChapter = new Paper(currentChapterIndex, extract);
                            papers.Add(currentChapter);
                            currentSection = null;
                            currentSectionIndex++;
                            currentSectionID = currentChapterIndex.ToString() + ":" +
                                currentSectionIndex.ToString();
                            currentSection = new Section(currentSectionIndex,
                                currentSectionID, "");
                            currentChapter.AddSection(currentSection);
                        }
                    } else if (line.StartsWith(sectionStart)) {
                        //Si es una seccion
                        extract = CommonTasks.Extract(line, sectionStart, commonEnd);
                        if (extract == null) {
                            errors.Add(String.Format(errorString, fileinfo.Name, count,
                                "No se pudo extraer el inicio de sección"));
                        } else {
                            currentSectionIndex++;
                            currentSectionID = currentChapterIndex.ToString() + ":" +
                                currentSectionIndex.ToString();
                            currentSection = new Section(currentSectionIndex,
                                currentSectionID, extract);
                            currentChapter.AddSection(currentSection);
                        }
                    } else if (line.StartsWith(oldidStart)) {
                        //Si es la línea con la antigua referencia
                        linePrevious = line;
                        linePreviousPos = count;
                    } else if (line.StartsWith(parStart)) {
                        //Si es un párrafo
                        if (linePreviousPos == count - 1) {
                            currentPar = new Par(line, linePrevious);
                            pars.Add(currentPar);
                            currentSection.AddPar(currentPar);
                        } else {
                            errors.Add(String.Format(errorString, fileinfo.Name, count,
                                "Línea previa incorrecta"));
                        }
                    } else if (line != "\\par" && line != "") {
                        errors.Add(String.Format(errorString, fileinfo.Name, count,
                            "Algo erróneo"));
                    }
                    count++;

                }
                stream.Close();
                progressBar.Value = f + 1;
            }
        }