Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }