@rtcoder/simple-summary
v1.1.0
Published
Text summarizer using Node.js
Downloads
51
Readme
simple-summary
Extractive text summarization library for Node.js. Automatically selects the most important sentences from a given text using frequency analysis and word clustering.
Installation
npm install @rtcoder/simple-summaryUsage
const summarize = require('@rtcoder/simple-summary');
const text = `The Internet is a global system of interconnected computer networks.
It carries a vast range of information resources and services, such as the World Wide Web.
The origins of the Internet date back to research during the 1960s.
Email is one of the most widely used communication tools on the Internet.`;
const result = summarize(text);
console.log(result);API
summarize(text, [options])
| Parameter | Type | Description |
|-----------|------|-------------|
| text | string | Text to summarize |
| options.n | number | Number of top words used for scoring (default: 100) |
| options.clusterThreshold | number | Max distance between words in a cluster (default: 5) |
Returns a string with the selected sentences joined by newlines. Returns an empty string for invalid or empty input.
Options example
const result = summarize(text, {
n: 50, // consider only top 50 most frequent words
clusterThreshold: 3, // tighter word clusters
});How it works
- Sentence extraction — splits the input into sentences
- Frequency analysis — tokenizes words, removes stop words, counts frequency
- Sentence scoring — for each sentence, finds clusters of important words and scores them based on density:
score = (important_words)² / cluster_length - Filtering — returns sentences scoring above
mean + 0.5 * std_deviation
