gate.creole.annic.lucene.LuceneAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gate-core Show documentation
Show all versions of gate-core Show documentation
GATE - general achitecture for text engineering - is open source
software capable of solving almost any text processing problem. This
artifact enables you to embed the core GATE Embedded with its essential
dependencies. You will able to use the GATE Embedded API and load and
store GATE XML documents. This artifact is the perfect dependency for
CREOLE plugins or for applications that need to customize the GATE
dependencies due to confict with their own dependencies or for lower
footprint.
The newest version!
/*
* LuceneAnalyzer.java
*
* Niraj Aswani, 19/March/07
*
* $Id: LuceneAnalyzer.html,v 1.0 2007/03/19 16:22:01 niraj Exp $
*/
package gate.creole.annic.lucene;
import gate.creole.annic.apache.lucene.analysis.*;
import gate.util.GateRuntimeException;
import java.io.*;
/**
* This class provides an implementation for Analyzer which is used
* internally by ANNIC resources.
*
* @author niraj
*
*/
public class LuceneAnalyzer extends Analyzer {
/**
* Each analyzer is required to provide implementation of this method.
* Using the provided reader, which in this case must be an instance
* of LuceneReader, it obtains the tokenStream and wrap it in the
* instanceof LuceneTokenizer. It is this instance that is returned to
* the user.
*/
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
try {
if(reader instanceof LuceneReader) {
if(fieldName.equals("contents")) {
LuceneReader gr = (LuceneReader)reader;
try {
TokenStream result = new LuceneTokenizer(gr.getTokenStream());
return result;
}
catch(Exception e) {
e.printStackTrace();
}
}
else {
new gate.creole.annic.apache.lucene.analysis.standard.StandardTokenizer(
reader);
}
}
}
catch(Exception e) {
throw new GateRuntimeException(e);
}
return null;
}
}