Esempio n. 1
0
        /// <summary>
        /// Teaverse Tree on Breath First Type
        /// </summary>
        /// <returns></returns>
        private string[] DoBFSTraverse(NodeWithFreq node)
        {
            if (node.HaveLinks())
            {
                List <string> suggestions = new List <string>();
                StringBuilder sb          = new StringBuilder();
                foreach (NodeWithFreq curNode in node.GetLinks())
                {
                    sb.Append(DoDFSTraverse(curNode));
                    suggestions.Add(sb.ToString());
                    sb.Remove(0, sb.Length);
                }

                return(suggestions.ToArray());
            }

            return(new string[] { node.Value.ToString() });
        }
Esempio n. 2
0
        /// <summary>
        /// Teaverse Tree on Depth First Type
        /// </summary>
        /// <returns></returns>
        private string[] DoDFSTraverse(NodeWithFreq node)
        {
            if (node.HaveLinks())
            {
                List <string> retDFS = new List <string>();
                foreach (NodeWithFreq curNode in node.GetLinks())
                {
                    retDFS.AddRange(DoDFSTraverse(curNode));
                }

                List <string> suggestions = new List <string>();
                if (node.Value != this.m_root.Value)
                {
                    if (node.IsEndOfWord)
                    {
                        suggestions.Add(new StringBuilder().Append(node.Value).ToString());
                    }

                    StringBuilder sb = new StringBuilder();
                    foreach (string str in retDFS)
                    {
                        sb.Append(str);
                        sb.Append(node.Value);
                        suggestions.Add(sb.ToString());
                        sb.Remove(0, sb.Length);
                    }

                    return(suggestions.ToArray());
                }
                else
                {
                    return(retDFS.ToArray());
                }
            }

            if (node.IsEndOfWord)
            {
                return(new string[] { new StringBuilder().Append(node.Value).ToString() });
            }
            else
            {
                return(new string[0]);
            }
        }