public void Rebuild(List <UserAction> actions) { //if (actions.Count == 4) // System.Windows.Forms.MessageBox.Show("bbq"); //Mutex mutex = new Mutex(false, CommonInfo.GUID + "-user-actions-lock"); //mutex.WaitOne(); SuffixTree suffix_tree = new SuffixTree(actions); //mutex.ReleaseMutex(); suffix_tree.BuildTree(); _longest_repetitions = suffix_tree.GetLongestRepeatedSubstrings(1); //UserActionList list = suffix_tree.GetLongestRepeatedSubstring(1, 3); //if (list != null) //{ // //_logger.WriteLine("Repetition detected at " + DateTime.Now.ToString()); // foreach (UserAction action in list) // _logger.WriteLine(action.Description); //} //_logger.WriteLine("Tree build on " + DateTime.Now); //try //{ // foreach (string str in _suffix_tree.DumpEdges()) // { // _logger.WriteLine(str); // } //} //catch (Exception e) //{ // //System.Windows.Forms.MessageBox.Show(e.Message); //} }
public void VerifyPartialRandomInvalidWords() { SuffixTree tree = new SuffixTree(theString); tree.BuildTree(); Random random = new Random((int)DateTime.Now.Ticks); foreach (string individualString in individualStrings) { StringBuilder builder = new StringBuilder(individualString); //this will inject random characters into valid words for (int j = random.Next(individualString.Length - 2); j < random.Next(individualString.Length); j++) { builder.Insert(j, random.Next('a', 'z')); } string builtString = builder.ToString(); string message = "Corrupting: " + individualString + " as " + builtString; //I originally checked to see if builder is in individualStrings, however with such a large //data set it took way too long to execute. There is a risk that a random string of 5 to 15 //characters IS in the word list! if (!individualStrings.Contains(builtString)) { Assert.IsTrue(!tree.Search(builtString), message); } } }
public void VerifyValidWords() { int count = 0; SuffixTree tree = new SuffixTree(theString); tree.BuildTree(); Stopwatch timer = Stopwatch.StartNew(); foreach (string individualString in individualStrings) { Assert.IsTrue(tree.Search(individualString)); count++; } timer.Stop(); Console.WriteLine(count + " words processed in " + timer.ElapsedMilliseconds + " miliseconds."); }
public void VerifyValidWordsFromFile() { SuffixTree tree = new SuffixTree(theString); tree.BuildTree(); using (FileStream writeFile = new FileStream("suffixtreetest", FileMode.Create, FileAccess.Write, FileShare.None)) { SuffixTree.Save(writeFile, tree); } SuffixTree testTree; using (FileStream readFile = new FileStream("suffixtreetest", FileMode.Open, FileAccess.Read, FileShare.None)) { testTree = SuffixTree.LoadFromFile(readFile); } foreach (string individualString in individualStrings) { Assert.IsTrue(testTree.Search(individualString)); } }
public void VerifyRandomInvalidWords() { SuffixTree tree = new SuffixTree(theString); tree.BuildTree(); Random random = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < individualStrings.Count; i++) { StringBuilder builder = new StringBuilder(); for (int j = 5; j < random.Next(15); j++) { builder.Append(random.Next('a', 'z')); } string builtString = builder.ToString(); string message = "Random String " + builtString + " was found!"; //I originally checked to see if builder is in individualStrings, however with such a large //data set it took way too long to execute. There is a risk that a random string of 5 to 15 //characters IS in the word list! Assert.IsTrue(!tree.Search(builtString)); } }