Code Monkey home page Code Monkey logo

cld3-asm's Introduction

Build Status Build status codecov npm node Greenkeeper badge

cld3-asm

cld3-asm is isomorphic javascript binding to google's compact language detector v3 based on WebAssembly cld3 binary. This module aims to provide thin, lightweight interface to cld3 without requiring native modules.

Install

npm install cld3-asm

Usage

Loading module asynchronously

cld3-asm relies on wasm binary (or asm.js where wasm is not supported) of cld3, which need to be initialized first.

import { loadModule } from 'cld3-asm';

const cldFactory = await loadModule();

loadModule loads wasm binary, initialize it, and returns factory function to create instance of cld3 language identifier.

loadModule(binaryEndpoint?: string, environment?: ENVIRONMENT): Promise<CldFactory>

It accepts binaryEndpoint as optional parameter for mainly browser environment. Unlike node, browser can't access wasm / asm binary directly in filesystem but have to fetch. Provide endpoints for paths to dist/src/lib/**/*.(wasm|mem) and it'll be fetched runtime. On node, this endpoint can be used to override physical path to binaries.

Additionally it accepts environment as well, allow to set running environment and ignores internal runtime detection. This is mostly for Electron's renderer process where node.js and fetch are available both, to selectively opt-in which way to use. It is important to note loadModule doesn't interop incorrect option value matching, like try to load correct binary when supply endpoint to file path with set env to browser.

Creating language identifier

create(minBytes?: number, maxBytes?: number): LanguageIdentifier

LanguageIdentifier exposes minimal interfaces to cld3's NNetLanguageIdentifier.

  • findLanguage(text: string): Readonly<LanguageResult> : Finds the most likely language for the given text.
  • findMostFrequentLanguages(text: string, numLangs: number): Array<Readonly<LanguageResult>> : Splits the input text into spans based on the script, predicts a language for each span, and returns a vector storing the top num_langs most frequent languages
  • dispose(): void : Destroy current instance of language identifier. It is important to note created instance will not be destroyed automatically.

There are simple examples for each environments. In each example directory do npm install && npm start.

Building / Testing

Few npm scripts are supported for build / test code.

  • build: Transpiles code to ES5 commonjs to dist.
  • test: Run cld / cld3-asm test both. Does not require build before execute test.
  • test:cld: Run integration test for actual cld3 wasm binary, using cld's test case.
  • test:cld3-asm: Run unit test against cld3-asm interface
  • lint: Run lint over all codebases
  • lint:staged: Run lint only for staged changes. This'll be executed automatically with precommit hook.
  • commit: Commit wizard to write commit message

License

cld3-asm's People

Contributors

kwonoj avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar  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.