The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a Python script to summarize your daily journal

Here’s a Python script that summarizes a daily journal by extracting the main ideas using basic natural language processing. It uses the nltk library for tokenization and sentence scoring based on word frequency.

python
import nltk from nltk.tokenize import sent_tokenize, word_tokenize from nltk.corpus import stopwords import string # Download necessary NLTK resources nltk.download('punkt') nltk.download('stopwords') def summarize_journal(journal_text, summary_sent_count=3): # Tokenize text into sentences and words sentences = sent_tokenize(journal_text) words = word_tokenize(journal_text.lower()) # Remove stopwords and punctuation stop_words = set(stopwords.words('english')) words = [word for word in words if word not in stop_words and word not in string.punctuation] # Calculate word frequency word_freq = {} for word in words: if word not in word_freq: word_freq[word] = 1 else: word_freq[word] += 1 # Score each sentence based on word frequency sentence_scores = {} for sentence in sentences: for word in word_tokenize(sentence.lower()): if word in word_freq: if sentence not in sentence_scores: sentence_scores[sentence] = word_freq[word] else: sentence_scores[sentence] += word_freq[word] # Sort sentences by score and return the top ones summarized_sentences = sorted(sentence_scores, key=sentence_scores.get, reverse=True)[:summary_sent_count] summary = ' '.join(summarized_sentences) return summary # Example usage if __name__ == "__main__": journal_input = """ Today was a productive day. I woke up early and went for a run. It felt refreshing to get some fresh air before breakfast. Work was busy, but I managed to complete my tasks ahead of time. In the afternoon, I had a meeting with the team to discuss our upcoming project. The ideas we shared were exciting, and I’m looking forward to what we’ll accomplish. I also took time to read a few chapters of a book I’ve been enjoying. Overall, I feel satisfied and optimistic about tomorrow. """ print("Journal Summary:") print(summarize_journal(journal_input))

Key Features:

  • Tokenizes the input journal text.

  • Removes common stopwords and punctuation.

  • Scores sentences based on the frequency of important words.

  • Returns the top N sentences as a summary (default is 3).

This script works well for straightforward journals and can be extended with advanced NLP libraries like spaCy or transformers for better accuracy.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About