예제 #1
0
        /// <summary>
        /// generates a bunch of items to be searched for within a larger text
        /// </summary>
        /// <param name="numberOfItems"></param>
        /// <returns></returns>
        public static List<string> GenerateTestDictionary(int numberOfItems)
        {
            List<string> rv = new List<string>();

            StringGenerator generator = new StringGenerator();

            for (int i = 0; i < numberOfItems; i++)
            {
                var line = generator.GenerateAlpha(10, 50);
                rv.Add(line);
            }
            return rv;
        }
예제 #2
0
        /// <summary>
        /// Generates a list of test strings, the number of items being specified by numberOfLines.
        /// percentMatch is the number of words in the dictionary per line, as dictated by pseudorandom distribution
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="percentMatch"></param>
        /// <param name="numberOfLines"></param>
        /// <returns></returns>
        public static List<string> GenerateSearchText(List<string> dictionary, int percentMatch, int numberOfLines)
        {
            List<string> rv = new List<string>();

            //define the flag to write out a dictionary item
            Random rnd = new Random();
            int dictSize = dictionary.Count;

            StringGenerator generator = new StringGenerator();
            int matchLines = 0;
            Func<string> generateLine = () =>
            {
                //get random number from 0 to 100
                var rndVal = rnd.Next(0, 100);
                //run random filter
                if (rndVal > percentMatch)
                    return string.Empty;

                matchLines++;

                //get random keyword and return it
                rndVal = rnd.Next(0, dictSize - 1);
                var keyWord = dictionary[rndVal];
                var fakeLinePrefix = generator.GenerateAlpha(100, 1000);
                var fakeLineSuffix = generator.GenerateAlpha(100, 1000);
                return fakeLinePrefix + keyWord + fakeLineSuffix; //stick the value in the middle of the fake line

            };

            for (int i = 0; i < numberOfLines; i++)
            {
                rv.Add(generateLine());
            }
            Debug.WriteLine("{0} match lines in {1} total", matchLines, numberOfLines);
            return rv;

        }
예제 #3
0
        public static List<string> GenerateDecorationySearchText(List<string> dictionary, int percentMatch, int numberOfLines)
        {
            List<string> rv = new List<string>();

            //define the flag to write out a dictionary item
            Random rnd = new Random();
            int dictSize = dictionary.Count;

            StringGenerator generator = new StringGenerator();
            Func<string> generateLine = () =>
            {
                string line = string.Empty;

                dictionary.ForEach(word =>
                {
                    var fakeLinePrefix = generator.GenerateAlpha(10, 50);
                    var fakeLineSuffix = generator.GenerateAlpha(10, 50);

                    line += fakeLinePrefix;

                    //get random number from 0 to 100
                    var rndVal = rnd.Next(0, 100);
                    //run random filter
                    if (rndVal < percentMatch)
                    {
                        line += word;
                    }
                    line += fakeLineSuffix;
                });

                return line;
            };

            for (int i = 0; i < numberOfLines; i++)
            {
                rv.Add(generateLine());
            }

            return rv;

        }