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

headline-parser

v1.0.0

Published

Determines the most relevant keywords from an article headline

Downloads

6

Readme

headline-parser

A simple NPM package that determines the most relevant keywords in a headline by considering article context.

Installation

$ npm install headline-parser

Use the --save flag to include the module in your package.json

Usage

Require the parser

var headline_parser = require("headline-parser");

// Declare variables for your headline and article summary. These have been edited to provide a good example.

var headline = 'China successfully develops drone defense system';

var 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
var important_keywords = headline_parser.findKeywords(headline, body, 3);

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

Arguments

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

.findKeywords(headline, body [, n][, args]);

| Argument name | Description | Permitted values | |---------------|-------------|------------------| | headline| Headline of article | String| | 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.| String| | (optional) n | Number of top keywords desired. If left out, the parser will return all keywords sorted by relevance. | Integer | | (optional) args | Takes an object containing parameters for the keyword-extractor module used to pull keywords from the headline. Default is {language:"english", return_changed_case:true} | Object (see docs)|

Running tests

Install the development dependencies by running the following command:

$ npm install

To run tests:

$ npm test

How does it work?

It's pretty simple. This parser uses the keyword-extractor module to obtain keywords from a headline (all non-stopwords), then sorts those words by how many times each word appears in the article body provided. For example, this is a great tool to use with the Twitter API if you plan to search or stream tweets that relate to a specific news article.

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. Additionally, unless the args object is supplied with a return_changed_case: false parameter, the module will count only the lowercase appearances of the word.