Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new <see cref="MarkovChainsNameGenerator"/> instance with specified map depth,
 /// minimum frequency, minimum and maximum lengths, with specified capitalization and whitespace-handling modes,
 /// with specified <see cref="Random"/> used to generate outputs, and eventually a list of forbidden and/or
 /// already-occured outputs.
 /// </summary>
 /// <param name="random"><see cref="Random"/> which will be used for generating outputs. If null, a new
 /// <see cref="Random"/> will be created automatically.</param>
 /// <param name="mapDepth">The depth of the <see cref="MarkovChainMap{T}"/> of strings which will be used to
 /// produce outputs.</param>
 /// <param name="minFrequency">The minimum frequency considered while producing random outputs. Please see
 /// <see cref="Sieve{T}.MinFrequency"/>. Will eventually be lower-bounded to zero.</param>
 /// <param name="minLength">The minimum length of produced outputs. Will eventually be lower-bounded to one.
 /// </param>
 /// <param name="maxLength">The maximum length of produced outputs. Will eventually be lower-bounded to
 /// <paramref name="minLength"/>.</param>
 /// <param name="capitalize">Whether or not outputs will be capitalized.</param>
 /// <param name="skipWhitespace">Whether or not whitespaces will be ignored while parsing the sample file into a
 /// <see cref="MarkovChainMap{T}"/>. Please see <see cref="MarkovChainStringMapBuilder.SkipWhitespace"/>.</param>
 /// <param name="blacklistedNames">A list of forbiden and/or already produced outputs. This list will be qualified
 /// further while new outputs are generated.</param>
 /// <exception cref="ArgumentException"><paramref name="mapDepth"/> is less than one.</exception>
 public MarkovChainsNameGenerator(Random random    = null, int mapDepth = DefaultDepth,
                                  int minFrequency = DefaultMinFrequency, int minLength = DefaultMinLength, int maxLength             = DefaultMaxLength,
                                  bool capitalize  = true, bool skipWhitespace          = true, IEnumerable <string> blacklistedNames = null)
 {
     _random         = random ?? new Random(Environment.TickCount);
     _mapDepth       = mapDepth;
     _minFrequency   = Math.Max(0, minFrequency);
     _minLength      = Math.Max(1, minLength);
     _maxLength      = Math.Max(_minLength, maxLength);
     _capitalize     = capitalize;
     _skipWhitespace = skipWhitespace;
     _mapBuilder     = new MarkovChainStringMapBuilder(mapDepth, skipWhitespace);
     _sieve          = new Sieve <string>(_minFrequency, _random);
     _sb             = new StringBuilder(_maxLength);
     if (blacklistedNames == null)
     {
         _blacklistedNames = new HashSet <string>();
     }
     else
     {
         _blacklistedNames = new HashSet <string>(blacklistedNames);
     }
 }