• Stars
    star
    769
  • Rank 59,078 (Top 2 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node module that summarizes text using a naive summarization algorithm

node-summary

Summarizes text using a naive summarization algorithm, based off of the Python implementation by shlomibabluki.

Build Status npm version

And now with UTF8 support, thanks to xissy.

The browser?

I've started working on a browser branch which will enable the use of node-summary from Node.js and the browser. All tests are currently passing however I feel like some of the code should be further optimized for the client before I release it.

Algorithm

The algorithm used is explained here. Essentially

This algorithm extracts the key sentence from each paragraph in the text.

Installation

$ npm install node-summary

Examples

var SummaryTool = require('node-summary');

var title = "Swayy is a beautiful new dashboard for discovering and curating online content [Invites]";
var content = "";
content += "Lior Degani, the Co-Founder and head of Marketing of Swayy, pinged me last week when I was in California to tell me about his startup and give me beta access. I heard his pitch and was skeptical. I was also tired, cranky and missing my kids – so my frame of mind wasn't the most positive.\n";
content += "I went into Swayy to check it out, and when it asked for access to my Twitter and permission to tweet from my account, all I could think was, \"If this thing spams my Twitter account I am going to bitch-slap him all over the Internet.\" Fortunately that thought stayed in my head, and not out of my mouth.\n";
content += "One week later, I'm totally addicted to Swayy and glad I said nothing about the spam (it doesn't send out spam tweets but I liked the line too much to not use it for this article). I pinged Lior on Facebook with a request for a beta access code for TNW readers. I also asked how soon can I write about it. It's that good. Seriously. I use every content curation service online. It really is That Good.\n";
content += "What is Swayy? It's like Percolate and LinkedIn recommended articles, mixed with trending keywords for the topics you find interesting, combined with an analytics dashboard that shows the trends of what you do and how people react to it. I like it for the simplicity and accuracy of the content curation.\n";
content += "Everything I'm actually interested in reading is in one place – I don't have to skip from another major tech blog over to Harvard Business Review then hop over to another major tech or business blog. It's all in there. And it has saved me So Much Time\n\n";
content += "After I decided that I trusted the service, I added my Facebook and LinkedIn accounts. The content just got That Much Better. I can share from the service itself, but I generally prefer reading the actual post first – so I end up sharing it from the main link, using Swayy more as a service for discovery.\n";
content += "I'm also finding myself checking out trending keywords more often (more often than never, which is how often I do it on Twitter.com).\n\n\n";
content += "The analytics side isn't as interesting for me right now, but that could be due to the fact that I've barely been online since I came back from the US last weekend. The graphs also haven't given me any particularly special insights as I can't see which post got the actual feedback on the graph side (however there are numbers on the Timeline side.) This is a Beta though, and new features are being added and improved daily. I'm sure this is on the list. As they say, if you aren't launching with something you're embarrassed by, you've waited too long to launch.\n";
content += "It was the suggested content that impressed me the most. The articles really are spot on – which is why I pinged Lior again to ask a few questions:\n";
content += "How do you choose the articles listed on the site? Is there an algorithm involved? And is there any IP?\n";
content += "Yes, we're in the process of filing a patent for it. But basically the system works with a Natural Language Processing Engine. Actually, there are several parts for the content matching, but besides analyzing what topics the articles are talking about, we have machine learning algorithms that match you to the relevant suggested stuff. For example, if you shared an article about Zuck that got a good reaction from your followers, we might offer you another one about Kevin Systrom (just a simple example).\n";
content += "Who came up with the idea for Swayy, and why? And what's your business model?\n";
content += "Our business model is a subscription model for extra social accounts (extra Facebook / Twitter, etc) and team collaboration.\n";
content += "The idea was born from our day-to-day need to be active on social media, look for the best content to share with our followers, grow them, and measure what content works best.\n";
content += "Who is on the team?\n";
content += "Ohad Frankfurt is the CEO, Shlomi Babluki is the CTO and Oz Katz does Product and Engineering, and I [Lior Degani] do Marketing. The four of us are the founders. Oz and I were in 8200 [an elite Israeli army unit] together. Emily Engelson does Community Management and Graphic Design.\n";
content += "If you use Percolate or read LinkedIn's recommended posts I think you'll love Swayy.\n";
content += "Want to try Swayy out without having to wait? Go to this secret URL and enter the promotion code thenextweb . The first 300 people to use the code will get access.\n";
content += "Image credit: Thinkstock";

SummaryTool.summarize(title, content, function(err, summary) {
	if(err) console.log("Something went wrong man!");

	console.log(summary);

	console.log("Original Length " + (title.length + content.length));
	console.log("Summary Length " + summary.length);
	console.log("Summary Ratio: " + (100 - (100 * (summary.length / (title.length + content.length)))));
});


var url = "https://www.forbes.com/sites/viviennedecker/2017/05/14/meet-the-23-year-old-innovating-the-nail-industry-with-static-nails/#4b48c203487d"

SummaryTool.summarizeFromUrl(url, function(err, summary) {
  if(err) {
    console.log("err is ", result)
  }
  else {
    console.log(summary)
  }
})

The output of the first example is:

Swayy is a beautiful new dashboard for discovering and curating online content [Invites]
I like it for the simplicity and accuracy of the content curation.

I can share from the service itself, but I generally prefer reading the actual post first – so I end up sharing it from the main link, using Swayy more as a service for discovery..
The idea was born from our day-to-day need to be active on social media, look for the best content to share with our followers, grow them, and measure what content works best.

Original Length 4364
Summary Length 515
Summary Ratio: 88.19890009165903

The output of the second example is:

Meet the 23-Year-Old Innovating The Nail Industry With Static Nails

"The best part is that these nails are non-damaging to natural nails, they can be customized without damaging the original design, they only take 5 minutes to apply, and can be worn up
to 18 days, or reapplied up to 6 Static Nails.

Static Nails Alexis Irene launched Static Nails on her 21st birthday, and after being in business for one week, she received a call from Kendo, the beauty brand incubator behind
Ole Henriksen and Marc Jacobs Beauty.β€œJames Vincent, a celebrity makeup artist introduced our product to tons of designers, which resulted in us doing lots of New York Fashion Week shows,”Irene said.

Usage

summary.summarize(title, content, function(err, summary) {
	if(err) {
		console.log("There was an error."); // Need better error reporting
	}

	console.log(summary);
});

summary.getSortedSentences(content, 5, function(err, sorted_sentences) {
    if(err) {
        console.log("There was an error."); // Need better error reporting
    }

    console.log(sorted_sentences);
});

summary.summarizeFromUrl(url, function(err, summary) {
  if(err) {
    console.log("err is ", result)
  }
  else {
    console.log(summary)
  }
})

For successively calling both summarize and getSortedSentences, pass in additional dict param to avoid reprocessing the dictionary between calls, like so:

summary.summarize(title, content, function(err, summary, dict) {
  ...
  summary.getSortedSentences(content, 5, function(err, sorted_sentences) {
    ...
  }, dict)
})

Tests

$ npm test

Tests are conducted using mocha and should.

License

MIT - http://jbrooksuk.mit-license.org

More Repositories

1

artisan.page

A bookmarkable, searchable cheatsheet for all of Laravel's default Artisan commands.
Vue
332
star
2

JSON-Airports

A JSON array of Airport names, IATA code and location
253
star
3

laravel-forge-action

Deploy your application to Laravel Forge with GitHub Actions.
Shell
71
star
4

laravel-colorize

A handy set of Stringable mixins for CLI text.
PHP
46
star
5

jQuery-Timer-Plugin

A timer plugin for jQuery
HTML
36
star
6

FlatDeveloperConsole

Google Chrome Developer Console with FlatUI Colors
CSS
32
star
7

Sublime-Evaluate

Selection evaluation in Sublime Text
Python
25
star
8

Sublime-Pebble

Pebble Package for Sublime Text
JavaScript
21
star
9

SoundRain

Evented Node.js module for downloading songs from SoundCloud.
JavaScript
19
star
10

SublimeWebColors

Sublime Text Plugin for CSS Web Colors and expanding hex codes.
Python
14
star
11

Oblivion

A customized Oblivion theme for Sublime Text, originally created by Paolo Borelli.
13
star
12

php-clamp

Clamp one number between a min and max.
PHP
12
star
13

ImprovedSQL

An improved SQL.tmLanguage
9
star
14

Purr

A Pebble watch app that replicates the Durr watch
C
9
star
15

palenight-sublime-text

Palenight Theme for Sublime Text
7
star
16

node-flux

Javascript port of Flux by @selvinortiz
JavaScript
7
star
17

Sublime-Blade

Improved Laravel 5 Blade syntax highlighting for Sublime Text 3
HTML
6
star
18

Leanpub

Leanpub snippets for Sublime Text
6
star
19

node-elo

Elo rating system for Node.js
JavaScript
5
star
20

TabsToTable

Sublime Text plugin which converts tabs to a table format
Python
5
star
21

StripHTML

Strip HTML content from selected text in Sublime Text 3
Python
4
star
22

jQuery-Seven-Segments

A jQuery plugin to create seven segment arrays
JavaScript
3
star
23

Colortip

Python
2
star
24

laravel-demo

Demo application for deploying to Forge.
PHP
2
star
25

jQuery-Contra

Easily create customizable Contra Code style Easter-eggs in your web application.
JavaScript
2
star
26

OctoGhost

Import Octopress posts into Ghost
JavaScript
2
star
27

ColourComplete

Sublime Text Plugin to complete colour names for CSS
Python
2
star
28

Affair

JavaScript events library
JavaScript
2
star
29

iawriter-markdown-sublime

Open your current file with iA Writer editor in Sublime 2/3
Python
2
star
30

Desktoppr

iOS Desktoppr App
Objective-C
2
star
31

atom-oblivion

A customized Oblivion theme for Atom
CSS
2
star
32

discord-notification-channel

Laravel notification channel for Discord
PHP
1
star
33

SublimeFlatColors

Flat UI Colors Auto-complete for Sublime Text
Python
1
star
34

RoR-Newsletter

Newsletter signup built in Ruby on Rails (as a test)
Ruby
1
star
35

swimming-clubs

A collective list of swimming clubs.
1
star
36

OpenInclude

Sublime Text 2 Plugin to open file under cursor
Python
1
star
37

UIColor-Hex

UIColorCategory to create color object from hex values
Objective-C
1
star
38

DCPU16

0x10c DCPU interpreter in PHP
PHP
1
star
39

ActionServerlessPHP

PHP
1
star
40

tweet.new

Say hello to tweet.new, your shortcut to posting faster on X!
1
star