Text Summariser

In this activity we will look at writing a basic text summariser using JavaScript

The goal of this activity is to create a script which will accept a block of text as input and summarise the text based on our algorithm. The algorithm that we will use to do this is outlined below:

  1. Break our text into sentences

  2. Break out sentences into words

  3. filter out stopwords (a starter list of stopwords will be provided)

  4. normalise the words

    1. remove any punctuation

    2. make everything lowercase

  5. index how many instances of each word we have

  6. iterate through the sentences

    1. assign each sentence a base score according to how early it appears in the text (earlier sentences are weighted higher)

    2. add to the base score according to the cumulative scores of all of the words in the sentence (we will use our index for this)

    3. store the sentence and its score

  7. fetch the 5 highest scoring sentences

  8. display them

This basic algorithm will provide us with a summary of the input text based on how frequently words in the sentence appeared, and how early the sentence occurred.

Let's get started 🚀