Example #1
0
        private string filtering(string Astr)
        {
            string   filtered    = "";
            string   checkedword = "";
            Zemberek filter      = new Zemberek(new TurkiyeTurkcesi());

            Astr = Normalize(Astr);
            foreach (string word in Astr.Split(' '))
            {
                if (filter.kelimeDenetle(word))
                {
                    checkedword = word;
                }
                else
                {
                    String[] suggestions = filter.asciidenTurkceye(word);
                    if (suggestions.Length > 0)
                    {
                        checkedword = suggestions[0];
                    }
                    else
                    {
                        try
                        {
                            suggestions = filter.oner(word);
                        }
                        catch (System.NullReferenceException ex)
                        {
                            adderrorlog(ex.Message);
                        }

                        if (suggestions.Length > 0)
                        {
                            checkedword = suggestions[0];
                        }
                        else
                        {
                            fresidue += word + " ";
                        }
                    }
                }
                Kelime[] solutions = filter.kelimeCozumle(checkedword);
                foreach (Kelime solution in solutions)
                {
                    if (!filtered.Contains(solution.kok().icerik()))
                    {
                        filtered += solution.kok().icerik() + " ";
                    }
                }
            }
            return(filtered);
        }
Example #2
0
        static void DosyaOkuma()
        {
            int i;

            string[] path = { @"c:\metinler\Pozitif\", @"c:\metinler\Negatif\", @"c:\metinler\Etkisiz\", @"c:\metinler\Kontrol\" };
            for (i = 0; i < path.Length; i++)
            {
                Dictionary <string, Dictionary <string, int> > tempDictionary = new Dictionary <string, Dictionary <string, int> >();
                DirectoryInfo di    = new DirectoryInfo(path[i]);
                FileInfo[]    files = di.GetFiles();

                foreach (FileInfo fi in files)
                {
                    Deasciifier deasciifier = new Deasciifier();
                    var         zemberek    = new Zemberek(new TurkiyeTurkcesi());
                    Dictionary <string, int> geciciKelimeler = new Dictionary <string, int>();
                    FileStream   fs   = new FileStream(path[i] + fi, FileMode.Open, FileAccess.Read);
                    StreamReader sr   = new StreamReader(fs, Encoding.GetEncoding("iso-8859-9"), false);
                    string       yazi = sr.ReadLine();
                    yazi = yazi.ToLower();
                    while (yazi != null)
                    {
                        char[]   karakterler = { ' ', ',', '.', '?', '!', ';', ':', '\n', '\t', '\"', '\'', '(', ')', '#', '^', '@', '+', '-', '*', '/', '’', '_', '-' };
                        string[] gecici      = yazi.Split(karakterler);

                        foreach (string s in gecici)
                        {
                            #region Turkcelestirmeden

                            /*
                             * if (!geciciKelimeler.ContainsKey(s))
                             *  geciciKelimeler.Add(s, 1);
                             * else
                             *  geciciKelimeler[s]++;
                             */
                            #endregion
                            #region Turkcelestirerek
                            if (zemberek.kelimeDenetle(s))
                            {
                                if (!geciciKelimeler.ContainsKey(s))
                                {
                                    geciciKelimeler.Add(s, 1);
                                }
                                else
                                {
                                    geciciKelimeler[s]++;
                                }
                            }
                            else
                            {
                                string duzelt = deasciifier.DeAsciify(s);
                                if (zemberek.kelimeDenetle(duzelt))
                                {
                                    if (!geciciKelimeler.ContainsKey(duzelt))
                                    {
                                        geciciKelimeler.Add(duzelt, 1);
                                    }
                                    else
                                    {
                                        geciciKelimeler[duzelt]++;
                                    }
                                }
                                else
                                {
                                    var oneriler = zemberek.oner(s);
                                    if (oneriler.Any())
                                    {
                                        duzelt = zemberek.oner(s)[0];

                                        if (!geciciKelimeler.ContainsKey(duzelt))
                                        {
                                            geciciKelimeler.Add(duzelt, 1);
                                        }
                                        else
                                        {
                                            geciciKelimeler[duzelt]++;
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                        yazi = sr.ReadLine();
                    }
                    sr.Close();
                    fs.Close();
                    tempDictionary.Add(fi.ToString(), geciciKelimeler);
                }
                siniflar.Add(path[i].Split('\\')[2], tempDictionary);
            }
        }