Ejemplo n.º 1
0
        public void Add(string word, int pos = 0)
        {
            if (pos == word.Length)
            {
                if (word.Length > 0)
                {
                    words.Add(word);
                }
                return;
            }
            var currentChar = word[pos];
            int edgeIndex   = 0;

            try
            {
                edgeIndex = letterMaps[currentChar];
            }
            catch (Exception) { }
            if (edges[edgeIndex] == null)
            {
                edges[edgeIndex] = new Predictive();
            }
            var nextPredic = edges[edgeIndex];

            nextPredic.Add(word, pos + 1);
        }
Ejemplo n.º 2
0
        public Predictive FindMostPopulatedNode()
        {
            Stack <Predictive> stk = new Stack <Predictive>();

            stk.Push(this);
            Predictive biggest = null;

            while (stk.Any())
            {
                var node = stk.Pop();
                biggest = biggest == null
                   ? node
                   : (node.words.Count > biggest.words.Count
                       ? node
                       : biggest);
                foreach (var next in node.edges.Where(e => e != null))
                {
                    stk.Push(next);
                }
            }
            return(biggest);
        }