nlp manual
import nltk nltk.download('punkt') # Download the punkt tokenizer models for word tokenization def count_lines(file_path): """ This function counts the number of lines in the given text file. """ try: with open(file_path, 'r') as file: lines = file.readlines() return len(lines) except FileNotFoundError: print("File not found. Please check the file path.") return 0 def count_words(file_path): """ This function counts the number of words in the given text file. It uses NLTK's word_tokenize method for accurate word tokenization. """ try: with open(file_path, 'r') as file: text = file.read() words = nltk.word_tokenize(text) # Tokenizes the text into words return len(words) except FileNotFoundError: print("File not found. Please check the file path.") return 0 def main(): file_path = input("Enter the path of the text file: ") # Counting lines line_count = count_lines(file_...