您的位置:首页 > 编程语言 > C#

C# 一个简单分词程序的思路和代码(四) 键树 查询记录

2007-10-27 20:18 1041 查看
由于明天有活动,今天就把(四)和(五)一起给弄出来了,希望大家喜欢。

下面是分词程序中,分词的结果就是使用下面的方法得到,这个我是写在KeyWordTree类中,但是大家喜欢了。

其实也可以放在应用程序中。




/**//// <summary>


/// 分词,键树查找


/// </summary>


/// <param name="strText">分词内容</param>


/// <returns>分词结果</returns>


public string FindKeyWord(string strText)




...{


List<KeyWordTreeNode> tmpRoot = Root.ChildList;


StringBuilder strBuilder = new StringBuilder();


int CC = 0; //已经查到字符数 ,为了找不到的时候,判断是否退回一个字符


for (int iCount = 0; iCount < strText.Length; iCount++)




...{


int tmpIndex = FindIndex(tmpRoot, strText[iCount]);


if (tmpIndex == -1)




...{


if (CC == 0)




...{


strBuilder.Append(strText[iCount]+"|");


}


else




...{


iCount -= 1;


strBuilder.Append("|");


}


tmpRoot = Root.ChildList;


CC = 0;


}


else




...{


strBuilder.Append(strText[iCount]);


//添加ID记录






tmpRoot = tmpRoot[tmpIndex].ChildList;


CC++;


}


}


return strBuilder.ToString();


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