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

nalapa

v1.11.0

Published

Collection of NodeJS NLP Library for Bahasa Indonesia.

Downloads

57

Readme

NALAPA

Collection of NodeJS NLP Library for Bahasa Indonesia.

NPM version Build Status Dependency Status

Installation

Install node modules with npm:

npm install --save nalapa

API

Tokenizer

Tokenizer = require('nalapa').tokenizer;

Tokenizer.tokenize("Hello world, my name is Alice...")
// ['Hello', 'world', ',', 'my', 'name', 'is', 'Alice', '.', '.', '.']

Tokenizer.tokenize("Monday, (1/11). I have 1.000 rupiah.")
// [ 'Monday', ',', '(', '1/11', ')', '.', 'I', 'have', '1.000', 'rupiah', '.' ]

Tokenizer.splitSentence("Hello world, my name is Alice! I live in Bandung. Jakarta kebanjiran gara-gara hujan - tugas kuliah sulit? Baiklah.");
/*
[
  "Hello world, my name is Alice",
  "I live in Bandung",
  "Jakarta kebanjiran gara-gara hujan",
  "tugas kuliah sulit",
  "Baiklah"
]
*/

var text = "Seorang remaja berinisal HAS (15) ditangkap aparat Polres Magelang lantaran diduga ..."
Tokenizer.getQuotations(text);
/*
[
  "\"Mereka beraksi siang hari, sekitar pukul 13.00 WIB akhir pekan lalu. Saat itu korban terlihat sendirian,\" kata Zain dalam gelar perkara, Selasa (16/2/2016).", 
  "\"Korban mengenali ponsel yang dipegang saksi adalah miliknya, baru kemudian ia melapor ke Polsek Kajoran. Saksi tersebut mengatakan kalau ponsel tersebut dibeli dari tetangga seharga Rp 250.000,\" papar mantan Kapolsek Metro Tamansari, Jakarta itu.", 
  "\"Kami masih koordinasi dengan pihak terkait apakah pelaku HAS ini akan menjalani diversi atau tidak,\" katanya.", 
  "\"Ponselnya saya jual lagi, uangnya buat bantu mertua yang mau nikah lagi. Saya dulu sales di Sumatera tapi sekarang nganggur,\" ucap bapak dari dua anak ini."
]
*/

Word

Word = require('nalapa').word;

// stopword
word.isStopword("adalah") // true
word.isStopword("Indonesia") // false

// basic word properties
word.isBasicWord('masak')  // true
word.isAdjective('abadi')  // true
word.isAdverb('adakala')  // true
word.isNum('wahid')  // true
word.isPre('adapun')  // true
word.isPron('aku')  // true
word.isVerb('ambil')  // true
word.isBasicWord('wrongxxx') // false

// stemming
word.stem('memberikan') // beri
word.stem('meong') // meong

// stemming for prefix, suffix, or confix
word.stemPrefix('penyadap') // sadap
word.stemSuffix('minuman') // minum
word.stemConfix('memberikan') // beri

Cleaner

Cleaner = require('nalapa').cleaner;

Cleaner.isASCII("abc123");      /* true */
Cleaner.isASCII("abc_-8+");     /* true */
Cleaner.isASCII("ابت");         /* false */

Cleaner.isAlphaNumeric("abc123");       /* true */
Cleaner.isAlphaNumeric("abc_-8+");      /* false */
Cleaner.isAlphaNumeric("ابت");          /* false */

Cleaner.removeNonASCII("abc123");       /* "abc123" */
Cleaner.removeNonASCII("abc_-8+");      /* "abc_-8+" */
Cleaner.removeNonASCII("ابت");          /* "" */

Cleaner.removeNonAlphaNumeric("abc123");        /* abc123 */
Cleaner.removeNonAlphaNumeric("abc_-8+");       /* abc8 */
Cleaner.removeNonAlphaNumeric("ابت");           /* "" */

Cleaner.removeHTMLTags("<p class="long">some long paragraph</p>");          /* "some long paragraph" */

