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

node-opennlp

v0.0.1

Published

Fork of opennlp, Apache OpenNLP wrapper for Node.

Downloads

9

Readme

node-opennlp

NOTE: This project is a fork of Node-OpenNLP by @mbejda. The fork was created to fix version related errors and to migrate it to modern ECMAScript syntax.

OpenNLP 1.6.0 Wrapper For Node.js

node-opennlp relies on java npm module, and interfaces with Apache-OpenNLP using that.

Installation

npm install node-opennlp --save

Node-OpenNLP comes with Apache OpenNLP 1.6.0 along with the following trained 1.5 series models:

  • en-chunker.bin
  • en-ner-person.bin
  • en-pos-maxent.bin
  • en-sent.bin
  • en-token.bin

More trained models can be found here

Sentence Detector

The OpenNLP Sentence Detector can detect that a punctuation character marks the end of a sentence or not. In this sense a sentence is defined as the longest white space trimmed character sequence between two punctuation marks.

var openNLP = require("opennlp");
var sentence = 'Pierre Vinken , 61 years old , will join the board as a nonexecutive director Nov. 29 .';
var sentenceDetector = new openNLP().sentenceDetector;
sentenceDetector.sentDetect(sentence, function(err, results) {
  /// To get probabilities
    sentenceDetector.probs(function(error,probability){
      console.log(error,probability)
    })
	console.log(results)
});

Configurations

The following default configurations can be overrided during initialization.

var openNLP = require("opennlp");
var opennlp = new openNLP({
    models : {
        doccat:__dirname + '/models/en-doccat.bin',
        posTagger: __dirname + '/models/en-pos-maxent.bin',
        tokenizer: __dirname + '/models/en-token.bin',
        nameFinder: __dirname + '/models/en-ner-person.bin',
        sentenceDetector: __dirname + '/models/en-sent.bin',
        chunker: __dirname + '/models/en-chunker.bin'
    },
    openNLP = {
        jar: __dirname + "/lib/opennlp-tools-1.6.0.jar"
    }
});

Tokenizer

The OpenNLP Tokenizers segment an input character sequence into tokens. Tokens are usually words, punctuation, numbers, etc.

var openNLP = require("opennlp");
var sentence = 'Pierre Vinken , 61 years old , will join the board as a nonexecutive director Nov. 29 .';
var tokenizer = new openNLP().tokenizer;
tokenizer.tokenize(sentence, function(err, results) {
    console.log(err, results);
    tokenizer.getTokenProbabilities(function(error, response) {
            console.log(error, response
            });
    });
})

Name Finder

The Name Finder can detect named entities and numbers in text. To be able to detect entities the Name Finder needs a model. The model is dependent on the language and entity type it was trained for.

var openNLP = require("opennlp");
var sentence = 'Pierre Vinken , 61 years old , will join the board as a nonexecutive director Nov. 29 .';
var nameFinder = new openNLP().nameFinder;
nameFinder.find(sentence, function(err, tokens_arr) {
    console.log(err, tokens_arr)
    nameFinder.probs(function(error, response) {
        console.log(error, response)
    });
});

Document Categorizer

The OpenNLP Document Categorizer can classify text into pre-defined categories. It is based on maximum entropy framework.

** To use the document categorizer you need to train a model first. The default trained model that is included is for testing purposes only. **

var openNLP = require("opennlp");
var doccat = new openNLP().doccat;
doccat.categorize("I enjoyed watching Rocky", function(err, list) {
    doccat.getAllResults(list, function(err, category) {
    });
    doccat.getBestCategory(list, function(err, category) {
    });
});
doccat.scoreMap("I enjoyed watching Rocky", function(err, category) {
});
doccat.sortedScoreMap("I enjoyed watching Rocky", function(err, category) {
});
doccat.getCategory(1, function(err, category) {
});
doccat.getIndex('Happy', function(err, index) {
});

Part-of-Speech Tagger

The Part of Speech Tagger marks tokens with their corresponding word type based on the token itself and the context of the token. A token might have multiple pos tags depending on the token and the context. The OpenNLP POS Tagger uses a probability model to predict the correct pos tag out of the tag set.

var openNLP = require("opennlp");
var posTagger = new openNLP().posTagger;
var sentence = 'Pierre Vinken , 61 years old , will join the board as a nonexecutive director Nov. 29 .';
posTagger.tag(sentence, function(err, tokens_arr) {
    console.log(err, tokens_arr)
});
posTagger.topKSequences(sentence, function(error, tagger) {
    console.log(tagger.getScore())
    console.log(tagger.getProbs())
    console.log(tagger.getOutcomes())
});

Chunker

Text chunking consists of dividing a text in syntactically correlated parts of words, like noun groups, verb groups, but does not specify their internal structure, nor their role in the main sentence.

var openNLP = require("opennlp");
var posTagger = new openNLP().posTagger;
var sentence = 'Pierre Vinken , 61 years old , will join the board as a nonexecutive director Nov. 29 .';
var chunker = new openNLP().chunker;
posTagger.tag(sentence, function(err, tokens_arr) {
    chunker.topKSequences(sentence, tokens_arr, function(err, tokens_arr) {
      console.log(err, tokens_arr)
    });
    chunker.chunk(sentence, tokens_arr, function(err, tokens_arr) {
        chunker.probs(function(error, prob) {

        });
    });
});

NPM