src/DotNetCommon.PinYin/Internals/BasePinyinMatch.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DotNetCommon.PinYin.Internals
{
internal abstract class BasePinyinMatch
{
#region pinyinSearch
public class PinyinSearch : BaseSearch
{
string[][] _keywordPinyins;
int[] _indexs;
public void SetKeywords(List<Tuple<string, string[]>> keywords)
{
_keywords = new string[keywords.Count];
_keywordPinyins = new string[keywords.Count][];
for (int i = 0; i < keywords.Count; i++) {
_keywords[i] = keywords[i].Item1;
_keywordPinyins[i] = keywords[i].Item2;
}
SetKeywords();
}
public void SetIndexs(int[] indexs)
{
_indexs = indexs;
}
public bool Find(string text, string hz, string[] pinyins)
{
TrieNode2 ptr = null;
for (int i = 0; i < text.Length; i++) {
TrieNode2 tn;
if (ptr == null) {
tn = _first[text[i]];
} else {
if (ptr.TryGetValue(text[i], out tn) == false) {
tn = _first[text[i]];
}
}
if (tn != null) {
if (tn.End) {
foreach (var result in tn.Results) {
var keyword = _keywords[result];
var start = i + 1 - keyword.Length;
var end = i;
bool isok = true;
var keywordPinyins = _keywordPinyins[result];
for (int j = 0; j < keyword.Length; j++) {
var idx = start + j;
var py = keywordPinyins[j];
if (py.Length == 1 && py[0] >= 0x3400 && py[0] <= 0x9fd5) {
if (hz[idx] != py[0]) {
后面还有 209 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
