Пример #1
0
        /// <summary>
        /// méthode permettant de lister les Occurences et de leurs incrémentations
        /// </summary>
        /// <param name="lstSub">liste des mots séparés</param>
        /// <param name="fi">fichier dans lequel l'occurence à été trouvée</param>
        /// <param name="lstOccurence">liste des occurences</param>
        /// <returns>la liste des occurences remplie</returns>
        public void SetOccurence(List <string> lstSub, FileInfo fi, List <Ocurrence> lstOccurence, string WebUrl)
        {
            List <string> lstWord2 = new List <string>();

            foreach (var substring in lstSub)
            {
                if (!lstWord2.Contains(substring))
                {
                    Ocurrence ocucu = new Ocurrence(fi, substring, WebUrl);
                    if (!lstOccurence.Contains(ocucu))
                    {
                        lstOccurence.Add(ocucu);
                        lstWord2.Add(substring);
                    }
                }
                else
                {
                    foreach (Ocurrence occurence in lstOccurence)
                    {
                        if (occurence.Word == substring)
                        {
                            occurence.IncreamentOccurence();
                        }
                    }
                }
            }
            foreach (Ocurrence ocu in lstOccurence)
            {
                ocu.SendToDataBase();
            }
        }
Пример #2
0
        public WordOnTxt(DirectoryInfo di)
        {
            string _encoding = "1252";


            foreach (var fi in di.GetFiles("*.txt", SearchOption.AllDirectories))
            {
                K_Google.AddFile(fi);



                List <string> lstWord = new List <string>();

                using (FileStream fs = File.OpenRead(fi.FullName))
                {
                    Ude.CharsetDetector cdet = new Ude.CharsetDetector();
                    cdet.Feed(fs);
                    cdet.DataEnd();
                    if (cdet.Charset != null)
                    {
                        _encoding = cdet.Charset;
                        //Console.WriteLine(_encoding);
                    }
                    else
                    {
                        Console.WriteLine("Detection failed.");
                    }
                }

                string path = fi.DirectoryName + "\\" + fi.Name;
                Console.WriteLine(path);
                StreamReader Reader = new StreamReader(path, Encoding.GetEncoding(_encoding));
                string       polpi  = Reader.ReadToEnd();
                Reader.Close();
                polpi = polpi.ToLower();



                Char[] delimiter = new char[] { '[', ']', '#', '^', '¦', '|', '£', '<', '>', '_', '$', '\n', '\r', '.', ' ', ',', '\'', '!', '?', '(', ')', '%', '&', '"', '=', '+', '{', '}', '*', ';', ':', '\\', '-', '/' };

                String[] substrings = polpi.Split(delimiter);



                //List<string> lstSub = new List<string>(substrings);

                List <string> lstSub = new List <string>();

                foreach (string word in substrings)
                {
                    if (word.Count() > 0)
                    {
                        lstSub.Add(word);
                    }
                }
                lstSub.Sort();
                foreach (var substring in lstSub)
                {
                    if (!lstWord.Contains(substring))
                    {
                        lstWord.Add(substring);
                    }
                }
                lstSub.Sort();
                foreach (var word in lstWord)
                {
                    AddWord(word);
                }
                List <string> lstWord2 = new List <string>();
                foreach (var substring in lstSub)
                {
                    if (!lstWord2.Contains(substring))
                    {
                        Ocurrence ocucu = new Ocurrence(fi, substring);
                        if (!lstOccurence.Contains(ocucu))
                        {
                            lstOccurence.Add(ocucu);
                            lstWord2.Add(substring);
                        }
                    }
                    else
                    {
                        foreach (Ocurrence occurence in lstOccurence)
                        {
                            if (occurence.Word == substring)
                            {
                                occurence.IncreamentOccurence();
                            }
                        }
                    }
                }
            }
            foreach (Ocurrence ocu in lstOccurence)
            {
                ocu.SendToDataBase();
            }
        }