Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions embedding/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,23 @@ def read_pdf_file(file_path: str) -> str:
def split_text_into_sentences(text: str, language: str) -> list[str]:
"""
Splits the given text into a list of sentences using NLTK's sentence tokenizer.

Args:
text (str): The input text to split into sentences.
language (str): The language of the text for the sentence tokenizer

Returns:
list[str]: A list of sentences.
"""
sentences = nltk.sent_tokenize(text, language=language)
return sentences
try:
# Try to load the standard tokenizer which we know works
from nltk.tokenize.punkt import PunktSentenceTokenizer
tokenizer = PunktSentenceTokenizer()
sentences = tokenizer.tokenize(text)
return sentences
except:
# Fallback to the simple case
return nltk.sent_tokenize(text)


def chunk_sentences(sentences: list[str], chunk_size: int, overlap_size: int) -> list[str]:
Expand Down Expand Up @@ -111,7 +118,4 @@ def chunk_sentences(sentences: list[str], chunk_size: int, overlap_size: int) ->