Comparison of Lucene Analyzer

Source: Internet
Author: User
Several commonly used English analyzer. The differences between them are as follows: Program .
Simpleanalyzer
Standardanalyzer
Whitespaceanalyzer
Stopanalyzer Package Analyzer;

Import Java. Io. reader;
Import Java. Io. stringreader;

Import Org. Apache. Lucene. analysis. analyzer;
Import Org. Apache. Lucene. analysis. simpleanalyzer;
Import Org. Apache. Lucene. analysis. stopanalyzer;
Import Org. Apache. Lucene. analysis. stopfilter;
Import Org. Apache. Lucene. analysis. Token;
Import Org. Apache. Lucene. analysis. tokenizer;
Import Org. Apache. Lucene. analysis. whitespaceanalyzer;
Import Org. Apache. Lucene. analysis. Standard. standardanalyzer;

Public Class Testanalyzer {
Private Static String teststring1 = " The quick brown fox jumped over the lazy dogs " ;
Private Static String teststring2 = " XY & Z mail is-xyz@sohu.com " ;
Public Static Void Testwhitespace (string teststring) Throws Exception {
Analyzer = New Whitespaceanalyzer ();
Reader R = New Stringreader (teststring );
Tokenizer TS = (Tokenizer) analyzer. tokenstream ( "" , R );
System. Err. println ( " ===== Whitespace analyzer ==== " );
System. Err. println ( " Analysis Method: Space Separation " );
Token T;
While (T = TS. Next ()) ! = Null ) {
System. Out. println (T. termtext ());
}
}
Public Static Void Testsimple (string teststring) Throws Exception {
Analyzer = New Simpleanalyzer ();
Reader R = New Stringreader (teststring );
Tokenizer TS = (Tokenizer) analyzer. tokenstream ( "" , R );
System. Err. println ( " ===== Simple analyzer ==== " );
System. Err. println ( " Analysis Method: space and symbol Segmentation " );
Token T;
While (T = TS. Next ()) ! = Null ) {
System. Out. println (T. termtext ());
}
}
Public Static Void Teststop (string teststring) Throws Exception {
Analyzer = New Stopanalyzer ();
Reader R = New Stringreader (teststring );
Stopfilter SF = (Stopfilter) analyzer. tokenstream ( "" , R );
System. Err. println ( " ===== Stop analyzer ==== " );
System. Err. println ( " Analysis Method: space and various symbols are separated to remove the stop words. The stop words include words with no practical meanings, such as is, are, in, on, and. " );
// Stopword
Token T;
While (T = SF. Next ()) ! = Null ) {
System. Out. println (T. termtext ());
}
}
Public Static Void Teststandard (string teststring) Throws Exception {
Analyzer = New Standardanalyzer ();
Reader R = New Stringreader (teststring );
Stopfilter SF = (Stopfilter) analyzer. tokenstream ( "" , R );
System. Err. println ( " ===== Standard analyzer ==== " );
System. Err. println ( " Analysis Method: Hybrid segmentation, including removing stop words and supporting Chinese " );
Token T;
While (T = SF. Next ()) ! = Null ) {
System. Out. println (T. termtext ());
}
}
Public Static Void Main (string [] ARGs) Throws Exception {
//String teststring = teststring1;
String teststring=Teststring2;
System. Out. println (teststring );
Testwhitespace (teststring );
Testsimple (teststring );
Teststop (teststring );
Teststandard (teststring );
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.