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