private string ExecuteWordJitter(string word, JitterType jitterType, double probabilityScaleFactor, int maxWordSize) { double jitterProbability = CalculateWordJitterProbability(word, jitterType, probabilityScaleFactor, maxWordSize); var proceed = _probabilityChecker.Check(jitterProbability); if (!proceed) { return(word); } switch (jitterType) { case JitterType.MutationSwitch: return(MutationSwitch(word)); case JitterType.MutationReplace: return(MutationReplace(word)); case JitterType.MutationRemove: return(MutationRemove(word)); case JitterType.MutationDuplicate: return(MutationDuplicate(word)); default: return(word); } }
public Task <string> ApplyJitterAsync(string source, JitterType jitterType, double probabilityScaleFactor = 0.5, int maxWordSize = 15) { if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(source)); } var words = source.Split(' ', StringSplitOptions.RemoveEmptyEntries); var jittered = new StringBuilder(); foreach (var word in words) { var jitteredWord = ExecuteWordJitter(word, jitterType, probabilityScaleFactor, maxWordSize); jittered.Append(jitteredWord); jittered.Append(" "); } return(Task.FromResult(jittered.ToString().Trim())); }
private double CalculateWordJitterProbability(string word, JitterType jitterType, double probabilityScaleFactor, int maxWordSize) { return(probabilityScaleFactor * (word.Length / (double)maxWordSize)); }