Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refactor normalize_case function in utils.py #204

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
25 changes: 2 additions & 23 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jwt
import hashlib
import json
import nltk
from typing import Literal
from loguru import logger
from passlib.context import CryptContext
Expand All @@ -12,7 +11,6 @@
from app.models import User


nltk.download('punkt_tab')
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


Expand Down Expand Up @@ -141,24 +139,5 @@ def read_timestamp(timestamp: int, output_format=Literal['date','datetime']) ->
raise ValueError("Invalid format")

def normalize_case(text):
if not text:
return None

processed_lines = []
for line in text.splitlines():
pre_symbol = ''
if line.startswith('#'):
pre_symbol = '#'
line = line[1:]
if line.startswith('-'):
pre_symbol = '-'
line = line[1:]
line = line.strip()

sentences = nltk.tokenize.sent_tokenize(line)
normalized_sentences = [sentence.capitalize() for sentence in sentences]
normalized_text = pre_symbol + ' ' + ' '.join(normalized_sentences)

processed_lines.append(normalized_text)

return '\n'.join(processed_lines)
# TODO
return text
Loading