kuromoji.js icon indicating copy to clipboard operation
kuromoji.js copied to clipboard

Builder wont accept url to data folder in chrome extension

Open ghost opened this issue 4 years ago • 1 comments

Im trying to use the library inside a chrome extension and when I set up the builder, I pass in a path to data made by chrome like this:

let builder = kuromoji
  .builder({ dicPath: chrome.extension.getURL("data/") })
  .build(function (err, tokenizer) {
    var path = tokenizer.tokenize("すもももももももものうち");
  });

However I get an error:

kuromoji.js:7724 Uncaught TypeError: Cannot read property 'lookup' of null
    at UnknownDictionary.lookup (kuromoji.js:7724)
    at ViterbiBuilder.build (kuromoji.js:8806)
    at Tokenizer.getLattice (kuromoji.js:6961)
    at Tokenizer.tokenizeForSentence (kuromoji.js:6916)
    at Tokenizer.tokenize (kuromoji.js:6907)
    at furigana.js:103
    at kuromoji.js:7010
    at kuromoji.js:8272
    at kuromoji.js:3876
    at kuromoji.js:475

ghost avatar Apr 15 '20 18:04 ghost

I created a chrome extension based on kuromoji too, it works well. https://github.com/larvata/mirigana/blob/develop/src/background/background.js#L46

I guess you place the dict files in the wrong place.

larvata avatar Apr 22 '20 18:04 larvata