How to summarize text in TypeScript without AI
Contents
Intro
All the applications that allow users to create long-form content, such as blog posts or news articles, will likely need summaries of these pieces. It's quite possible to do using a simple TypeScript function without any AI-driven models.
Why approaches without AI?
Because you will need to pay for that AI 💰
If you need something special, you can pay a little money, but if your task is not so important, and you do not mind some inaccuracy, you can use the method described below.
Thing
How the algorithm works:
- Counting Word Frequency: This counts the frequency of each word still left in the text
- Sorting and Returning the Top Words: This orders the words out of their order based on frequency, back in line with returning the most important
Below I will give a couple of additional methods that you can use if you wish.
Stop words (optional)
Add any words here to your taste, you can also add obscene language here to filter the text.
Singular forms (optional)
This remains only singular forms to avoid duplicates (like "book", "books")
The default method that processes text and extracts keywords from it:
By default, it will return next keywords in, development, it, and, javascript but if you add optional methods it will return another set of keywords javascript, development, language, web, and application which fits better, so feel free to tune it for your needs.