Spaces:
Runtime error
Runtime error
File size: 829 Bytes
b77e4f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
'''
Utility functions for the Climate Change Radio Script Generator
'''
import nltk
import string
# Download the necessary NLTK data
nltk.download('punkt')
# Function to clean the generated paragraph
def clean_paragraph(entry):
paragraphs = entry.split('\n')
for i in range(len(paragraphs)):
split_sentences = nltk.tokenize.sent_tokenize(paragraphs[i], language='english')
if i == len(paragraphs) - 1 and split_sentences[:1][-1] not in string.punctuation:
paragraphs[i] = " ".join(split_sentences[:-1])
return capitalize_first_char("\n".join(paragraphs))
# Function to capitalize the first character of a string
def capitalize_first_char(entry):
for i in range(len(entry)):
if entry[i].isalpha():
return entry[:i] + entry[i].upper() + entry[i + 1:]
return entry |