Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Reset();
            openFileDialog1.Filter          = "文本文件(*.txt)|*.txt|所有文件|*";
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.Multiselect     = false;
            openFileDialog1.Title           = "打开文件";
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                GrammarEditor.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);

                /* isopenFile = true;
                 * istextChanged = false;
                 * this.tsBtnY.Text = Path.GetFileName(openFileDialog1.FileName) + "-源程序";
                 * fileAddress = openFileDialog1.FileName;*/
            }
        }
            public string Populate(int seed, bool checkGrammar)
            {
                Dictionary <int, Word> definedGroupWords = new Dictionary <int, Word>();
                WordDictionaryLookup   wordLookup        = new WordDictionaryLookup(seed);
                BigramDictionaryLookup bigramLookup      = new BigramDictionaryLookup(wordLookup, seed);

                foreach (TemplatePhrase phrase in phrases)
                {
                    phrase.SetSeed(seed);
                    phrase.Populate(definedGroupWords, bigramLookup, wordLookup);
                }

                string result = template;
                int    offset = 0;

                if (checkGrammar)
                {
                    foreach (TemplatePhrase phrase in phrases)
                    {
                        List <TemplateWord> editedWords = GrammarEditor.EditPhrase(phrase.words);
                        foreach (TemplateWord word in editedWords)
                        {
                            result  = result.Substring(0, word.start + offset) + word.Word.Value + result.Substring(word.start + word.length + offset);
                            offset += word.Word.Value.Length - word.ToString().Length;
                        }
                    }
                    result = GrammarEditor.Filter(result);
                }
                else
                {
                    foreach (TemplatePhrase phrase in phrases)
                    {
                        foreach (TemplateWord word in phrase.words)
                        {
                            result  = result.Substring(0, word.start + offset) + word.Word.Value + result.Substring(word.start + word.length + offset);
                            offset += word.Word.Value.Length - word.ToString().Length;
                        }
                    }
                }
                return(result);
            }