Search code examples
javascriptparsingkuromoji

How to Use Kuromoji.js in Javascript


I recently installed a package w/ Bower from here: https://github.com/takuyaa/kuromoji.js/

Reading the installation on the github, I basically copied and pasted from the guide:

kuromoji.builder({ dicPath: "../bower_components/kuromoji/dict/" }).build(function (err, tokenizer) {
    // tokenizer is ready
    var path = tokenizer.tokenize("すもももももももものうち");
    console.log(path);
});

However, I do not know what the "kuromoji" should refer to. Here is the obvious error:

Uncaught ReferenceError: kuromoji is not defined

Here is a screenshot of my directory tree:

enter image description here

Not sure how to properly use this.


Solution

  • import kuromoji from 'kuromoji'
    

    That provides the 'kuromoji' object you're trying to reference