Esempio n. 1
0
        public static void Main(string[] args)
        {
            var engine = new PredictionEngine<Statistics>();
            engine.LoadDB(EngineDb);

            var buffer = "";
            var character = '\0';

            var predictions = new Dictionary<char, float>();

            do
            {
                var key = Console.ReadKey();
                character = key.KeyChar;

                if (character == ShellExit)
                {
                    break;
                }

                if (engine.ValidCharacter(character) == false)
                {
                    continue;
                }

                engine.CharacterTyped(character);

                buffer += character;

                Console.Clear();
                Console.WriteLine(buffer);

                predictions = engine.GetPredictions();

                if (engine.IsUnknownWord())
                {
                    Console.WriteLine("Unknown word!");

                    continue;
                }

                foreach (var prediction in predictions)
                {
                    if (prediction.Value != 0)
                    {
                        Console.WriteLine("P(" + prediction.Key + ") = " + prediction.Value);
                    }
                }

            } while (true);

            engine.SaveDB(EngineDb);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var writeRight = new WriteRight();
            writeRight.LoadDB(WriteRightDb);

            var buffer = "";
            var character = '\0';
            var foregroundColor = Console.ForegroundColor;

            var topKPredictions = new Dictionary<char, float>();

            do
            {
                var key = Console.ReadKey();
                character = key.KeyChar;

                if (character == ShellExit)
                {
                    break;
                }

                if (writeRight.IsValidCharacter(character) == false)
                {
                    continue;
                }

                writeRight.CharacterTyped(character);

                buffer += character;

                Console.Clear();
                Console.WriteLine(buffer);

                topKPredictions = writeRight.GetTopKPredictions();

                if (writeRight.IsUnknownWord())
                {
                    Console.WriteLine("Unknown word!");

                    continue;
                }

                Console.ForegroundColor = ConsoleColor.Green;

                foreach (var prediction in topKPredictions)
                {
                    Console.WriteLine("P(" + prediction.Key + ") = " + prediction.Value);
                }

                Console.WriteLine("\n");
                Console.ForegroundColor = ConsoleColor.Red;

                var predictions = writeRight.GetPredictions();

                foreach (var prediction in predictions)
                {
                    if (topKPredictions.ContainsKey(prediction.Key) == false)
                    {
                        Console.WriteLine("P(" + prediction.Key + ") = " + prediction.Value);
                    }
                }

                Console.ForegroundColor = foregroundColor;

            } while (true);

            writeRight.SaveDB(WriteRightDb);
        }
Esempio n. 3
-1
        public Trie()
        {
            this.subTries = new Dictionary<char, Trie>();

            foreach (var letter in Trie.LatinLetters)
            {
                this.subTries.Add(letter, null);
            }
        }