Exemple #1
0
        //-------------------------------------------------------------------------
        private static Entry  JoinInstancesOfEntries(Entry left, Entry right,
                                                     EntryProximity requiredProximity)
        {
            Entry JoinedEntry = new Entry();

            JoinedEntry.DocIndex  = left.DocIndex;
            JoinedEntry.TfIdf     = left.TfIdf + right.TfIdf;
            JoinedEntry.Proximity = left.Proximity;
            InstanceOffset[] joinedOffsets;

            //  If required proximity is Phrasal, then we need to highlight
            //  only those terms and show only those contexts which correspond
            //  to seach term instances EXACTLY in phrases found, and not
            //  others located elsewhere in the document.
            if (requiredProximity == EntryProximity.Phrase)
            {
                //  Assumption is made that all offsets in the entries are
                //  sorted in asceding order.

                ArrayList tempOffsets = new ArrayList();
                int       leftIndex = 0, rightIndex = 0;
                while (leftIndex < left.Count && rightIndex < right.Count)
                {
                    InstanceOffset leftOff = left.Offsets[leftIndex], rightOff = right.Offsets[rightIndex];
                    if (ProximityEstimator.isPhraseProximity(leftOff, rightOff))
                    {
                        tempOffsets.Add(leftOff);
                        tempOffsets.Add(rightOff);
                        AddMappedInstances(tempOffsets, left.DocIndex, rightOff);
                        MappedInstances[HC(left.DocIndex, leftOff.OffsetNormal)] = rightOff;
                    }
                    if (leftOff.OffsetNormal < rightOff.OffsetNormal)
                    {
                        leftIndex++;
                    }
                    else
                    {
                        rightIndex++;
                    }
                }
                joinedOffsets = (InstanceOffset[])tempOffsets.ToArray(typeof(InstanceOffset));
            }
            else
            {
                joinedOffsets = new InstanceOffset[left.Count + right.Count];
                left.Offsets.CopyTo(joinedOffsets, 0);
                right.Offsets.CopyTo(joinedOffsets, left.Count);
            }
            JoinedEntry.Offsets = joinedOffsets;

            return(JoinedEntry);
        }
Exemple #2
0
        private static List <long> JoinInstancesOfEntries(List <long> left, List <long> right,
                                                          EntryProximity requiredProximity)
        {
            List <long> joinedList = new List <long>();

            if (requiredProximity == EntryProximity.Phrase)
            {
                //  Assumption is made that all offsets in the entries are
                //  sorted in asceding order.

                int leftIndex = 0, rightIndex = 0;
                while (leftIndex < left.Count && rightIndex < right.Count)
                {
                    int order1 = MaskEncoder.TokenOrder(left[leftIndex]),
                        order2 = MaskEncoder.TokenOrder(right[rightIndex]);

                    if (ProximityEstimator.isPhraseProximity(order1, order2))
                    {
                        joinedList.Add(left[leftIndex]);
                        joinedList.Add(right[rightIndex]);
                    }
                    if (order1 < order2)
                    {
                        leftIndex++;
                    }
                    else
                    {
                        rightIndex++;
                    }
                }
            }
            else
            {
                joinedList.AddRange(left);
                joinedList.AddRange(right);
            }

            return(joinedList);
        }