Example #1
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;
        }
Example #2
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();
        }
Example #3
0
 /// <summary>
 /// Adds a parragraph.
 /// </summary>
 /// <param name="par">Parragraph.</param>
 public void AddPar(Par par)
 {
     pars.Add(par);
 }
Example #4
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;
            }
        }