internal static EntryProximity EstimateProximity(List <long> Left, List <long> Right) { int iLeft = 0, iRight = 0; EntryProximity Result = EntryProximity.Document; while ((iLeft < Left.Count) && (iRight < Right.Count)) { long leftOff = Left[iLeft]; long rightOff = Right[iRight]; if (MaskEncoder.Sentence(leftOff) == MaskEncoder.Sentence(rightOff)) { Result = EntryProximity.Sentence; if (isPhraseProximity(MaskEncoder.TokenOrder(leftOff), MaskEncoder.TokenOrder(rightOff))) { Result = EntryProximity.Phrase; break; } } if (MaskEncoder.OffsetNormal(leftOff) < MaskEncoder.OffsetNormal(rightOff)) { iLeft++; } else { iRight++; } } return(Result); }
internal static EntryProximity EstimateProximity(Entry Left, Entry Right) { Debug.Assert(Left.DocIndex == Right.DocIndex, "Illegal precondition for calling Estimator - doc IDs are different"); int iLeft = 0, iRight = 0; EntryProximity Result = EntryProximity.Document; while ((iLeft < Left.Count) && (iRight < Right.Count)) { InstanceOffset leftOff = Left.Instance(iLeft); InstanceOffset rightOff = Right.Instance(iRight); if (leftOff.Sentence == rightOff.Sentence) { Result = EntryProximity.Sentence; if (isPhraseProximity(leftOff, rightOff)) { Result = EntryProximity.Phrase; break; } } if (leftOff.OffsetNormal < rightOff.OffsetNormal) { iLeft++; } else { iRight++; } } return(Result); }
//------------------------------------------------------------------------- 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); }
///<summary> /// "And" and "Near" Ops. Particular behavior is determined by optional /// predicate which may perform additional check of [intermediate] document, /// feasible for inclusion into the result set /// </summary> private static Entry[] Intercross(Entry[] leftIndices, Entry[] rightIndices, EntryProximity reqProximity) { if ((leftIndices == null) || (rightIndices == null)) { return(null); } Array.Sort(leftIndices); Array.Sort(rightIndices); //--------------------------------------------------------------------- ArrayList array_ = new ArrayList(); int i_Left = 0, i_Right = 0; while ((i_Left < leftIndices.Length) && (i_Right < rightIndices.Length)) { if (leftIndices[i_Left].DocIndex == rightIndices[i_Right].DocIndex) { EntryProximity scope = ProximityEstimator.EstimateProximity(leftIndices[i_Left], rightIndices[i_Right]); if (scope <= reqProximity) { leftIndices[i_Left].Proximity = scope; array_.Add(JoinInstancesOfEntries(leftIndices[i_Left], rightIndices[i_Right], reqProximity)); } i_Left++; i_Right++; } else if (leftIndices[i_Left].DocIndex < rightIndices[i_Right].DocIndex) { i_Left++; } else { i_Right++; } } //--------------------------------------------------------------------- Entry[] ai_Result = null; if (array_.Count > 0) { ai_Result = new Entry[array_.Count]; array_.CopyTo(ai_Result); } return(ai_Result); }
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); }
private static List <long> Intercross(List <long> leftIndices, List <long> rightIndices, EntryProximity reqProximity) { if ((leftIndices == null) || (rightIndices == null)) { return(null); } leftIndices.Sort(); rightIndices.Sort(); List <long> result = new List <long>(); EntryProximity scope = ProximityEstimator.EstimateProximity(leftIndices, rightIndices); if (scope <= reqProximity) { result.AddRange(JoinInstancesOfEntries(leftIndices, rightIndices, reqProximity)); } return((result.Count == 0) ? null : result); }