Example #1
0
        public IEnumerable <SentenceModel> Right(SentenceModel sentence)
        {
            var i = GetIndex(sentence);

            if (i < 0)
            {
                yield break;
            }

            i += 1;
            while (i < Sentences.Count)
            {
                var candidate = Sentences[i];
                if (Math.Abs(candidate.Bottom - sentence.Bottom) < YTolerance)
                {
                    if (candidate.Right > sentence.Right)
                    {
                        yield return(candidate);
                    }
                    else
                    {
                        yield break;
                    }
                }
                i += 1;
            }
        }
Example #2
0
        public IEnumerable <SentenceModel> Left(SentenceModel sentence)
        {
            var i = GetIndex(sentence);

            if (i < 0)
            {
                yield break;
            }

            i -= 1;
            while (i > 0)
            {
                var candidate = Sentences[i];
                if (Math.Abs(candidate.Bottom - sentence.Bottom) < YTolerance)
                {
                    if (candidate.Left < sentence.Left)
                    {
                        yield return(candidate);
                    }
                    else
                    {
                        yield break;
                    }
                }
                i -= 1;
            }
        }
Example #3
0
        private bool AreInSameColumn(SentenceModel main, SentenceModel secondary)
        {
            var isMainRightMost      = !Right(main).Any();
            var isSecondaryRightMost = !Right(secondary).Any();

            if (isMainRightMost && isSecondaryRightMost)
            {
                var leftOfMain      = Left(main).FirstOrDefault();
                var leftOfSecondary = Left(secondary).FirstOrDefault();

                if (leftOfMain?.Right < main.Left &&
                    leftOfMain.Right < secondary.Left &&
                    leftOfSecondary?.Right < main.Left &&
                    leftOfSecondary.Right < secondary.Left
                    )
                {
                    return(true);
                }
            }

            var midX            = main.Left + main.Width / 2;
            var secondaryLeft   = (Left(secondary).FirstOrDefault()?.Right + secondary.Left) / 2 ?? secondary.Left - 100;
            var candidateRight  = (Right(secondary).FirstOrDefault()?.Left + secondary.Right) / 2 ?? secondary.Right + 100;
            var areInSameColumn = secondaryLeft <= midX && midX <= candidateRight;

            return(areInSameColumn);
        }
Example #4
0
        private int GetIndex(SentenceModel sentence)
        {
            var index = sentence.PageIndex;

            if (index < 0)
            {
                return(-1);
            }
            if (index > Sentences.Count)
            {
                return(-1);
            }
            return(Sentences[index] == sentence ? index : -1);
        }
Example #5
0
        public IEnumerable <SentenceModel> Below(SentenceModel sentence)
        {
            var i = GetIndex(sentence);

            if (i < 0)
            {
                yield break;
            }

            i += 1;
            while (i < Sentences.Count)
            {
                var candidate = Sentences[i];
                if (candidate.Bottom > sentence.Bottom)
                {
                    if (AreInSameColumn(sentence, candidate))
                    {
                        yield return(candidate);
                    }
                }
                i += 1;
            }
        }
Example #6
0
        public SentenceModel Above(SentenceModel sentence)
        {
            var i = GetIndex(sentence);

            if (i < 0)
            {
                return(null);
            }

            i -= 1;
            while (i >= 0)
            {
                var candidate = Sentences[i];
                if (candidate.Bottom < sentence.Bottom)
                {
                    if (AreInSameColumn(sentence, candidate))
                    {
                        return(candidate);
                    }
                }
                i -= 1;
            }
            return(null);
        }