SharpICTCLAS分词系统简介(9)词库扩充

SharpICTCLAS分词系统简介(9)词库扩充(转)

1、SharpICTCLAS中词库的扩充

如果对SharpICTCLAS目前词库不满意的化,可以考虑扩充现有词库。扩充方法非常简单,代码如下:

Copy Code
词库扩充
static void Main( string[] args)
{
   string DictPath = Path.Combine(Environment.CurrentDirectory, "Data") +
                     Path.DirectorySeparatorChar;
   Console.WriteLine( "正在读入字典,请稍候...");

   WordDictionary dict = new WordDictionary();
   dict.Load(DictPath + "coreDict.dct");

   Console.WriteLine( "\r\n向字典库插入“设计模式”一词...");
   dict.AddItem( "设计模式", Utility.GetPOSValue( "n"), 10);

   Console.WriteLine( "\r\n修改完成,将字典写入磁盘文件coreDictNew.dct,请稍候...");
   dict.Save(DictPath + "coreDictNew.dct");

   Console.Write( "按下回车键退出......");
   Console.ReadLine();
}

通过AddItem方法可以轻松实现添加新词汇,添加时除了要指明词外,还需指明词性、词频。

2、其它工具

SharpICTCLAS示例代码中还提供了一些用于对文件进行预处理的工具类PreProcessUtility,里面提供了将GB2312中繁体汉字转换为简体字的代码,以及将全角字母转换为半角字母的方法,除此之外,还提供了对HTML文件进行预处理,去除HTML标记的方法,用户可酌情使用。

 

  • 小结

有关SharpICTCLAS的系列文章到此为止就全部结束。

来源:http://www.cnblogs.com/zhenyulu/category/85598.html

你可能感兴趣的:(SharpICTCLAS分词系统简介(9)词库扩充)