Need help with retext-keywords?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

244 Stars 28 Forks MIT License 153 Commits 1 Opened issues


plugin to extract keywords and key-phrases

Services available


Need anything else?

Contributors list


Build Coverage Downloads Size Sponsors Backers Chat

retext plugin to extract keywords and key-phrases.



npm install retext-keywords


Say we have the following file,

, with the first four paragraphs on term Extraction from Wikipedia:
Terminology mining, term extraction, term recognition, or glossary extraction, is a subtask of information extraction. The goal of terminology extraction is to automatically extract relevant terms from a given corpus.

In the semantic web era, a growing number of communities and networked enterprises started to access and interoperate through the internet. Modeling these communities and their information needs is important for several web applications, like topic-driven web crawlers, web services, recommender systems, etc. The development of terminology extraction is essential to the language industry.

One of the first steps to model the knowledge domain of a virtual community is to collect a vocabulary of domain-relevant terms, constituting the linguistic surface manifestation of domain concepts. Several methods to automatically extract technical terms from domain-specific document warehouses have been described in the literature.

Typically, approaches to automatic term extraction make use of linguistic processors (part of speech tagging, phrase chunking) to extract terminological candidates, i.e. syntactically plausible terminological noun phrases, NPs (e.g. compounds "credit card", adjective-NPs "local tourist information office", and prepositional-NPs "board of directors" - in English, the first two constructs are the most frequent). Terminological entries are then filtered from the candidate list using statistical and machine learning methods. Once filtered, because of their low ambiguity and high specificity, these terms are particularly useful for conceptualizing a knowledge domain or for supporting the creation of a domain ontology. Furthermore, terminology extraction is a very useful starting point for semantic similarity, knowledge management, human translation and machine translation, etc.

…and our script,

, looks as follows:
var vfile = require('to-vfile')
var retext = require('retext')
var pos = require('retext-pos')
var keywords = require('retext-keywords')
var toString = require('nlcst-to-string')

retext() .use(pos) // Make sure to use retext-pos before retext-keywords. .use(keywords) .process(vfile.readSync('example.txt'), done)

function done(err, file) { if (err) throw err

console.log('Keywords:') { console.log(toString(keyword.matches[0].node)) })

console.log() console.log('Key-phrases:') { console.log(phrase.matches[0]'')) function stringify(value) { return toString(value) } }) }

Now, running

node example

Key-phrases: terminology extraction terms term extraction knowledge domain communities


retext().use(keywords[, options])

Extract keywords and key-phrases from the document.

The results are stored on
: keywords at
and key-phrases at
. Both are lists.

A single keyword looks as follows:

  stem: 'term',
  score: 1,
  matches: [
    {node: Node, index: 5, parent: Node},
    // …
  // …

…and a key-phrase:

  score: 1,
  weight: 11,
  stems: ['terminolog', 'extract'],
  value: 'terminolog extract',
  matches:  [
    {nodes: [Node, Node, Node], parent: Node},
    // …

Try to detect at most

, default:

Note that actual counts may differ. For example, when two words have the same score, both will be returned. Or when too few words exist, less will be returned. the same goes for phrases.


for ways to get started. See
for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.