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); }
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); }
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); }
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; }
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); }
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; }
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); }
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); }
public bool OverlapsOrIsAdjacentTo(PositionTextPair p) { return (position <= p.position && position + text.Length >= p.position) || (p.position <= position && p.position + p.text.Length >= position); }
public bool OverlapsOrIsAdjacentTo(PositionTextPair p) { return((position <= p.position && position + text.Length >= p.position) || (p.position <= position && p.position + p.text.Length >= position)); }