Esempio n. 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;
        }
Esempio n. 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();
        }