yukichant 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/node.js +16 -5
package/package.json
CHANGED
package/src/node.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
3
4
|
import kuromoji from 'kuromoji'
|
|
4
5
|
import natural from 'natural'
|
|
5
6
|
import typoCorrection from './typo-correction.js'
|
|
@@ -7,16 +8,26 @@ import { initTypoCorrection } from './typo-correction.js'
|
|
|
7
8
|
import fkm, { initFuzzyKanjiMatch } from './fuzzy-kanji-match.js'
|
|
8
9
|
import { createChant } from './index.js'
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const require = createRequire(import.meta.url)
|
|
12
|
+
|
|
13
|
+
const meisi = JSON.parse(fs.readFileSync(new URL('../data/meisi.json', import.meta.url), 'utf8'));
|
|
14
|
+
const dousi = JSON.parse(fs.readFileSync(new URL('../data/dousi.json', import.meta.url), 'utf8'));
|
|
15
|
+
|
|
16
|
+
const kanji2radicalPath = require.resolve('kanjivg-radical/data/kanji2radical.json')
|
|
17
|
+
const kanjiVgRadicalDir = path.dirname(path.dirname(kanji2radicalPath))
|
|
18
|
+
const kanji2element = JSON.parse(
|
|
19
|
+
fs.readFileSync(path.join(kanjiVgRadicalDir, 'data', 'kanji2radical.json'), 'utf8')
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const yukidicBasePath = require.resolve('yukidic/dic/base.dat.gz')
|
|
23
|
+
const yukidicDir = path.dirname(path.dirname(yukidicBasePath))
|
|
24
|
+
const dicPath = path.join(yukidicDir, 'dic') + path.sep
|
|
14
25
|
|
|
15
26
|
initFuzzyKanjiMatch({ meisi, dousi, kanji2element, TfIdf: natural.TfIdf });
|
|
16
27
|
|
|
17
28
|
const tokenizer = await new Promise((resolve, reject) => {
|
|
18
29
|
kuromoji
|
|
19
|
-
.builder({ dicPath
|
|
30
|
+
.builder({ dicPath })
|
|
20
31
|
.build(function (err, tokenizer) {
|
|
21
32
|
if (err != null) {
|
|
22
33
|
reject(err);
|