> For the complete documentation index, see [llms.txt](https://learning.pavey.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learning.pavey.dev/javascript/activities/text-summariser.md).

# Text Summariser

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.&#x20;

Let's get started 🚀


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learning.pavey.dev/javascript/activities/text-summariser.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
