Example #1
0
        public static void SolveFromFile(string inputFile, string outputFile, string modelName)
        {
            var model  = ModelLoader.LoadByName(modelName);
            var method = new NGramInputMethod(model);

            using (var outputWriter = File.CreateText(outputFile))
            {
                var lineCount = 0;
                foreach (string input in File.ReadLines(inputFile))
                {
                    method.Clear();
                    var pinyins = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    SolveAndWritePinyin(pinyins, method, outputWriter);
                    ++lineCount;
                    if (lineCount % 10 == 0)
                    {
                        Console.Error.WriteLine($"Converted {lineCount} lines");
                    }
                }
                Console.Error.WriteLine($"Done converting pinyin, {lineCount} lines in total.");
            }
        }
Example #2
0
        public static void InteractiveSolve(string modelName)
        {
            NGramBase model  = ModelLoader.LoadByName(modelName);
            var       method = new NGramInputMethod(model)
            {
                PrintDistributeSize = PersistentConfiguration.CandidatesEachStep,
            };

            Console.WriteLine($"Using {method.Name}");

            while (true)
            {
                Console.Write("Pinyin > ");
                var raw = Console.ReadLine();
                if (raw == null)
                {
                    break;
                }
                var input = raw.Trim();
                method.Clear();
                var pinyins = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                SolveAndWritePinyin(pinyins, method, Console.Out);
            }
        }