public MarkovGenerator(string text, GeneratorParams inputParams) { //Verify input is sane if (inputParams == null) { throw new Exceptions.InvalidArguments("Null Generator Parameters"); } if (inputParams.Punctuation == null) { throw new Exceptions.InvalidArguments("Null punctuation list"); } if (inputParams.SentenceEnd == null) { throw new Exceptions.InvalidArguments("Null end of sentence"); } Punctuation = inputParams.Punctuation; SentenceEnd = inputParams.SentenceEnd; _allPunctuation = new List <char>(); _allPunctuation.AddRange(Punctuation); _allPunctuation.AddRange(SentenceEnd); _allPunctuation = new List <char>(_allPunctuation.Distinct()); _chainGenerator = new ChainGenerator(text, _allPunctuation.ToArray(), inputParams.ChainSize); _chainGenerator.GenerateChains(); _wordGenerator = new WordGenerator(_chainGenerator.Chains, inputParams.Rand); _sentenceGenerator = new WordGenerator(_chainGenerator.Chains, inputParams.Rand); }
public void T_Chains_2() { ChainGenerator chainGenerator = new ChainGenerator(_advancedChainString, _delims, 2) ; chainGenerator.GenerateChains() ; Dictionary<ChainKey, List<string>> correctChains = new Dictionary<ChainKey, List<string>>{ {new ChainKey(new string[]{null, null}), new List<string>{"words"}}, {new ChainKey(new string[]{null, "words"}), new List<string>{"from"}}, {new ChainKey(new string[]{"words", "from"}), new List<string>{".", "sentence"}}, {new ChainKey(new string[]{"from", "."}), new List<string>{"sentence"}}, {new ChainKey(new string[]{".", "sentence"}), new List<string>{","}}, {new ChainKey(new string[]{"sentence", ","}), new List<string>{"will"}}, {new ChainKey(new string[]{",", "will"}), new List<string>{"never"}}, {new ChainKey(new string[]{"will", "never"}), new List<string>{"end"}}, {new ChainKey(new string[]{"never", "end"}), new List<string>{"?"}}, {new ChainKey(new string[]{"end", "?"}), new List<string>{"because"}}, {new ChainKey(new string[]{"?", "because"}), new List<string>{"words"}}, {new ChainKey(new string[]{"because", "words"}), new List<string>{"from"}}, {new ChainKey(new string[]{"from", "sentence"}), new List<string>{"is"}}, {new ChainKey(new string[]{"sentence", "is"}), new List<string>{"good"}}, {new ChainKey(new string[]{"is", "good"}), new List<string>{"."}} }; TestUtils.CompareChainTables(chainGenerator.Chains, correctChains) ; }
public MarkovGenerator(string text, GeneratorParams inputParams) { //Verify input is sane if(inputParams == null) { throw new Exceptions.InvalidArguments("Null Generator Parameters") ; } if(inputParams.Punctuation == null) { throw new Exceptions.InvalidArguments("Null punctuation list") ; } if(inputParams.SentenceEnd == null) { throw new Exceptions.InvalidArguments("Null end of sentence") ; } Punctuation = inputParams.Punctuation ; SentenceEnd = inputParams.SentenceEnd ; _allPunctuation = new List<char>() ; _allPunctuation.AddRange(Punctuation) ; _allPunctuation.AddRange(SentenceEnd) ; _allPunctuation = new List<char>(_allPunctuation.Distinct()) ; _chainGenerator = new ChainGenerator(text, _allPunctuation.ToArray(), inputParams.ChainSize) ; _chainGenerator.GenerateChains() ; _wordGenerator = new WordGenerator(_chainGenerator.Chains, inputParams.Rand) ; _sentenceGenerator = new WordGenerator(_chainGenerator.Chains, inputParams.Rand) ; }
/// <summary> /// Create a word generator with constant Random seed /// </summary> /// <returns></returns> private WordGenerator InitSimpleWordGen() { ChainGenerator chainGen = new ChainGenerator(_simpleSentence, TestUtils.StandardDelims.ToArray(), 2) ; chainGen.GenerateChains() ; return new WordGenerator(chainGen.Chains, new Random(1000)) ; }
public void T_Constructor_Exceptions() { string origText = "Hello world string."; ChainGenerator chainGenerator = new ChainGenerator(origText, _delims, 2) ; Assert.Throws(typeof(Exceptions.InvalidArguments), delegate { chainGenerator = new ChainGenerator(origText, _delims, 0);}); Assert.Throws(typeof(Exceptions.InvalidArguments), delegate { chainGenerator = new ChainGenerator(origText, _delims, 20);}); Assert.Throws(typeof(Exceptions.InvalidArguments), delegate { chainGenerator = new ChainGenerator(null, _delims, 2);}); }