public void Close()
        {
            if (isClosed)
            {
                return;
            }
            isClosed = true;
            KeyOff.Begin();

            Task.Factory.StartNew(() =>
            {
                KoreanCorrecter?.Dispose();
                KoreanCorrecter = null;
                EnglishCorrecter?.Dispose();
                EnglishCorrecter = null;
            });
        }
        public KeyControl()
        {
            InitializeComponent();

            SignCache(Grid_Big);

            Task.Factory.StartNew(() =>
            {
                KoreanCorrecter  = new WordCorrecter(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "CorrectionKorean.xml"));
                EnglishCorrecter = new WordCorrecter(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "CorrectionEnglish.xml"));
            });

            KeyOn             = (Storyboard)FindResource("KeyOn");
            KeyOff            = (Storyboard)FindResource("KeyOff");
            KeyOff.Completed += delegate
            {
                Closed?.Invoke(this, null);
            };
        }
Exemple #3
0
        public void PredictWord()
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                DefaultExt = ".xml",
                Filter     = "XML File (*.xml)|*.xml",
                Title      = "Select your sentence dataset"
            };

            ofd.ShowDialog();

            var corrector = new WordCorrecter(ofd.FileName);

            while (true)
            {
                Console.Write("Input> ");
                var read = Console.ReadLine().Trim();
                if (read.Length > 0)
                {
                    var result = corrector.Correcting(read);
                    if (result != null)
                    {
                        foreach (var item in result)
                        {
                            Console.WriteLine($"{item.Index.ToString().PadRight(5)} | {CenterString(item.Name, 30)} | {item.UsedCount}");
                        }

                        var  message = $"Select suggestion [0~{result.Length - 1}";
                        bool contain = corrector.Contains(read);
                        if (!contain)
                        {
                            message += " -1 to Add";
                        }
                        message += "]> ";
                        Console.Write(message);
                        try
                        {
                            var indRead = Console.ReadLine().Trim();
                            var ind     = Convert.ToInt32(indRead);

                            if (ind == -1)
                            {
                                corrector.Used(read);
                            }
                            else
                            {
                                Console.WriteLine("Corrected to " + result[ind].Name);
                                corrector.Used(result[ind].Name);
                            }
                        }
                        catch (FormatException) { }
                        catch (IndexOutOfRangeException) { }
                    }
                    else
                    {
                        Console.Write("Add new? [Y/n] ");
                        bool add     = true;
                        var  addRead = Console.ReadLine();

                        if (addRead != null && addRead != "")
                        {
                            add = false;
                            if (addRead.ToLower() == "y")
                            {
                                add = true;
                            }
                        }

                        if (add)
                        {
                            corrector.Used(read);
                        }
                    }
                }
            }
        }