JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q22985F
  • License ISC

:robot: Natural language processing with Javascript

Package Exports

  • classifier.js
  • classifier.js/dist/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (classifier.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

classifier.js

Open Source Love version PRs Welcome CD

🤖 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')