/// <summary>
        /// train with list of folder as array
        /// </summary>
        /// <param name="folderPathArr"></param>
        private async Task<bool> Train(string[] folderPathArr)
        {
            _model = new LanguageModelBuilder();
            const string progressTitle = "Please wait...";
            const string progressTemplate = "Folder: {0}\nTraining {1}/{2} file(s) ({3}%)...";
            var controller =
                await _window.ShowProgressAsync(progressTitle, String.Format(progressTemplate, "", 0, 0, 0));
            try
            {
                var sw = new Stopwatch();
                foreach (var folderPath in folderPathArr)
                {
                    sw.Restart();
                    var fileArr = Directory.GetFiles(folderPath);
                    //set initial progress
                    controller.SetMessage(String.Format(progressTemplate, folderPath, 0, fileArr.Length, 0));
                    await Task.Delay(1);

                    var cnt = 0;
                    var currentPercentage = 0;
                    foreach (var fileName in fileArr)
                    {
                        _model.Train(File.ReadAllText(fileName));
                        cnt++;
                        if (cnt*100/fileArr.Length <= currentPercentage) continue;
                        currentPercentage = cnt * 100 / fileArr.Length;
                        await Task.Delay(1);
                        controller.SetMessage(String.Format(progressTemplate, folderPath, cnt, fileArr.Length, currentPercentage));
                        controller.SetProgress((double)cnt / fileArr.Length);
                    }

                    //training with unknown word
                    _model.Train(LanguageModelBuilder.UnknownWordStr);

                    //marked as is trained
                    IsTrained = true;

                    _elapsedTime = (double)sw.ElapsedMilliseconds / 1000;
                    sw.Stop();
                    TrainingLog += String.Format("Trained folder {0} with {1} file(s). Elapsed Time: {2:##.###}s",
                        folderPath,
                        fileArr.Length,
                        _elapsedTime) + "\n";
                    TrainingLog += String.Format("Total words: {0}. Total distinct words: {1}.",
                        _model.WordCount,
                        _model.WordDict.Count) + "\n";
                    TrainingLog += String.Format("Total sentences: {0}.",
                        _model.SentenceCount) + "\n";
                }


            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
            await controller.CloseAsync();
            return true;
        }
        public void Test(string trainFolder, string testFolder)
        {
            var model = new LanguageModelBuilder();
            Console.WriteLine("Training first with {0}", trainFolder);
            //model.TrainByFolder(trainFolder, ShowLog);

            Console.WriteLine("Test with {0}", testFolder);
            //var perplexity = model.TestSourceByFolder(testFolder, ShowLog);
            //Console.WriteLine(perplexity);
        }
        public MainWindowViewModel(MetroWindow window)
        {
            _window = window;

            _model = new LanguageModelBuilder();

            _service = new FolderService();

            //assing commands
            ChooseTrainingFolder1Cmd = new DelegateCommand(ChooseTrainingFolder1);
            ChooseTrainingFolder2Cmd = new DelegateCommand(ChooseTrainingFolder2);

            TrainBothSetCmd = new DelegateCommand(TrainBothSet);
            GetAllWordsCmd = new DelegateCommand(GetAllWords);

            TrainAndTestCmd = new DelegateCommand<string>(TrainAndTest);
            GenSentencesCmd = new DelegateCommand(GenSentences);

            //get defaul training folder
            SetDefaultTrainingFolder();

            //marked trained as false
            IsTrained = false;

            //guess word
            GuessWords = new ObservableCollection<string> { "", "", "", "", "", "" };
            PrevWords = new ObservableCollection<string> { "", "", "", "", "", "" };
            _lastChange = DateTime.Now;
        }