public static void QueryModel() { NGramBase ng1 = ModelLoader.Load <NGram1>(); NGramBase ng2 = ModelLoader.Load <NGram2>(); NGramBase ng3 = ModelLoader.Load <NGram3>(); while (true) { Console.Write("Data > "); var input = Console.ReadLine().Trim(); // [char]+ [pinyin] string chars = input.Split()[0]; string pinyin = input.Split().ElementAtOrDefault(1); var condition = new PinyinToSolve(chars, pinyin); try { Console.WriteLine("1-gram"); ng1.GetDistribution(condition).Take(5).Print(); Console.WriteLine("2-gram"); ng2.GetDistribution(condition).Take(5).Print(); Console.WriteLine("3-gram"); ng3.GetDistribution(condition).Take(5).Print(); } catch (Exception e) { Console.WriteLine(e); } } }
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); } }
public static NGramInputMethod GetInputMethod(this NGramBase model) { return(new NGramInputMethod(model)); }
public NGramInputMethod(NGramBase model) { Model = model; }