Beispiel #1
0
        public List <string> Predictions(string prefix)
        {
            List <string> pred = new List <string>();

            if (prefix == null || prefix.Length == 0 || !root.ContainsKey(prefix[0]))
            {
                return(pred);
            }

            Node cur = root[prefix[0]];

            for (int i = 1; i < prefix.Length; i++)
            {
                if (cur.hasChild(prefix[i]))
                {
                    cur = cur.getChild(prefix[i]);
                }
                else
                {
                    break;
                }
            }

            GetWords(cur, pred);
            return(pred);
        }
Beispiel #2
0
        private void GetWords(Node node, List <string> pred)
        {
            if (pred.Count >= maxPredictions)
            {
                return;
            }

            foreach (char c in node.dict.Keys)
            {
                Node cur = node.getChild(c);
                if (cur.IsWord)
                {
                    pred.Add(cur.str);
                    if (pred.Count > maxPredictions)
                    {
                        return;
                    }
                }

                GetWords(cur, pred);
            }
        }
Beispiel #3
0
        private void GetWords(Node node, List<string> pred)
        {
            if (pred.Count >= maxPredictions)
                return;

            foreach (char c in node.dict.Keys)
            {
                Node cur = node.getChild(c);
                if (cur.IsWord)
                {
                    pred.Add(cur.str);
                    if (pred.Count > maxPredictions)
                        return;
                }

                GetWords(cur, pred);
            }
        }