LLM for Unity  v2.3.0
Create characters in Unity with LLMs!
Loading...
Searching...
No Matches
SentenceSplitter.cs
Go to the documentation of this file.
1
3using System;
4using System.Collections.Generic;
5using System.Threading.Tasks;
6using System.Linq;
7
8namespace LLMUnity
9{
14 [Serializable]
16 {
17 public const string DefaultDelimiters = ".!:;?\n\r";
19 public char[] delimiters = DefaultDelimiters.ToCharArray();
20
26 public override async Task<List<(int, int)>> Split(string input)
27 {
28 List<(int, int)> indices = new List<(int, int)>();
29 await Task.Run(() => {
30 int startIndex = 0;
31 bool seenChar = false;
32 for (int i = 0; i < input.Length; i++)
33 {
34 bool isDelimiter = delimiters.Contains(input[i]);
35 if (isDelimiter)
36 {
37 while ((i < input.Length - 1) && (delimiters.Contains(input[i + 1]) || char.IsWhiteSpace(input[i + 1]))) i++;
38 }
39 else
40 {
41 if (!seenChar) seenChar = !char.IsWhiteSpace(input[i]);
42 }
43 if ((i == input.Length - 1) || (isDelimiter && seenChar))
44 {
45 indices.Add((startIndex, i));
46 startIndex = i + 1;
47 }
48 }
49 });
50 return indices;
51 }
52 }
53}
Class implementing the chunking functionality.
Definition Chunking.cs:18
Class implementing a sentence-based splitter.
char[] delimiters
delimiters used to split the phrases
override async Task< List<(int, int)> > Split(string input)
Splits the provided phrase into chunks according to delimiters (defined in the delimiters variable)