Ejemplo n.º 1
0
        public bool AddNgrams(ref VBuffer <uint> src, int icol, uint keyMax)
        {
            Contracts.Assert(icol >= 0);
            Contracts.Assert(keyMax > 0);

            uint curKey = 0;

            if (src.IsDense)
            {
                for (int i = 0; i < src.Length; i++)
                {
                    curKey = src.Values[i];
                    if (curKey > keyMax)
                    {
                        curKey = 0;
                    }

                    _queue.AddLast(curKey);

                    // Add the ngram counts
                    if (_queue.IsFull && !ProcessNgrams(icol))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                var queueSize = _queue.Capacity;

                int iindex = 0;
                for (int i = 0; i < src.Length; i++)
                {
                    if (iindex < src.Count && i == src.Indices[iindex])
                    {
                        curKey = src.Values[iindex];
                        if (curKey > keyMax)
                        {
                            curKey = 0;
                        }
                        iindex++;
                    }
                    else
                    {
                        curKey = 0;
                    }

                    _queue.AddLast(curKey);
                    if (!_queue.IsFull)
                    {
                        continue;
                    }

                    // Add the ngram counts
                    if (!ProcessNgrams(icol))
                    {
                        return(false);
                    }
                }
            }

            if (_queue.IsFull)
            {
                _queue.RemoveFirst();
            }

            // Process the grams of the remaining terms
            while (_queue.Count > 0)
            {
                if (!ProcessNgrams(icol))
                {
                    return(false);
                }
                _queue.RemoveFirst();
            }
            return(true);
        }