analyzerdemo.java

来自「LuceneInAction配套源码,LuceneInAction是对lucen」· Java 代码 · 共 53 行

JAVA
53
字号
package lia.analysis;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.StopAnalyzer;import org.apache.lucene.analysis.SimpleAnalyzer;import org.apache.lucene.analysis.WhitespaceAnalyzer;import org.apache.lucene.analysis.standard.StandardAnalyzer;import java.io.IOException;/** * Adapted from code which first appeared in a java.net article * written by Erik */public class AnalyzerDemo {  private static final String[] examples = {    "The quick brown fox jumped over the lazy dogs",    "XY&Z Corporation - xyz@example.com"  };  private static final Analyzer[] analyzers = new Analyzer[]{    new WhitespaceAnalyzer(),    new SimpleAnalyzer(),    new StopAnalyzer(),    new StandardAnalyzer()  };  public static void main(String[] args) throws IOException {    // Use the embedded example strings, unless    // command line arguments are specified, then use those.    String[] strings = examples;    if (args.length > 0) {      strings = args;    }    for (int i = 0; i < strings.length; i++) {      analyze(strings[i]);    }  }  private static void analyze(String text) throws IOException {    System.out.println("Analyzing \"" + text + "\"");    for (int i = 0; i < analyzers.length; i++) {      Analyzer analyzer = analyzers[i];      String name = analyzer.getClass().getName();      name = name.substring(name.lastIndexOf(".") + 1);      System.out.println("  " + name + ":");      System.out.print("    ");      AnalyzerUtils.displayTokens(analyzer, text);      System.out.println("\n");    }  } }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?