예제 #1
0
        public void Merge(PositionTextPair p)
        {
            if (p.position >= position && p.position + p.text.Length <= position + text.Length)
            {
                return;
            }
            else if (position >= p.position && position + text.Length <= p.position + p.text.Length)
            {
                text = p.text;
            }
            else if (position <= p.position && position + text.Length >= p.position)
            {
                if (position + text.Length == p.position)
                {
                    text += p.text;
                }
                else
                {
                    text += p.text.Substring(position + text.Length - p.position);
                }
            }
            else if (p.position <= position && p.position + p.text.Length >= position)
            {
                if (p.position + p.text.Length == position)
                {
                    text = p.text + text;
                }
                else
                {
                    text = p.text + text.Substring(p.position + p.text.Length - position);
                }
            }

            position = Math.Min(position, p.position);
        }
예제 #2
0
 public PositionTextPairGroup(PositionTextPair pair,
                              int contextSizeChars)
 {
     startPosition = Math.Max(0, pair.position - contextSizeChars);
     endPosition = pair.position + pair.text.Length + contextSizeChars;
     pairs = new List<PositionTextPair>();
     pairs.Add(pair);
 }
예제 #3
0
 public PositionTextPairGroup(PositionTextPair pair,
                              int contextSizeChars)
 {
     startPosition = Math.Max(0, pair.position - contextSizeChars);
     endPosition   = pair.position + pair.text.Length + contextSizeChars;
     pairs         = new List <PositionTextPair>();
     pairs.Add(pair);
 }
예제 #4
0
        public bool IsWithinRange(PositionTextPair pair,
                                  int contextSizeChars)
        {
            int distanceToStart = startPosition - (pair.position + pair.text.Length);
            int distanceFromEnd = pair.position - endPosition;

            Console.WriteLine("isWithinRange: group [{0} - {1}], pair {2}, {3}, context {4} => {5} {6}",
                              startPosition, endPosition, pair.position, pair.text.Length, contextSizeChars, distanceToStart, distanceFromEnd);
            return Math.Max(distanceToStart, distanceFromEnd) <= contextSizeChars;
        }
예제 #5
0
        public bool IsWithinRange(PositionTextPair pair,
                                  int contextSizeChars)
        {
            int distanceToStart = startPosition - (pair.position + pair.text.Length);
            int distanceFromEnd = pair.position - endPosition;

            Console.WriteLine("isWithinRange: group [{0} - {1}], pair {2}, {3}, context {4} => {5} {6}",
                              startPosition, endPosition, pair.position, pair.text.Length, contextSizeChars, distanceToStart, distanceFromEnd);
            return(Math.Max(distanceToStart, distanceFromEnd) <= contextSizeChars);
        }
예제 #6
0
        public PositionTextPairGroup Extend(PositionTextPair pair,
                                            int contextSizeChars)
        {
            if (startPosition > Math.Max(0, pair.position - contextSizeChars))
                startPosition = Math.Max(0, pair.position - contextSizeChars);
            else if (endPosition < pair.position + pair.text.Length + contextSizeChars)
                endPosition = pair.position + pair.text.Length + contextSizeChars;

            foreach (PositionTextPair p in pairs)
            {
                if (p.OverlapsOrIsAdjacentTo(pair))
                {
                    p.Merge(pair);
                    return this;
                }
            }
            pairs.Add(pair);
            return this;
        }
예제 #7
0
        public void Merge(PositionTextPair p)
        {
            if (p.position >= position && p.position + p.text.Length <= position + text.Length)
                return;
            else if (position >= p.position && position + text.Length <= p.position + p.text.Length)
                text = p.text;
            else if (position <= p.position && position + text.Length >= p.position)
            {
                if (position + text.Length == p.position)
                    text += p.text;
                else
                    text += p.text.Substring(position + text.Length - p.position);
            }
            else if (p.position <= position && p.position + p.text.Length >= position)
            {
                if (p.position + p.text.Length == position)
                    text = p.text + text;
                else
                    text = p.text + text.Substring(p.position + p.text.Length - position);
            }

            position = Math.Min(position, p.position);
        }
예제 #8
0
        public PositionTextPairGroup Extend(PositionTextPair pair,
                                            int contextSizeChars)
        {
            if (startPosition > Math.Max(0, pair.position - contextSizeChars))
            {
                startPosition = Math.Max(0, pair.position - contextSizeChars);
            }
            else if (endPosition < pair.position + pair.text.Length + contextSizeChars)
            {
                endPosition = pair.position + pair.text.Length + contextSizeChars;
            }

            foreach (PositionTextPair p in pairs)
            {
                if (p.OverlapsOrIsAdjacentTo(pair))
                {
                    p.Merge(pair);
                    return(this);
                }
            }
            pairs.Add(pair);
            return(this);
        }
예제 #9
0
 public bool OverlapsOrIsAdjacentTo(PositionTextPair p)
 {
     return (position <= p.position && position + text.Length >= p.position)
         || (p.position <= position && p.position + p.text.Length >= position);
 }
예제 #10
0
 public bool OverlapsOrIsAdjacentTo(PositionTextPair p)
 {
     return((position <= p.position && position + text.Length >= p.position) ||
            (p.position <= position && p.position + p.text.Length >= position));
 }