LuceneAnalyzer.java
01 /*
02  *  LuceneAnalyzer.java
03  *
04  *  Niraj Aswani, 19/March/07
05  *
06  *  $Id: LuceneAnalyzer.html,v 1.0 2007/03/19 16:22:01 niraj Exp $
07  */
08 package gate.creole.annic.lucene;
09 
10 import gate.creole.annic.apache.lucene.analysis.*;
11 import gate.util.GateRuntimeException;
12 
13 import java.io.*;
14 
15 /**
16  * This class provides an implementation for Analyzer which is used
17  * internally by ANNIC resources.
18  
19  @author niraj
20  
21  */
22 public class LuceneAnalyzer extends Analyzer {
23 
24   /**
25    * Each analyzer is required to provide implementation of this method.
26    * Using the provided reader, which in this case must be an instance
27    * of LuceneReader, it obtains the tokenStream and wrap it in the
28    * instanceof LuceneTokenizer. It is this instance that is returned to
29    * the user.
30    */
31   public TokenStream tokenStream(String fieldName, Reader reader) {
32     try {
33       if(reader instanceof LuceneReader) {
34         if(fieldName.equals("contents")) {
35           LuceneReader gr = (LuceneReader)reader;
36           try {
37             TokenStream result = new LuceneTokenizer(gr.getTokenStream());
38             return result;
39           }
40           catch(Exception e) {
41             e.printStackTrace();
42           }
43 
44         }
45         else {
46           new gate.creole.annic.apache.lucene.analysis.standard.StandardTokenizer(
47                   reader);
48         }
49       }
50     }
51     catch(Exception e) {
52       throw new GateRuntimeException(e);
53     }
54     return null;
55   }
56 }