Advertisement
xxdriesxx

Rule-set + pattern generation algorithm

Jun 28th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. foreach (string s in dataSequence)
  2. {
  3.     int rest = data.Length%stepSize;
  4.  
  5.     for (int i = 0; i < data.Length - rest; i += stepSize)
  6.     {
  7.         string first = data.Substring(i, stepSize);
  8.         string followedBy = "";
  9.  
  10.         if (i == data.Length - (rest + stepSize))
  11.             followedBy = data.Substring(i + stepSize, rest);
  12.         else
  13.             followedBy = data.Substring(i + stepSize, stepSize);
  14.  
  15.         if (!_rules.ContainsKey(first))
  16.         {
  17.             _rules.Add(first, new List<string>());
  18.                 }
  19.  
  20.         _rules[first].Add(followedBy);
  21.     }
  22.    
  23.     var vowels = new char[] { 'a', 'e', 'i', 'o', 'u' };
  24.     var consonants = new char[]
  25.     {
  26.         'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v',
  27.         'w', 'x', 'y', 'z'
  28.     };
  29.  
  30.     var pattern = "";
  31.  
  32.     foreach (var character in name.ToLower())
  33.     {
  34.         if (vowels.Contains(character))
  35.             pattern += 'V';
  36.         else if (consonants.Contains(character))
  37.             pattern += 'C';
  38.         else
  39.             pattern += character;
  40.     }
  41.  
  42.     _patterns.Add(pattern);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement