-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
25 lines (21 loc) · 790 Bytes
/
Copy pathhelpers.py
File metadata and controls
25 lines (21 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import re
import hashlib
def clean_text(text: str) -> str:
"""Remove extra whitespace and normalize the text."""
text = re.sub(r'\s+', ' ', text)
return text.strip()
def split_text(text: str, chunk_size: int, overlap: int) -> list:
"""Split text into overlapping chunks for embedding."""
chunks = []
start = 0
while start < len(text):
end = min(len(text), start + chunk_size)
chunks.append(text[start:end])
start += chunk_size - overlap
return chunks
def format_confidence(score: float) -> str:
"""Convert float confidence to readable percentage."""
return f"{round(score * 100, 2)}%"
def get_file_hash(filepath):
with open(filepath, "rb") as f:
return hashlib.md5(f.read()).hexdigest()