GithubHelp home page GithubHelp logo

tokenizer.js's Introduction

tokenizer.js

A tokenizer written for JavaScript NLP applications

How to install

npm install tokenizer.js

How to declare

import { Tokenizer } from 'tokenizer.js'; // ES6
const Tokenizer = require('tokenizer.js') // Node.js
// Declare a new object
let tokenizer = new Tokenizer(array_of_sentences)
// From JSON
let tokenizer = new Tokenizer()
tokenizer.fromJSON('./path/to/index.json')

How to use

// Returns index generated (e.g. { 'word1': 0, 'word2': 1, 'word3': 3 }).
tokenizer.index;
// Creates new index and overwrites current index.
tokenizer.create(array_of_senteces);
// Check if word exists in index.
tokenizer.exists('example');
// Takes string or number as argument, if string, returns the corresponding number. If number, returns number.
tokenizer.find('word'); tokenizer.find(5);
/* Adds word sttring to index and returns corresponding number. If word exists, returns false
Numbers are assigned incrementally unless any entries were previously removed, 
if so, it takes a number from the empty_slots buffer. 
The empty_slots buffer is stored in tokenizer.index.empty_slots */
tokenizer.add('word');
// Removes word entry and stores its number in the empty_slots buffer.
tokenizer.remove('word');
// Sorts index in ascending order by value, takes no arguments.
tokenizer.sort();
// Returns the length of the index, takes no arguments.
tokenizer.indexLength();
// Encodes a string sentence and returns an array of numbers.
tokenizer.encode("this is a sentence"); // -> [223, 554, 420, 73]
// Decodes an array of numbers and returns a string sentence.
tokenizer.decode([223, 554, 420, 73]); // -> "this is a sentence"
// Exports the index to a JSON (.json) file, takes path to file as argument (default: './index.json').
tokenizer.toJSON('./path/to/file.json');
// Imports an index from a JSON (.json) file, takes path to file as argument (default: './index.json').
tokenizer.fromJSON('./path/to/index.json');

tokenizer.js's People

Contributors

alexantoniades avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.