C # Chinese Word Segmentation Algorithm : Chineseanalyzer.
First, we need to reference the two dll library files Lucene. net. dll + Lucene. China. dll, which will be packaged at the end of this article and debugged using vs2008:
Using Lucene. net;
Using Lucene. net. analysis;
Using Lucene. China;
----------
Example:
Private void button#click (Object sender, eventargs E)
{
Stringbuilder sb = new stringbuilder ();
SB. Remove (0, SB. Length );
String T1 = "";
Int I = 0;
Analyzer analyzer = new Lucene. China. chineseanalyzer ();
Stringreader sr = new stringreader (richtextbox1.text );
Tokenstream stream = analyzer. tokenstream (null, Sr );
Long begin = system. datetime. Now. ticks;
Token T = stream. Next ();
While (T! = NULL)
{
T1 = T. tostring (); // display format: (keyword,), to be processed
T1 = t1.replace ("(","");
Char [] separator = {','};
T1 = t1.split (separator) [0];
SB. append (I + ":" + t1 + "\ r \ n ");
T = stream. Next ();
I ++;
}
Richtextbox2.text = sb. tostring ();
Long end = system. datetime. Now. ticks; // 100 milliseconds
Int time = (INT) (end-begin)/10000); // MS
Richtextbox2.text + = "Time consumed" + (time) + "Ms \ r \ n ==================================== \ r \ n ";
}
As follows:
:
Chinese Word Segmentation Algorithm: chineseanalyzer.rar