26 public override async Task<List<(int, int)>>
Split(
string input)
28 bool IsBoundary(
char c)
30 return Char.IsPunctuation(c) || Char.IsWhiteSpace(c);
33 List<(int, int)> indices =
new List<(
int,
int)>();
34 await Task.Run(() => {
35 List<(int, int)> wordIndices =
new List<(
int,
int)>();
38 for (
int i = 0; i < input.Length; i++)
40 if (i == input.Length - 1 || IsBoundary(input[i]))
42 while (i < input.Length - 1 && IsBoundary(input[i + 1])) i++;
44 wordIndices.Add((startIndex, endIndex));
49 for (
int i = 0; i < wordIndices.Count; i +=
numWords)
51 int iTo = Math.Min(wordIndices.Count - 1, i +
numWords - 1);
52 indices.Add((wordIndices[i].Item1, wordIndices[iTo].Item2));