📄 sharpictclas分词系统简介(8)其它 - first we try, then we trust - 博客园.mht
字号:
=95=B0=E6=8D=AE=EF=BC=8C=E6=97=A5=E5=90=8E=E5=8F=AF=E4=BB=A5=E8=80=83=E8=99=
=91=E9=87=87=E7=94=A8=E6=9B=B4=E5=A4=8D=E6=9D=82=E7=9A=84=E8=A1=A8=E7=A4=BA=
=E5=BD=A2=E5=BC=8F=E8=BE=93=E5=87=BA=E4=B8=AD=E9=97=B4=E7=BB=93=E6=9E=9C=E3=
=80=82=E8=AF=A5=E4=BA=8B=E4=BB=B6=E5=85=83=E7=B4=A0=E5=AE=9A=E4=B9=89=E5=A6=
=82=E4=B8=8B=EF=BC=9A</P>
<DIV class=3Dcode>
<DIV class=3Dtitle>
<DIV style=3D"FLOAT: right"><IMG class=3DcopyCodeImage=20
src=3D"http://www.cnblogs.com/images/cnblogs_com/zhenyulu/200701/copycode=
.gif"=20
align=3DabsMiddle name=3DccImage> <A onclick=3DCopyCode(this) =
href=3D"javascript:">Copy=20
Code</A></DIV>
<DIV style=3D"CLEAR: =
none">SegmentEventArgs=E7=9A=84=E5=AE=9A=E4=B9=89</DIV></DIV>
<DIV class=3Dcontent><SPAN style=3D"COLOR: #0000ff">public</SPAN> <SPAN=20
style=3D"COLOR: #0000ff">class</SPAN> SegmentEventArgs : EventArgs <BR>{ =
<BR> <SPAN style=3D"COLOR: #0000ff">public</SPAN> =
SegmentStage Stage;=20
<BR> <SPAN style=3D"COLOR: #0000ff">public</SPAN> <SPAN=20
style=3D"COLOR: #0000ff">string</SPAN> Info =3D <SPAN=20
style=3D"COLOR: #ff00ff">""</SPAN>; <BR><BR> ...... =
<BR>}</DIV></DIV>
<P>=E5=89=A9=E4=B8=8B=E7=9A=84=E5=B7=A5=E4=BD=9C=E5=B0=B1=E6=98=AF=E5=AE=9A=
=E4=B9=89=E5=A7=94=E6=B4=BE=E5=B9=B6=E5=8F=91=E5=B8=83=E4=BA=8B=E4=BB=B6=E4=
=BA=86=E3=80=82=E7=94=B1=E4=BA=8E=E5=88=86=E8=AF=8D=E8=BF=87=E7=A8=8B=E4=B8=
=BB=E8=A6=81=E9=9B=86=E4=B8=AD=E5=9C=A8=E4=B8=A4=E4=B8=AA=E7=B1=BB=E4=B8=AD=
=EF=BC=9AWordSegment=E7=B1=BB=E4=B8=8ESegment=E7=B1=BB=EF=BC=8C=E8=80=8C=E7=
=94=A8=E6=88=B7=E9=80=9A=E5=B8=B8=E5=8F=AA=E9=9C=80=E8=A6=81=E4=B8=8EWord=
Segment=E7=B1=BB=E6=89=93=E4=BA=A4=E9=81=93=EF=BC=8C=E5=9B=A0=E6=AD=A4Wor=
dSegment=E7=B1=BB=E4=B8=AD=E8=BD=AC=E5=8F=91=E4=BA=86Segment=E7=B1=BB=E4=BA=
=A7=E7=94=9F=E7=9A=84=E4=BA=8B=E4=BB=B6=E3=80=82</P>
<P>=E5=A7=94=E6=B4=BE=E7=9A=84=E5=AE=9A=E4=B9=89=E4=BB=A5=E5=8F=8A=E4=BA=8B=
=E4=BB=B6=E7=9A=84=E5=AE=9A=E4=B9=89=E5=A6=82=E4=B8=8B=EF=BC=88=E9=83=A8=E5=
=88=86=EF=BC=89=EF=BC=9A</P>
<DIV class=3Dcode>
<DIV class=3Dtitle>
<DIV style=3D"FLOAT: right"><IMG class=3DcopyCodeImage=20
src=3D"http://www.cnblogs.com/images/cnblogs_com/zhenyulu/200701/copycode=
.gif"=20
align=3DabsMiddle name=3DccImage> <A onclick=3DCopyCode(this) =
href=3D"javascript:">Copy=20
Code</A></DIV>
<DIV style=3D"CLEAR: none">=E7=A8=8B=E5=BA=8F</DIV></DIV>
<DIV class=3Dcontent><SPAN style=3D"COLOR: =
#008000">//---=E5=AE=9A=E4=B9=89=E5=A7=94=E6=B4=BE </SPAN><BR><SPAN=20
style=3D"COLOR: #0000ff">public</SPAN> <SPAN=20
style=3D"COLOR: #0000ff">delegate</SPAN> <SPAN style=3D"COLOR: =
#0000ff">void</SPAN>=20
SegmentEventHandler(<SPAN style=3D"COLOR: #0000ff">object</SPAN> sender, =
SegmentEventArgs e); <BR><BR><SPAN style=3D"COLOR: =
#008000">//---=E5=AE=9A=E4=B9=89=E4=BA=8B=E4=BB=B6=20
</SPAN><BR><SPAN style=3D"COLOR: #0000ff">public</SPAN> <SPAN=20
style=3D"COLOR: #0000ff">event</SPAN> SegmentEventHandler =
OnSegmentEvent;=20
<BR><BR><SPAN style=3D"COLOR: =
#008000">//---=E5=8F=91=E5=B8=83=E4=BA=8B=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=
=95 </SPAN><BR><SPAN=20
style=3D"COLOR: #0000ff">private</SPAN> <SPAN style=3D"COLOR: =
#0000ff">void</SPAN>=20
SendEvents(SegmentEventArgs e) <BR>{ <BR> <SPAN=20
style=3D"COLOR: #0000ff">if</SPAN> (OnSegmentEvent !=3D <SPAN=20
style=3D"COLOR: #0000ff">null</SPAN>) <BR> =
OnSegmentEvent(<SPAN style=3D"COLOR: #0000ff">this</SPAN>, e); <BR>} =
<BR><BR><SPAN=20
style=3D"COLOR: #008000">//---=E5=BC=80=E5=A7=8B=E5=88=86=E8=AF=8D =
</SPAN><BR><SPAN=20
style=3D"COLOR: #0000ff">private</SPAN> <SPAN style=3D"COLOR: =
#0000ff">void</SPAN>=20
OnBeginSegment(<SPAN style=3D"COLOR: #0000ff">string</SPAN> sentence) =
<BR>{=20
<BR> SendEvents(<SPAN style=3D"COLOR: #0000ff">new</SPAN>=20
SegmentEventArgs(SegmentStage.BeginSegment, sentence)); <BR>} =
<BR><BR>......=20
<BR><BR><SPAN style=3D"COLOR: =
#008000">//---=E7=BB=93=E6=9D=9F=E5=88=86=E8=AF=8D </SPAN><BR><SPAN=20
style=3D"COLOR: #0000ff">private</SPAN> <SPAN style=3D"COLOR: =
#0000ff">void</SPAN>=20
OnFinishSegment(List<WordResult[]> m_pWordSeg) <BR>{ =
<BR> =20
StringBuilder sb =3D <SPAN style=3D"COLOR: #0000ff">new</SPAN> =
StringBuilder();=20
<BR> <SPAN style=3D"COLOR: #0000ff">for</SPAN> (<SPAN=20
style=3D"COLOR: #0000ff">int</SPAN> k =3D 0; k < m_pWordSeg.Count; =
k++)=20
<BR> { <BR> <SPAN=20
style=3D"COLOR: #0000ff">for</SPAN> (<SPAN style=3D"COLOR: =
#0000ff">int</SPAN> j =3D=20
0; j < m_pWordSeg[k].Length; j++)=20
<BR> sb.Append(<SPAN=20
style=3D"COLOR: #0000ff">string</SPAN>.Format(<SPAN style=3D"COLOR: =
#ff00ff">"{0}=20
/{1} "</SPAN>, m_pWordSeg[k][j].sWord, =20
<BR> &nb=
sp; =20
Utility.GetPOSString(m_pWordSeg[k][j].nPOS)));=20
<BR> sb.Append(<SPAN=20
style=3D"COLOR: #ff00ff">"\r\n"</SPAN>); <BR> } =
<BR><BR> =20
SendEvents(<SPAN style=3D"COLOR: #0000ff">new</SPAN>=20
SegmentEventArgs(SegmentStage.FinishSegment, sb.ToString())); =
<BR>}</DIV></DIV>
<P>=E6=9C=89=E4=BA=86=E8=BF=99=E4=BA=9B=E4=BA=8B=E4=BB=B6=EF=BC=8C=E7=94=A8=
=E6=88=B7=E5=8F=AF=E4=BB=A5=E6=A0=B9=E6=8D=AE=E9=9C=80=E8=A6=81=E8=AE=A2=E9=
=98=85=E4=B8=8D=E5=90=8C=E7=9A=84=E4=BA=8B=E4=BB=B6=E6=9D=A5=E8=8E=B7=E5=8F=
=96=E5=88=86=E8=AF=8D=E7=9A=84=E4=B8=AD=E9=97=B4=E7=BB=93=E6=9E=9C=EF=BC=8C=
=E6=9E=81=E5=A4=A7=E6=96=B9=E4=BE=BF=E4=BA=86=E7=A8=8B=E5=BA=8F=E8=B0=83=E8=
=AF=95=E5=B7=A5=E4=BD=9C=E3=80=82</P>
<H3>2=E3=80=81SharpICTCLAS=E7=9A=84=E4=BD=BF=E7=94=A8</H3>
<P>=E4=B8=8B=E9=9D=A2=E6=98=AF=E4=B8=80=E4=B8=AA=E4=BD=BF=E7=94=A8SharpIC=
TCLAS=E7=9A=84=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=9A</P>
<DIV class=3Dcode>
<DIV class=3Dtitle>
<DIV style=3D"FLOAT: right"><IMG class=3DcopyCodeImage=20
src=3D"http://www.cnblogs.com/images/cnblogs_com/zhenyulu/200701/copycode=
.gif"=20
align=3DabsMiddle name=3DccImage> <A onclick=3DCopyCode(this) =
href=3D"javascript:">Copy=20
Code</A></DIV>
<DIV style=3D"CLEAR: none">WordSegmentSample.cs</DIV></DIV>
<DIV class=3Dcontent><SPAN style=3D"COLOR: #0000ff">using</SPAN> System; =
<BR><SPAN=20
style=3D"COLOR: #0000ff">using</SPAN> System.Collections.Generic; =
<BR><SPAN=20
style=3D"COLOR: #0000ff">using</SPAN> System.Text; <BR><STRONG><SPAN=20
style=3D"COLOR: #0000ff">using</SPAN> SharpICTCLAS; =
</STRONG><BR><BR><SPAN=20
style=3D"COLOR: #0000ff">public</SPAN> <SPAN style=3D"COLOR: =
#0000ff">class</SPAN>=20
WordSegmentSample <BR>{ <BR> <SPAN=20
style=3D"COLOR: #0000ff">private</SPAN> <SPAN style=3D"COLOR: =
#0000ff">int</SPAN>=20
nKind =3D 1; <SPAN style=3D"COLOR: =
#008000">//=E5=9C=A8NShortPath=E6=96=B9=E6=B3=95=E4=B8=AD=E7=94=A8=E6=9D=A5=
=E5=86=B3=E5=AE=9A=E5=88=9D=E6=AD=A5=E5=88=87=E5=88=86=E6=97=B6=E5=88=86=E6=
=88=90=E5=87=A0=E7=A7=8D=E7=BB=93=E6=9E=9C=20
</SPAN><BR> <SPAN style=3D"COLOR: #0000ff">private</SPAN> =
WordSegment=20
wordSegment; <BR><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #008000">//=20
=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=EF=BC=8C=E5=9C=A8=E6=B2=A1=E6=9C=89=E6=
=8C=87=E6=98=8EnKind=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8CnKind =
=E5=8F=96 1 </SPAN><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #0000ff">public</SPAN>=20
WordSegmentSample(<SPAN style=3D"COLOR: #0000ff">string</SPAN> dictPath) =
: <SPAN=20
style=3D"COLOR: #0000ff">this</SPAN>(dictPath, 1) { } =
<BR><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #008000">// =
=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=20
</SPAN><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #0000ff">public</SPAN>=20
WordSegmentSample(<SPAN style=3D"COLOR: #0000ff">string</SPAN> dictPath, =
<SPAN=20
style=3D"COLOR: #0000ff">int</SPAN> nKind) <BR> {=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">this</SPAN>.nKind =3D nKind;=20
<BR> <STRONG><SPAN=20
style=3D"COLOR: #0000ff">this</SPAN>.wordSegment =3D <SPAN=20
style=3D"COLOR: #0000ff">new</SPAN> WordSegment();=20
</STRONG><BR><BR> <SPAN=20
style=3D"COLOR: #008000">//---------- =
=E8=AE=A2=E9=98=85=E5=88=86=E8=AF=8D=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E4=
=BA=8B=E4=BB=B6 ----------=20
</SPAN><BR><STRONG> =
wordSegment.OnSegmentEvent +=3D=20
<SPAN style=3D"COLOR: #0000ff">new</SPAN> SegmentEventHandler(<SPAN=20
style=3D"COLOR: #0000ff">this</SPAN>.OnSegmentEventHandler);=20
<BR> =
wordSegment.InitWordSegment(dictPath);=20
</STRONG><BR> } <BR><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #008000">// =
=E5=BC=80=E5=A7=8B=E5=88=86=E8=AF=8D=20
</SPAN><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #0000ff">public</SPAN>=20
List<WordResult[]> Segment(<SPAN style=3D"COLOR: =
#0000ff">string</SPAN>=20
sentence) <BR> { <BR> =
<STRONG><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN> wordSegment.Segment(sentence, =
nKind);=20
</STRONG><BR> } <BR> <BR> =
<SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #008000">// =
=E8=BE=93=E5=87=BA=E5=88=86=E8=AF=8D=E8=BF=87=E7=A8=8B=E4=B8=AD=E6=AF=8F=E4=
=B8=80=E6=AD=A5=E7=9A=84=E4=B8=AD=E9=97=B4=E7=BB=93=E6=9E=9C=20
</SPAN><BR> <SPAN=20
style=3D"COLOR: =
#008000">//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
</SPAN><BR> <SPAN style=3D"COLOR: #0000ff">private</SPAN> =
<SPAN=20
style=3D"COLOR: #0000ff">void</SPAN> OnSegmentEventHandler(<SPAN=20
style=3D"COLOR: #0000ff">object</SPAN> sender, SegmentEventArgs e)=20
<BR> { <BR> <SPAN=20
style=3D"COLOR: #0000ff">switch</SPAN> (e.Stage)=20
<BR> {=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.BeginSegment:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
=E5=8E=9F=E5=A7=8B=E5=8F=A5=E5=AD=90=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info + <SPAN style=3D"COLOR: =
#ff00ff">"\r\n"</SPAN>);=20
<BR> =
<SPAN=20
style=3D"COLOR: #0000ff">break</SPAN>;=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.AtomSegment:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
=E5=8E=9F=E5=AD=90=E5=88=87=E5=88=86=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info);=20
<BR> =
<SPAN=20
style=3D"COLOR: #0000ff">break</SPAN>;=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.GenSegGraph:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
=E7=94=9F=E6=88=90=20
segGraph=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info);=20
<BR> =
<SPAN=20
style=3D"COLOR: #0000ff">break</SPAN>;=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.GenBiSegGraph:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
=E7=94=9F=E6=88=90=20
biSegGraph=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info);=20
<BR> =
<SPAN=20
style=3D"COLOR: #0000ff">break</SPAN>;=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.NShortPath:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
NShortPath =
=E5=88=9D=E6=AD=A5=E5=88=87=E5=88=86=E7=9A=84=E5=88=B0=E7=9A=84 N=20
=E4=B8=AA=E7=BB=93=E6=9E=9C=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info);=20
<BR> =
<SPAN=20
style=3D"COLOR: #0000ff">break</SPAN>;=20
<BR> <SPAN=20
style=3D"COLOR: #0000ff">case</SPAN> SegmentStage.BeforeOptimize:=20
<BR> =20
Console.WriteLine(<SPAN style=3D"COLOR: #ff00ff">"\r\n=3D=3D=3D=3D =
=E7=BB=8F=E8=BF=87=E6=95=B0=E5=AD=97=E3=80=81=E6=97=A5=E6=9C=9F=E5=90=88=E5=
=B9=B6=E7=AD=89=E7=AD=96=E7=95=A5=E5=A4=84=E7=90=86=E5=90=8E=E7=9A=84 N=20
=E4=B8=AA=E7=BB=93=E6=9E=9C=EF=BC=9A\r\n"</SPAN>);=20
<BR> =20
Console.WriteLine(e.Info);=20
<BR> =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -