39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const utils = require('../../utils');
|
|
|
|
const input = fs.readFileSync(path.join(__dirname, './data.txt'), 'utf8')
|
|
|
|
let list = input.trim().replace(/[\r\n]+/g, "\n").split("\n")
|
|
console.log(list)
|
|
let radical = ""
|
|
let isWord = false
|
|
let pinyin = []
|
|
for (let i = 0; i < list.length; i++) {
|
|
const item = list[i].trim()
|
|
let match = item.match(/(.) 部首的汉字/)
|
|
if (match) {
|
|
// 新的偏旁部首开始了
|
|
radical = match[1]
|
|
} else {
|
|
// 这是汉字或者拼音
|
|
if (!isWord) {
|
|
// 拼音
|
|
pinyin = item.split(' ').sort()
|
|
} else {
|
|
// 汉字
|
|
let struct = utils.structure()
|
|
struct.word = item
|
|
struct.pinyin = pinyin
|
|
struct.type = 2
|
|
struct.from.push("3")
|
|
utils.addData(struct, false)
|
|
// console.log(item, pinyin)
|
|
}
|
|
isWord = !isWord
|
|
}
|
|
}
|
|
|
|
utils.saveData()
|
|
console.log("done")
|