Пример #1
0
        public static void BuildModel(string filePath, IEnumerable <string> modelNames)
        {
            var stat = new TextStatistician(filePath);

            foreach (var modelName in modelNames)
            {
                var model = NGramModelFileLoader.NewByName(modelName);
                model.FromStatistician(stat);
                model.Save();
            }
        }
Пример #2
0
        public static void TestOnData(TestOption opt)
        {
            IEnumerable <NGramModelBase> models;

            if (opt.StatFiles == null)
            {
                models = opt.ModelNames.Select(NGramModelFileLoader.LoadByName);
            }
            else
            {
                models = from stat in opt.StatFiles.Select(path => new TextStatistician(path))
                         from model in opt.ModelNames.Select(name =>
                {
                    var model = NGramModelFileLoader.NewByName(name);
                    Console.WriteLine($"Built model: [{name}] from [{stat.SourceName}]");
                    model.FromStatistician(stat);
                    return(model);
                })
                         select model;
            }
            var inputers = models.Select(model => new NGramInputer(model)).Cast <FullPinyinInputer>().ToArray();
            var tester   = new InputerTester(inputers);

            using (var inputFile = File.OpenText(opt.InputFile))
            {
                if (opt.OutputFile == null)
                {
                    tester.TestData(inputFile, Console.Out, opt.Format);
                }
                else
                {
                    using (var outputFile = File.CreateText(opt.OutputFile))
                        tester.TestData(inputFile, outputFile, opt.Format);
                }
            }
        }