Example #1
0
 // Rule 1: Try to find matching edge for the parent node.
 private ExtensionResult extendSuffixByRuleOne(
     ref StSuffix active, ref StNode parentNode, int endIndex)
 {
     if (active.IsExplicit)
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[endIndex]);
         if (edge != null && edge.IsSet())
         {
             return(ExtensionResult.Done);
         }
     }
     else    // active suffix is implicit
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[active.BeginIndex]);
         int    span = active.EndIndex - active.BeginIndex;
         if (text[edge.BeginIndex + span + 1] == text[endIndex])
         {
             return(ExtensionResult.Done);
         }
         StUtil.WriteLine(StVerbosityLevel.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);
 }
            public SuffixTree(string text)
            {
                this.text = text;
                this.root = new StNode(this, null);

                StUtil.WriteLine(StVerbosityLevel.Verbose, "Creating the active (longest proper) suffix pointer");
                StSuffix active = new StSuffix(this, root, 0, InfiniteIndex);
                for (int endIndex = 0; endIndex < text.Length; endIndex++)
                {
                    StUtil.WriteLine(StVerbosityLevel.Verbose, this.ToString());
                    StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                        "Calling extendSuffixes() with endIndex = {0:d} ('{1:c}') and active suffix = {2:s}",
                        endIndex, text[endIndex], active.ToString()));
                    extendSuffixes(ref active, endIndex);
                }
                StUtil.Write(StVerbosityLevel.Normal, this.ToString());
            }
Example #3
0
            public SuffixTree(string text)
            {
                this.text = text;
                this.root = new StNode(this, null);

                StUtil.WriteLine(StVerbosityLevel.Verbose, "Creating the active (longest proper) suffix pointer");
                StSuffix active = new StSuffix(this, root, 0, InfiniteIndex);

                for (int endIndex = 0; endIndex < text.Length; endIndex++)
                {
                    StUtil.WriteLine(StVerbosityLevel.Verbose, this.ToString());
                    StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                         "Calling extendSuffixes() with endIndex = {0:d} ('{1:c}') and active suffix = {2:s}",
                                         endIndex, text[endIndex], active.ToString()));
                    extendSuffixes(ref active, endIndex);
                }
                StUtil.Write(StVerbosityLevel.Normal, this.ToString());
            }
 // Rule 1: Try to find matching edge for the parent node.
 private ExtensionResult extendSuffixByRuleOne(
     ref StSuffix active, ref StNode parentNode, int endIndex)
 {
     if (active.IsExplicit)
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[endIndex]);
         if (edge != null && edge.IsSet())
         {
             return ExtensionResult.Done;
         }
     }
     else    // active suffix is implicit
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[active.BeginIndex]);
         int span = active.EndIndex - active.BeginIndex;
         if (text[edge.BeginIndex + span + 1] == text[endIndex])
         {
             return ExtensionResult.Done;
         }
         StUtil.WriteLine(StVerbosityLevel.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;
 }