takuyaa / kuromoji.js

JavaScript implementation of Japanese morphological analyzer
846 stars 118 forks source link

Builder wont accept url to data folder in chrome extension #39

Open ghost opened 4 years ago

ghost commented 4 years ago

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
larvata commented 4 years ago

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.