コード例 #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);
 }
コード例 #2
0
            // Rule 2: Create a new edge and add it to the tree at the parent's position.
            //     Part of this is inserting the new edge into the hash table,
            //     and creating a suffix link to the new node from the last one visited.
            private void extendSuffixByRuleTwo(
                ref StSuffix active, StNode parentNode, ref StNode prevParentNode, int endIndex)
            {
                StEdge newEdge = new StEdge(this, parentNode, endIndex, this.text.Length - 1);

                newEdge.Add();
                StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                     "  Rule #2: New edge E{0:d} (\"{1:s}\") connects N{2:d} (old parent) to N{3:d} (new child)",
                                     newEdge.Id,
                                     newEdge.GetText(),
                                     newEdge.ParentNode.Id,
                                     newEdge.ChildNode.Id
                                     ));
                setSuffixLink(prevParentNode, parentNode);
                prevParentNode = parentNode;
            }
コード例 #3
0
            public StNode Split(StSuffix s)
            {
                Remove();
                StEdge newEdge = new StEdge(tree, s.OriginNode, BeginIndex, BeginIndex + s.Span);

                newEdge.Add();
                newEdge.ChildNode.SuffixNode = s.OriginNode;
                BeginIndex += s.Span + 1;
                ParentNode  = newEdge.ChildNode;
                Add();
                StUtil.WriteLine(StVerbosityLevel.Normal, String.Format(
                                     "  Split E{0:d} into E{1:d} + E{0:d} = \"{2:s}\" + \"{3:s}\"",
                                     Id, newEdge.Id,
                                     newEdge.GetText(),
                                     this.GetText()
                                     ));
                return(newEdge.ChildNode);
            }
コード例 #4
0
 public StNode Split(StSuffix s)
 {
     Remove();
     StEdge newEdge = new StEdge(tree, s.OriginNode, BeginIndex, BeginIndex + s.Span);
     newEdge.Add();
     newEdge.ChildNode.SuffixNode = s.OriginNode;
     BeginIndex += s.Span + 1;
     ParentNode = newEdge.ChildNode;
     Add();
     StUtil.WriteLine(StVerbosityLevel.Normal, String.Format(
         "  Split E{0:d} into E{1:d} + E{0:d} = \"{2:s}\" + \"{3:s}\"",
         Id, newEdge.Id,
         newEdge.GetText(),
         this.GetText()
         ));
     return newEdge.ChildNode;
 }
コード例 #5
0
 // Rule 2: Create a new edge and add it to the tree at the parent's position.
 //     Part of this is inserting the new edge into the hash table,
 //     and creating a suffix link to the new node from the last one visited.
 private void extendSuffixByRuleTwo(
     ref StSuffix active, StNode parentNode, ref StNode prevParentNode,  int endIndex)
 {
     StEdge newEdge = new StEdge(this, parentNode, endIndex, this.text.Length - 1);
     newEdge.Add();
     StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
         "  Rule #2: New edge E{0:d} (\"{1:s}\") connects N{2:d} (old parent) to N{3:d} (new child)",
         newEdge.Id,
         newEdge.GetText(),
         newEdge.ParentNode.Id,
         newEdge.ChildNode.Id
         ));
     setSuffixLink(prevParentNode, parentNode);
     prevParentNode = parentNode;
 }