/// <summary> /// Rule #1 (Ukkonen's first group of t_i-transitions): Try to find matching edge for the parent node. /// </summary> /// <param name="parentNode">This is a member of active. It is kept separate for clarity.</param> private ExtensionResult extendSuffixByRuleOne( ref GstSuffix active, ref GstNode parentNode, int endIndex, int wordNum) { if (active.IsExplicit) { GstEdge edge = active.OriginNode.GetChildEdge(GetWordChar(wordNum, endIndex)); if (edge != null && edge.IsSet()) { return(ExtensionResult.Done); } } else // active suffix is implicit { GstEdge edge = active.OriginNode.GetChildEdge(GetWordChar(wordNum, active.BeginIndex)); int span = active.EndIndex - active.BeginIndex; if (edge != null) { int extantWordNum = edge.GetExtantWordNum(); if (GetWordChar(extantWordNum, edge.GetBeginIndex(extantWordNum) + span + 1) == GetWordChar(wordNum, endIndex)) { return(ExtensionResult.Done); } GstUtil.WriteLine(GstVerbosityLevel.Verbose, String.Format( " Rule #1: About to split edge E{0:d} (\"{1:s}\") at suffix {2:s}", edge.Id, edge.GetText(), active.ToString())); parentNode = edge.Split(active); } } return(ExtensionResult.NotDone); }
private bool AddWord(string word, bool doConsoleVerbose = false) { if (word == null || word.Length == 0) { return(false); } GstUtil.WriteLine(GstVerbosityLevel.Verbose, new String('-', 40)); int wordNum = wordCount++; wordDict[wordNum] = word; GstUtil.WriteLine(GstVerbosityLevel.Verbose, String.Format( "Adding word #{0:d} (\"{1:s}\") to the suffix tree", wordNum, wordDict[wordNum])); GstSuffix active = new GstSuffix(this, root, wordNum, 0, GSuffixTree.InfiniteIndex); GstUtil.WriteLine(GstVerbosityLevel.Verbose, String.Format( "Created active (longest proper) suffix pointer: {0:s}", active.ToString())); int endIndex = 0; if (wordNum > 0) { skipDuplicateInitialSubstring(ref active, ref endIndex, wordNum); if (endIndex > 0) { GstUtil.WriteLine(GstVerbosityLevel.Verbose, String.Format( "The first {0:d} letter(s) of word #{1:d} are already in the suffix tree", endIndex, wordNum)); } } for ( ; endIndex < wordDict[wordNum].Length; endIndex++) { GstUtil.WriteLine(GstVerbosityLevel.Verbose, this.ToString()); GstUtil.WriteLine(GstVerbosityLevel.Verbose, String.Format( "Calling extendSuffixes() for word #{0:d}, with endIndex = {1:d} ('{2:c}') and active suffix = {3:s}", wordNum, endIndex, GetWordChar(wordNum, endIndex), active.ToString())); extendSuffixes(ref active, endIndex, wordNum); } if (doConsoleVerbose) { string logStr = String.Format("Done adding word #{0:d} (\"{1:s}\") to the suffix tree", wordNum, wordDict[wordNum]); GstUtil.WriteLine(GstVerbosityLevel.Verbose, logStr); Console.WriteLine(logStr); Console.WriteLine(this.ToString()); } return(true); }