添加 README.MD

This commit is contained in:
toolgood
2020-04-06 10:16:39 +08:00
parent 3e4b2c8f31
commit 74b6830cbd
4 changed files with 84 additions and 4 deletions
+56
View File
@@ -0,0 +1,56 @@
ToolGood.Words(Js版本)
==================
一款高性能非法词(敏感词)检测组件,繁体简体互换,获取拼音首字母,获取拼音字母等功能。
文件说明:
```
ToolGood.Words.PinYin.js 拼音转化
ToolGood.Words.Translate.js 繁体简体转化
ToolGood.Words.StringSearch.js 字符串检索
ToolGood.Words.WordsSearch.js 字符串检索,包含位置信息、索引
```
### 拼音操作
```
var pinyin = new PinYin();
// 获取全拼
pinyin.GetPinYin("我爱中国");//WoAiZhongGuo
pinyin.GetPinYin("我爱中国",true);//WǒÀiZhōngGuó
// 获取首字母
pinyin.GetFirstPinYin("我爱中国");//WAZG
// 获取全部拼音
pinyin.GetAllPinYin('传');//Chuan,Zhuan
// 获取姓名
pinyin.GetPinYinForName("单一一")//ShanYiYi
pinyin.GetPinYinForName("单一一",true)//ShànYīYī
```
### 繁体简体互换
```
var translate = new Translate();
// 转成简体
translate.ToSimplifiedChinese("我愛中國");
translate.ToSimplifiedChinese("我愛中國",1);// 港澳繁体 转 简体
translate.ToSimplifiedChinese("我愛中國",2);// 台湾正体 转 简体
// 转成繁体
translate.ToTraditionalChinese("我爱中国");
translate.ToTraditionalChinese("我爱中国",1);// 简体 转 港澳繁体
translate.ToTraditionalChinese("我爱中国",2);// 简体 转 台湾正体
```
### 字符串检测
```
string s = "中国|国人|zg人";
string test = "我是中国人";
var search = new WordsSearch();// 或 var search = new StringSearch();
wordsSearch.SetKeywords(s.split('|'));
// 查找第一个匹配
var f = search.FindFirst(test);
// 查找所有匹配
var all = search.FindAll(test);
// 检查是否有匹配
var b = search.ContainsAny(test);
// 替换所有匹配
var str = search.Replace(test, '*');
```
+19 -1
View File
@@ -253,7 +253,7 @@ function PinYin() {
*/
this.GetPinYinList = function (text, tone = 0) {
InitPyWords();
if (tone) { tone = 1;}
if (tone) { tone = 1; }
var list = [];
for (var i = 0; i < text.length; i++) {
list.push(null);
@@ -306,6 +306,24 @@ function PinYin() {
}
return sb;
}
/**
* 获取拼音首字母
* @param {any} text
* @param {any} tone 是否带声调 1 是 0否
*/
this.GetFirstPinYin = function (text, tone = 0) {
if (tone) { tone = 1; }
var list = this.GetPinYinList(text, tone);
var sb = "";
for (var i = 0; i < list.length; i++) {
var c = list[i];
if (c != null) {
sb += c[0];
}
}
return sb;
}
/**
* 获取 单字的 所有拼音 ,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证
File diff suppressed because one or more lines are too long
+6
View File
@@ -164,12 +164,18 @@
log("PinYin GetPinYin is error.............................");
}
log("PinYin GetPinYin is run.");
py = pinyin.GetPinYin("我爱中国", true);
if (py != "WǒÀiZhōngGuó") {
log("PinYin GetPinYin is error.............................");
}
log("PinYin GetFirstPinYin is run.");
py = pinyin.GetFirstPinYin("我爱中国");
if (py != "WAZG") {
log("PinYin GetFirstPinYin is error.............................");
}
log("PinYin GetAllPinYin is run.");
var pys = pinyin.GetAllPinYin('传');