Exemplo n.º 1
0
        internal ICollection <SearchResultOfHead2Left <T> > FindOfHead2Left(ss_word_t headWord)
        {
            var ss     = default(SortedSet <SearchResultOfHead2Left <T> >);
            var finder = Finder.Create(_Root);
            int index  = 0;

            for (var word = headWord; word != null; word = word.next)
            {
                var node = finder.Find(word.valueOriginal);

                if (node.HasNgrams)
                {
                    foreach (var ngram in node.Ngrams)
                    {
                        var wordIndex = index - ngram.words.Length + 1;
                        if (wordIndex == 0)
                        {
                            if (ss == null)
                            {
                                ss = new SortedSet <SearchResultOfHead2Left <T> >(SearchResultOfHead2Left <T> .Comparer.Inst);
                            }

                            var r = ss.Add(new SearchResultOfHead2Left <T>(word, ngram.words.Length, ngram.value));
                            Debug.Assert(r);
                        }
                    }
                }
                index++;
            }
            if (ss != null)
            {
                return(ss);
            }
            return(EMPTY_RESULT_2);
        }
Exemplo n.º 2
0
        internal ICollection <SearchResultOfHead2Left <TValue> > FindOfHead2Left(ss_word_t headWord)
        {
            var searchResults = default(SortedSet <SearchResultOfHead2Left <TValue> >);

            TreeNode node  = _Root;
            int      index = 0;

            for (var word = headWord; word != null; word = word.next)
            {
                TreeNode trans = null;
                while (trans == null)
                {
                    trans = node.GetTransition(word.valueOriginal);
                    if (node == _Root)
                    {
                        break;
                    }
                    if (trans == null)
                    {
                        node = node.Failure;
                    }
                }
                if (trans != null)
                {
                    node = trans;
                }

                if (0 < node.Ngrams.Count)
                {
                    //for ( int i = 0, len = node.Ngrams.Count; i < len; i++ )
                    foreach (var ngram in node.Ngrams)
                    {
                        var wordIndex = index - ngram.words.Length + 1;
                        if (wordIndex == 0)
                        {
                            if (searchResults == null)
                            {
                                searchResults = new SortedSet <SearchResultOfHead2Left <TValue> >(SearchResultOfHead2LeftIComparer.Instance);
                            }
                            var r = searchResults.Add(new SearchResultOfHead2Left <TValue>(word, ngram.words.Length, ngram.value));
                            System.Diagnostics.Debug.Assert(r);
                        }
                    }
                }
                index++;
            }
            if (searchResults != null)
            {
                return(searchResults);
            }
            return(EMPTY_RESULT_2);
        }
Exemplo n.º 3
0
 public SearchResultOfHead2Left(ss_word_t lastWord, int length, TValue value) : this()
 {
     LastWord = lastWord;
     Length   = length;
     v        = value;
 }