def_split_document(self,text:str)->list[str]:iftext=="":return[]defsplit_text_by_period(text:str)->list[str]:segments:list[str]=[]start:int=0formatchinself._PERIOD_PAT.finditer(text):end:int=match.end()segments.append(text[start:end])start=endifstart<len(text):segments.append(text[start:])return[segment.strip()forsegmentinsegments]sentences:list[str]=[]forlineintext.split("\n"):# Split by periodssentence_candidates:list[str]=split_text_by_period(line)# Merge sentence candidates so that strings in parentheses or brackets are not splitparenthesis_level:int=0hook_bracket_level:int=0double_hook_bracket_level:int=0sentence:str=""whilesentence_candidates:sentence_candidate:str=sentence_candidates.pop(0)sentence+=sentence_candidateparenthesis_level+=sentence_candidate.count("(")-sentence_candidate.count(")")parenthesis_level+=sentence_candidate.count("(")-sentence_candidate.count(")")hook_bracket_level+=sentence_candidate.count("「")-sentence_candidate.count("」")double_hook_bracket_level+=sentence_candidate.count("『")-sentence_candidate.count("』")ifparenthesis_level==hook_bracket_level==double_hook_bracket_level==0:ifsentence.strip():sentences.append(sentence.strip())sentence=""ifsentence.strip():sentences.extend(split_text_by_period(sentence.strip()))returnsentences