BIO Label

BIOLabel = require('nalapa').BIOLabel;

var data = {
  text : 'i eat nasi goreng for breakfast, lunch, and dinner',
  labels : [
    { label : 'food', words : ['nasi goreng'] }
  ]
}

BIOLabel.label(data);
/*
{
  tokens : ['i', 'eat', 'nasi', 'goreng', 'for', 'breakfast', ',', 'lunch', ',', 'and', 'dinner'],
  labels : [['other'], ['other'], ['b_food'], ['i_food'], ['other'], ['other'], ['other'], ['other'], ['other'], ['other'], ['other']]
}
*/ 

var data2 = {
  text : 'i eat nasi goreng at midnight too',
  labels : [
    { label : 'who', words : ['i'] },
    { label : 'what', words : ['i eat nasi goreng'] }
  ]
}

BIOLabel.label(data2);
/*
{
  tokens : ['i', 'eat', 'nasi', 'goreng', 'at', 'midnight', 'too'],
  labels : [['b_who', 'b_what'], ['i_what'], ['i_what'], ['i_what'], ['other'], ['other'], ['other']]
}
*/

var data3 = {
  text : 'if you are reading this, you are reading this',
  labels : [
    { label : 'person', words : ['you'] },
    { label : 'activity', words : ['you are reading'] }
  ]
}

BIOLabel.label(data3);
/*
{ 
  tokens: ['if', 'you', 'are', 'reading', 'this', ',', 'you', 'are', 'reading', 'this'],
  labels: [['other'], ['b_person', 'b_activity'], ['i_activity'], ['i_activity'], ['other'], ['other'], ['b_person', 'b_activity'], ['i_activity'], ['i_activity'], ['other']]
}
*/

var data4 = {
  text : 'friday, saturday, and sunday morning',
  labels : [
    { label : 'day_name', words : ['friday', 'saturday', 'sunday'] },
    { label : 'time', words : ['sunday morning'] }
  ]
}

BIOLabel.label(data4);
/*
{
  tokens : [ 'friday', ',', 'saturday', ',', 'and', 'sunday', 'morning' ],
  labels : [ ['b_day_name'], ['other'], ['b_day_name'], ['other'], ['other'], ['b_day_name', 'b_time'], ['i_time'] ]
}
*/

// get label from sequence of BIOLabel
var tags = [['other', 'other', 'b_food', 'i_food', 'other', 'other', 'other', 'other', 'other', 'other', 'other'], ['b_action', 'i_action', 'i_action', 'i_action', 'other', 'other', 'other']]
var tokens = [['i', 'eat', 'nasi', 'goreng', 'for', 'breakfast', ',', 'lunch', ',', 'and', 'dinner'], ['i', 'eat', 'nasi', 'goreng', 'at', 'midnight', 'too']]
BIOLabel.getLabelFromSequence(tags, tokens)
/*
{ 
  food: [ 'nasi goreng' ],
  action: [ 'i eat nasi goreng' ]
}
*/

Feature

feature = require('nalapa').feature;

feature.isEquals('hehe', 'hehe') // true
feature.isEquals('hehe', 'hoho') // false

feature.isAllCapital('ABCD') // true
feature.isAllCapital('Abcd') // false

feature.isBeginsWithCapital('ABc') // true
feature.isBeginsWithCapital('aBC') // false

feature.isContainsNumber('he1he') // true
feature.isContainsNumber('hehe') // false

feature.isContainsYear('1985haihai') // true
feature.isContainsYear('hoho') // false
feature.isContainsYear('666') // false

feature.isRomanNumber('MCMXCII') // true
feature.isRomanNumber('MCMXCIIPOPO') // false

feature.isContainsNonAlphanumeric('abc') // false
feature.isContainsNonAlphanumeric('@bc') // true

feature.isContainsPunctuation('abcd;') // true
feature.isContainsPunctuation(';') // true
feature.isContainsPunctuation('abcd') // false

Testing

From the repo root:

npm test

License

MIT © Ananta Pandu