This folder contains webassembly make file for Bling Fire. This is work in progress and we likely to change the files. Help needed!
The web assembly and JS code implement the following functions:
- TextToSentences -- breaks JS string into sentences using default model
- TextToWords -- breaks JS string into NLTK style tokens using default model
- async LoadModel -- given a URL fetches it and loads a model, returns a handle to the loaded model
- FreeModel -- destroys model object given a model handle
- TextToIds -- given a model handle and a JS string returns an array of ids of int type
- WordHyphenation -- given a model handle and a word as a JS string and an optional hyphenation unicode code returns a hyphenated word
Note: we have tesed this on Linux only, however after compiled it suppose to work on any platform.
- git clone https://github.com/emscripten-core/emsdk.git
- cd emsdk
- git pull
- ./emsdk install latest
- ./emsdk install latest
- ./emsdk activate latest
- source "/home/sergei/tmp/emsdk/emsdk_env.sh"
- make all
- add word "export" without qoutes to generated blingfire.js
If you want to integrate BlingFire into your library, using cmake to build bingfire is a better choice.
The following code is just to demonstrate how build WebAssembly version of blingfiretokdll with cmake.
cmake -DCMAKE_TOOLCHAIN_FILE=/home/sergei/tmp/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake .. -B build
cmake --build build --target blingfiretokdll - make http.server
- open in a browser http://0.0.0.0:8000/
- select example.html or blingfire.html
As you click buttons in example.html a corresponding APIs are called and results are printed to console.log. You will see something like this:
Version: 6001
I saw a girl with a telescope . Я видел девушку с телескопом .
I saw a girl with a telescope. Я видел девушку с телескопом.
Model handle: [object Object]
Int32Array(21) [ 109, 29, 425, 13, 8710, 66, 1087, 13, 83595, 9, … ]
Int32Array(21) [ 109, 29, 425, 13, 8710, 66, 1087, 13, 83595, 9, … ]
Model Freed!
Load the model first!
To integrate into a client web page and use in a browser you need three files:
- blingfire.js -- generated JS from Emscripten, contains some useful and not useful helper function and glue code
- blingfire.wasm -- compiled WASM of Blig Fire
- blingfire_wrapper.js -- manually written wrapper JS to implement APIs above