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

classifier.js

v2.0.0

Published

:robot: Natural language processing with Javascript

Downloads

486

Readme

classifier.js

Open Source Love version PRs Welcome CD

:robot: An library for natural language processing with JavaScript

Table of Contents

Instalation

npm i classifier.js
# or
yarn add classifier.js

Example of use

import { Classifier } from 'classifier.js'

const classifier = new Classifier({ percentualReturn: true })

classifier.learn('I like cats', ['animal'])
classifier.learn('Cats are cool', ['animal'])
classifier.learn('Dogs are noisy', ['animal'])
classifier.learn('I love animals', ['animal'])
classifier.learn('I like my horse', ['animal'])
classifier.learn('Chocolate is good', ['food'])
classifier.learn('I eat apple', ['food'])
classifier.learn('Juice is very good', ['food'])
classifier.learn('Brazilians eat rice and beans', ['food'])
classifier.learn('Bananas are good for health', ['food'])

classifier.classify('Apple juice is awesome')
// OUTPUT: { unknown: '20%', animal: '0%', food: '80%' }

Auto detection of numeric strings shape

import { Classifier } from 'classifier.js'

const classifier = new Classifier({ percentualReturn: true })

classifier.learn('000.000.000-11', ['cpf'])
classifier.learn('00.000.000/0001-00', ['cnpj'])
classifier.learn('00155-333', ['zipcode'])

classifier.classify('999.999.999-99')
// OUTPUT: { unknown: '0%', cpf: '100%', cnpj: '0%', zipcode: '0%' }
classifier.classify('99.999.999/9999-99')
// OUTPUT: { unknown: '0%', cpf: '0%', cnpj: '100%', zipcode: '0%' }
classifier.classify('99999-999')
// OUTPUT: { unknown: '0%', cpf: '0%', cnpj: '0%', zipcode: '100%' }

API

learn

Receive data with an array of related categories.

classifier.learn('Your sentence', ['your-category'])

classify

Classify a sentence based on received data.

classifier.classify('Sentence to classify')

resetKnowledge

Removes all that was learned.

classifier.resetKnowledge()

toJSON

Saves classifier data to a JSON file that can be imported later.

classifier.toJSON('myFolder/savedClassifier.json')
# Or simply
classifier.toJSON('savedClassifier.json')

fromJSON

Imports data from a JSON file.

classifier.fromJSON('myFolder/savedClassifier.json')
# Or simply
classifier.fromJSON('savedClassifier.json')

toYAML

Saves classifier data to an YAML file that can be imported later.

classifier.toYAML('myFolder/savedClassifier.yaml')
# Or simply
classifier.toYAML('savedClassifier.yaml')

fromYAML

Imports data from an YAML file.

classifier.toYAML('myFolder/savedClassifier.yaml')
# Or simply
classifier.toYAML('savedClassifier.yaml')