stopword
stopword
is a module for node and the browser that allows you to strip stopwords from an
input text. In natural language processing, "Stopwords" are words
that are so frequent that they can safely be removed from a text
without altering its
meaning.
Demo
Live stopword browser demo.
Usage
Node.js
sw = require('stopword')
Script tag method
<script src="stopword.js"></script>
<script>
</script>
Default (English)
By default, stopword
will strip an array of "meaningless" English words
sw = require('stopword')
const oldString = 'a really Interesting string with some words'.split(' ')
const newString = sw.removeStopwords(oldString)
Other languages
You can also specify a language other than English:
sw = require('stopword')
const oldString = 'Trädgårdsägare är beredda att pröva vad som helst för att bli av med de hatade mördarsniglarna åäö'.split(' ')
const newString = sw.removeStopwords(oldString, sw.sv)
Custom list of stopwords
And last, but not least, it is possible to use your own, custom list of stopwords:
sw = require('stopword')
const oldString = 'you can even roll your own custom stopword list'.split(' ')
const newString = sw.removeStopwords(oldString, [ 'even', 'a', 'custom', 'stopword', 'list', 'is', 'possible']
API
removeStopwords
Returns an Array that represents the text with the specified stopwords removed.
text
An array of wordsstopwords
An array of stopwords
sw = require('stopword')
var text = sw.removeStopwords(text[, stopwords])
<language code>
Arrays of stopwords for the following 32 languages are supplied:
af
- Afrikaansar
- Modern Standard Arabicbn
- Bengalibr
- Brazilian Portugueseda
- Danishde
- Germanen
- Englishes
- Spanishfa
- Farsifi
- Finnishfr
- Frenchha
- Hausahe
- Hebrewhi
- Hindiid
- Indonesianit
- Italianja
- Japaneselgg
- Lugbara (without diacritics)lggo
- Lugbara official (with diacritics)nl
- Dutchno
- Norwegianpl
- Polishpt
- Portuguesepa
- Punjabi Gurmukhiru
- Russianso
- Somalist
- Sothosv
- Swedishsw
- Swahilivi
- Vietnameseyo
- Yorubazh
- Chinese Simplifiedzu
- Zulu
sw = require('stopword')
norwegianStopwords = sw.no
Languages with no space between words
ja
Japanese and zh
Chinese Simplified have no space between words. For these languages you need to split the text into words before feeding it to the stopword
module. You can check out TinySegmenter for Japanese and chinese-tokenizer for Chinese.
Your language missing?
If you can't find a stopword file for your language, you can try creating one with stopword-trainer
. We're happy to help you in the process.