`

<转>庖丁解牛分词之自定义词库[自定义词典]

 
阅读更多

原链接: http://hi.baidu.com/stone_kings/item/fff2efd6db55df2b38f6f766 

 

发现很久很久没更新了,尤其是这个模块,也就好久没进步了!学习如逆水行舟,不进则退!趁着还没到白首之际,应该多学习。
首先,还是先贴出来参考来源,毕竟非原创。
1)、http://blog.csdn.net/askpp/archive/2009/09/08/4532355.aspx
2)、http://qipei.javaeye.com/blog/365207
现在继续:
1
、到http://code.google.com/p/paoding/downloads/list下载paoding-analysis-2.0.4-alpha2.zip
2
、然后解压缩,找到dic文件夹,复制到你想存放的文件夹下
         <!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter" /> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0" /> <v:f eqn="sum @0 1 0" /> <v:f eqn="sum 0 0 @1" /> <v:f eqn="prod @2 1 2" /> <v:f eqn="prod @3 21600 pixelWidth" /> <v:f eqn="prod @3 21600 pixelHeight" /> <v:f eqn="sum @0 0 1" /> <v:f eqn="prod @6 1 2" /> <v:f eqn="prod @7 21600 pixelWidth" /> <v:f eqn="sum @8 21600 0" /> <v:f eqn="prod @7 21600 pixelHeight" /> <v:f eqn="sum @10 21600 0" /> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" /> <o:lock v:ext="edit" aspectratio="t" /> </v:shapetype><v:shape id="图片_x0020_2" o:spid="_x0000_i1037" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/fbf41423c208de7c9922ed1b.jpg" style='width:399pt;height:178.5pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image001.png" o:title="fbf41423c208de7c9922ed1b" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/fbf41423c208de7c9922ed1b.jpg<!--[endif]--><!--[if gte vml 1]><v:shape id="图片_x0020_3" o:spid="_x0000_i1036" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/b5564f95a57a4d267bf480e5.jpg" style='width:568.5pt;height:421.5pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image003.png" o:title="b5564f95a57a4d267bf480e5" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/b5564f95a57a4d267bf480e5.jpg<!--[endif]-->


3
、配置环境变量,如果不配置,运行会报错,报错的中文信息也是需要进行配置环境变量

<!--[if gte vml 1]><v:shape id="图片_x0020_4" o:spid="_x0000_i1035" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/e1d7bb50d86e89721038c2a0.jpg" style='width:315.75pt;height:371.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image005.png" o:title="e1d7bb50d86e89721038c2a0" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/e1d7bb50d86e89721038c2a0.jpg<!--[endif]-->
4
、删除.compiled文件
<!--[if gte vml 1]><v:shape id="图片_x0020_5" o:spid="_x0000_i1034" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/4c5a624e6044dae4d1c86abe.jpg" style='width:97.5pt;height:59.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image007.png" o:title="4c5a624e6044dae4d1c86abe" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/4c5a624e6044dae4d1c86abe.jpg<!--[endif]-->5
、新建一个文本文件,后缀名问.dic,采用utf-8保存到dic的文件目录中,这里保存在了E:\paodingTest\dic\locale
       <!--[if gte vml 1]><v:shape id="图片_x0020_6" o:spid="_x0000_i1033" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/7bbc5afaee6569b959ee90bc.jpg" style='width:568.5pt;height:471pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image009.png" o:title="7bbc5afaee6569b959ee90bc" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/7bbc5afaee6569b959ee90bc.jpg<!--[endif]-->
6
、下面我们写个分词测试程序
<!--[if gte vml 1]><v:shape id="图片_x0020_7" o:spid="_x0000_i1032" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/8c7c43df1e87c53d6327988f.jpg" style='width:568.5pt;height:311.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image011.jpg" o:title="8c7c43df1e87c53d6327988f" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/8c7c43df1e87c53d6327988f.jpg<!--[endif]-->7
、自定义词库的情况下分词结果,首先看到的是词库的编译信息
<!--[if gte vml 1]><v:shape id="图片_x0020_8" o:spid="_x0000_i1031" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/0a089ebf54f7cf2419d81f91.jpg" style='width:568.5pt;height:195pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image013.png" o:title="0a089ebf54f7cf2419d81f91" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/0a089ebf54f7cf2419d81f91.jpg<!--[endif]-->
8
、带自定义词库的分词结果
<!--[if gte vml 1]><v:shape id="图片_x0020_9" o:spid="_x0000_i1030" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/0bf25ef431d584c17609d793.jpg" style='width:354pt;height:577.5pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image015.png" o:title="0bf25ef431d584c17609d793" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/0bf25ef431d584c17609d793.jpg<!--[endif]-->
















































9
、删除自定义词库和.compiled文件,重新分词
<!--[if gte vml 1]><v:shape id="图片_x0020_10" o:spid="_x0000_i1029" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/6b01aa191c987954dbb4bd64.jpg" href="http://hiphotos.baidu.com/xwx520/pic/item/7f5f19fb7a6de44a034f569b.jpg" target="_blank" style='width:295.5pt;height:494.25pt;visibility:visible; mso-wrap-style:square' o:button="t"> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image017.png" o:title="6b01aa191c987954dbb4bd64" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/6b01aa191c987954dbb4bd64.jpg<!--[endif]-->
10
、放在一起比较,效果还是有的
<!--[if gte vml 1]><v:shape id="图片_x0020_11" o:spid="_x0000_i1028" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/72bcd813dabe2dfef6039e7d.jpg" style='width:569.25pt;height:504.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image019.png" o:title="72bcd813dabe2dfef6039e7d" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/72bcd813dabe2dfef6039e7d.jpg<!--[endif]-->















































11
、假设我们在分词的时候,需要把运、动分开,默认情况下是不分开的
<!--[if gte vml 1]><v:shape id="图片_x0020_12" o:spid="_x0000_i1027" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/fe4fc7ca9669e8a8c8176844.jpg" style='width:511.5pt;height:428.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image021.png" o:title="fe4fc7ca9669e8a8c8176844" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/fe4fc7ca9669e8a8c8176844.jpg<!--[endif]-->
12
、在词库中增加两个词运和动
<!--[if gte vml 1]><v:shape id="图片_x0020_13" o:spid="_x0000_i1026" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/d105e1196167f86b42a9ad47.jpg" style='width:568.5pt;height:453.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image023.png" o:title="d105e1196167f86b42a9ad47" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/d105e1196167f86b42a9ad47.jpg<!--[endif]-->

13
、当然,如果想把这个分词器用得更好,还需要深入去了解和思考该分词方法,比如,我是运动员,虽然我们在自定义词库中填加了词运动员,但是依旧没有切分成运动员,反而出现了不相关的动员这个词语。而需要同时将运动切分为运动,那也是需要好好思考用法,当然这也和中国汉语的特殊性有关,例如:乒乓球拍卖完了,在没有上下文的情况下本身就存在歧义。
<!--[if gte vml 1]><v:shape id="图片_x0020_14" o:spid="_x0000_i1025" type="#_x0000_t75" alt="http://hiphotos.baidu.com/xwx520/pic/item/2349d418ada8959a4bedbc36.jpg" style='width:559.5pt;height:7in;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///r:\Temp\msohtmlclip1\01\clip_image025.png" o:title="2349d418ada8959a4bedbc36" /> </v:shape><![endif]--><!--[if !vml]-->http://hiphotos.baidu.com/xwx520/pic/item/2349d418ada8959a4bedbc36.jpg<!--[endif]-->

<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics