LLM for Unity  v2.4.2
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;
7using UnityEngine;
8
9namespace LLMUnity
10{
15 [Serializable]
17 {
18 public const string DefaultDelimiters = ".!:;?\n\r";
20 [Tooltip("delimiters used to split the phrases")]
21 public char[] delimiters = DefaultDelimiters.ToCharArray();
22
28 public override async Task<List<(int, int)>> Split(string input)
29 {
30 List<(int, int)> indices = new List<(int, int)>();
31 await Task.Run(() => {
32 int startIndex = 0;
33 bool seenChar = false;
34 for (int i = 0; i < input.Length; i++)
35 {
36 bool isDelimiter = delimiters.Contains(input[i]);
37 if (isDelimiter)
38 {
39 while ((i < input.Length - 1) && (delimiters.Contains(input[i + 1]) || char.IsWhiteSpace(input[i + 1]))) i++;
40 }
41 else
42 {
43 if (!seenChar) seenChar = !char.IsWhiteSpace(input[i]);
44 }
45 if ((i == input.Length - 1) || (isDelimiter && seenChar))
46 {
47 indices.Add((startIndex, i));
48 startIndex = i + 1;
49 }
50 }
51 });
52 return indices;
53 }
54 }
55}
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)