npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eklem-headline-parser

v4.0.3

Published

Determines the most relevant keywords from an article headline

Downloads

56

Readme

eklem-headline-parser

Determines the most relevant keywords in a headline by considering article context. Works for Node.js and the browser. Started as a forked version of TessMyers headline-parser.

NPM version NPM downloads Build Status JavaScript Style Guide MIT License

Breaking change

API on importing CJS- and ESM-script changed.

Demo

Browser demo screenshot Check out the browser demo or have a look at the demo source files.

Usage

Common JS

const { findKeywords } = require('eklem-headline-parser')
// findKeywords(headline, body [, cutoff]) now available

ES Modules

import { findKeywords } from 'eklem-headline-parser'
// findKeywords(headline, body [, cutoff]) now available

UMD - Script tag method

<script src="https://cdn.jsdelivr.net/npm/eklem-headline-parser/dist/eklem-headline-parser.umd.min.js"></script>
<script>
// ehp.findKeywords(headline, body [, cutoff]) now available
</script>

Remove noise

To skip all words with little or no meaning, use a stopword stripping library, i.e. stopword.

<script src="headline-parser.js"></script>
<script src="stopword.js"></script>
<script>
// ehp.findKeywords(sw.removeStopwords(headline), body [, cutoff])
</script>

Calculating some keywords

const headlineParser = require('eklem-headline-parser')
const sw = require('stopword')

// Declare variables for your headline and article summary. These have been edited to provide a good example.
let headline = 'China successfully develops drone defense system'

let body = 'China has tested a self-developed laser defense system against small-scale low-altitude drones, state media said on Sunday. Reportedly, the drone defense is designed to destroy small-scale drones flying within an altitude of 500 meters and at speeds below 50 meters per second. In addition to the drone network, china has developed stealth jets and has built one aircraft carrier.'

// Find the most relevant keywords in the headline, sorted by number of appearances in the body text
let important_keywords = headline_parser.findKeywords(sw.removeStopwords(headline.split(' ')), body.split(' '), 3);

// => Returns the top three occuring words [ 'drone', 'defence', 'China' ], with 'drone' appearing most often.

API

findKeywords() accepts four arguments, of which the last two are optional.

.findKeywords(headline, body [, cutoff]);

| Argument name | Description | Permitted values | |---------------|-------------|------------------| | headline| Headline of article | Array| | body | Context from the article. May be the entire article body, or just a few sample sentences. The more context, the greater the accuracy of the parser.| Array| | (optional) cutoff | Number of top keywords desired. If left out, the parser will return all keywords sorted by relevance. | Integer |

How does it work?

It's pretty simple. The parser will count how many times a word in a title is repeated in a body text and then sorts those words by how many times each word appears in the article body provided.

The parser is language agnostic, but for better accuracy, you should use the stopword module to obtain only the words that are not stopwords. For this to happen, you need to define which langauge is used in the text analyzed.

Some things to note: The module will not count partial appearances of keywords, or compounded keywords. For instance, if one of your headline keywords is ['china'], then neither "China", "china's" or "Indochina" will be counted as an appearance of that keyword.