hexenq / kuroshiro

Japanese language library for converting Japanese sentence to Hiragana, Katakana or Romaji with furigana and okurigana modes supported.
https://kuroshiro.org
MIT License
781 stars 88 forks source link

TypeError: Cannot read property 'parse' of null #78

Closed Takiyo0 closed 3 years ago

Takiyo0 commented 3 years ago

Anyone know why i get this error? i use code from readme, this is my code

const Kuroshiro = require('kuroshiro');
const kuroshiro = new Kuroshiro();

const result = await kuroshiro.convert("感じ取れたら手を繋ごう、重なるのは人生のライン and レミリア最高!", { to: "hiragana" });
            console.log(result)

and this is the error

TypeError: Cannot read property 'parse' of null
    at Kuroshiro._callee2$ (/home/runner/ChilledChino/node_modules/kuroshiro/lib/core.js:162:55)
    at tryCatch (/home/runner/ChilledChino/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/home/runner/ChilledChino/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.<computed> [as next] (/home/runner/ChilledChino/node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/home/runner/ChilledChino/node_modules/kuroshiro/lib/core.js:19:191)
    at /home/runner/ChilledChino/node_modules/kuroshiro/lib/core.js:19:437
    at new Promise (<anonymous>)
    at Kuroshiro.<anonymous> (/home/runner/ChilledChino/node_modules/kuroshiro/lib/core.js:19:99)
    at Kuroshiro.convert (/home/runner/ChilledChino/node_modules/kuroshiro/lib/core.js:438:30)
    at Object.execute (/home/runner/ChilledChino/command/information/japanese.js:15:45)
    at Client.<anonymous> (/home/runner/ChilledChino/index.js:968:13)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

did i miss some code? please let me know. thanks

hw4n commented 3 years ago

I also had this error but it works great after initializing with an analyzer

try this one:

const Kuroshiro = require('kuroshiro');
const kuroshiro = new Kuroshiro();
const KuromojiAnalyzer = require('kuroshiro-analyzer-kuromoji');
const analyzer = new KuromojiAnalyzer();

async function init() {
  await kuroshiro.init(analyzer);
}

async function toRomaji(string) {
  return await kuroshiro.convert(string, { to: "romaji", romajiSystem: "passport" });
}

init().then(() => {
  toRomaji("創造は始まりの風を連れて").then(str => console.log(str));
  toRomaji("月曜日のクリームソーダ").then(str => console.log(str));
});

result:

sozowahajimarinokazeotsurete
getsuyobinokurimusoda
Takiyo0 commented 3 years ago

ah yes, thanks :D