-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a408c9
Showing
7 changed files
with
159,391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
/char2pinyin.json | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict'; | ||
|
||
var cantCharDict = require('./dict/cantCharDic.json'); | ||
var pinyinDict = require('./dict/pinyinDict.json'); | ||
var codePointDict = require('./dict/codePointDict.json'); | ||
|
||
function getPinyin (c) { | ||
var result = (!isNaN(c) ? codePointDict[c] : cantCharDict[c]); | ||
return Array.isArray(result) ? result.map(function (child) { | ||
return child.pinyin | ||
}) : null; | ||
} | ||
|
||
function getCodePoint (c) { | ||
c = c.toString(); | ||
var result = (c.match(/^[a-z]+$/i) ? pinyinDict[c] : cantCharDict[c]); | ||
return Array.isArray(result) ? result.map(function (child) { | ||
return child.codepoint | ||
}) : null; | ||
} | ||
|
||
function getChar (c) { | ||
var result = (!isNaN(c) ? codePointDict[c] : pinyinDict[c]); | ||
return Array.isArray(result) ? result.map(function (child) { | ||
return child.char | ||
}) : null; | ||
} | ||
|
||
module.exports = { | ||
getPinyin: getPinyin, | ||
getChar: getChar, | ||
getCodePoint: getCodePoint | ||
}; | ||
|
||
//console.log(getCodePoint(19958)); | ||
//console.log(getPinyin(199990)); | ||
//console.log(getChar("一")); | ||
|
||
|
||
|
||
//console.log(getCodePoint("一")); | ||
//console.log(getPinyin("一")); | ||
//console.log(getPinyin(19968)); | ||
//console.log(getChar("yat")); | ||
//console.log(getChar(19968)); | ||
|
||
/** | ||
* For Development Purpose. | ||
*/ | ||
|
||
/** | ||
{ | ||
"codepoint": 19968, | ||
"char": "一", | ||
"pinyin": "yat" | ||
}, | ||
* */ | ||
//var pinyin = {}; | ||
//char2pinyinSet.forEach(function (child) { | ||
// | ||
// var py = child.pinyin.split('/'); | ||
// | ||
// py.forEach(function (pyChild) { | ||
// if (!pinyin.hasOwnProperty(pyChild)) pinyin[pyChild] = []; | ||
// | ||
// pinyin[pyChild].push(child); | ||
// }); | ||
// | ||
// | ||
//}); | ||
// | ||
//writeile('./pinyinDict.json', pinyin); | ||
|
||
//var cantChar = {}; | ||
//char2pinyinSet.forEach(function (child) { | ||
// | ||
// var c = child.char; | ||
// | ||
// if (!cantChar.hasOwnProperty(c)) cantChar[c] = []; | ||
// | ||
// cantChar[c].push(child); | ||
// | ||
//}); | ||
// | ||
//writeile('./cantCharDic.json', cantChar); | ||
|
||
//var codePoint = {}; | ||
//char2pinyinSet.forEach(function (child) { | ||
// | ||
// var c = child.codepoint; | ||
// | ||
// if (!codePoint.hasOwnProperty(c)) codePoint[c] = []; | ||
// | ||
// codePoint[c].push(child); | ||
// | ||
//}); | ||
// | ||
//writeile('./codePointDict.json', codePoint); | ||
// | ||
// | ||
//function writeile(path, jObj) { | ||
// var fs = require('fs'); | ||
// fs.writeFile(path, JSON.stringify(jObj, null, 4), function (err) { | ||
// if (err) return console.log(err); | ||
// console.log("Write to " + path + " Done."); | ||
// }); | ||
//} | ||
|
||
//console.log(pinyin); |
Binary file not shown.
Oops, something went wrong.