Exemplo n.º 1
0
        public override bool LessThan(System.Object a, System.Object b)
        {
            TextFragment fragA = (TextFragment)a;
            TextFragment fragB = (TextFragment)b;

            if (fragA.GetScore() == fragB.GetScore())
            {
                return(fragA.fragNum > fragB.fragNum);
            }
            else
            {
                return(fragA.GetScore() < fragB.GetScore());
            }
        }
Exemplo n.º 2
0
        /// <summary>Improves readability of a score-sorted list of TextFragments by merging any fragments
        /// that were contiguous in the original text into one larger fragment with the correct order.
        /// This will leave a "null" in the array entry for the lesser scored fragment.
        ///
        /// </summary>
        /// <param name="frag">An array of document fragments in descending score
        /// </param>
        private void  MergeContiguousFragments(TextFragment[] frag)
        {
            bool mergingStillBeingDone;

            if (frag.Length > 1)
            {
                do
                {
                    mergingStillBeingDone = false;                     //initialise loop control flag
                    //for each fragment, scan other frags looking for contiguous blocks
                    for (int i = 0; i < frag.Length; i++)
                    {
                        if (frag[i] == null)
                        {
                            continue;
                        }
                        //merge any contiguous blocks
                        for (int x = 0; x < frag.Length; x++)
                        {
                            if (frag[x] == null)
                            {
                                continue;
                            }
                            if (frag[i] == null)
                            {
                                break;
                            }
                            TextFragment frag1    = null;
                            TextFragment frag2    = null;
                            int          frag1Num = 0;
                            int          frag2Num = 0;
                            int          bestScoringFragNum;
                            int          worstScoringFragNum;
                            //if blocks are contiguous....
                            if (frag[i].Follows(frag[x]))
                            {
                                frag1    = frag[x];
                                frag1Num = x;
                                frag2    = frag[i];
                                frag2Num = i;
                            }
                            else if (frag[x].Follows(frag[i]))
                            {
                                frag1    = frag[i];
                                frag1Num = i;
                                frag2    = frag[x];
                                frag2Num = x;
                            }
                            //merging required..
                            if (frag1 != null)
                            {
                                if (frag1.GetScore() > frag2.GetScore())
                                {
                                    bestScoringFragNum  = frag1Num;
                                    worstScoringFragNum = frag2Num;
                                }
                                else
                                {
                                    bestScoringFragNum  = frag2Num;
                                    worstScoringFragNum = frag1Num;
                                }
                                frag1.Merge(frag2);
                                frag[worstScoringFragNum] = null;
                                mergingStillBeingDone     = true;
                                frag[bestScoringFragNum]  = frag1;
                            }
                        }
                    }
                }while (mergingStillBeingDone);
            }
        }