官术网_书友最值得收藏!

Obtaining a TokenStream

TokenStream is an intermediate data format between components within the analysis process. TokenStream acts as both an input and output format in all filters. For tokenizer, it consumes text from a reader and outputs result as TokenStream. Let's explore TokenStream in detail in this section.

Getting ready

The Analyzer class is an abstract base class containing two methods of interest. The first one is createComponents (String fieldname, Reader reader). This is where the analyzer is put together by chaining the tokenizer and filters. The second method is tokenStream (String fieldname, Reader reader). This is the method we will review in this section. We will use the tokenStream method to return a processed TokenStream so we can examine its content after the analysis process.

How to do it...

We need two arguments to call the tokenStream method. The first is a field name and the second is a reader:

Reader reader = new StringReader("Text to be passed");
Analyzer analyzer = new SimpleAnalyzer();
TokenStream tokenStream = analyzer.tokenStream("myField", reader);

How it works…

An analyzer processes incoming text via a Reader input. Internally, the Reader is passed on to Tokenizer, which turns the text into a TokenStream after it's been processed. From here on, TokenStream is passed around between filters in every step. TokenStream is essentially an enumeration of tokens that you can iterate through. TokenStream extends from AttributeSource and it provides an interface to return token attributes and value.

主站蜘蛛池模板: 三原县| 普宁市| 桃园市| 夏邑县| 尉氏县| 鸡西市| 和政县| 怀集县| 伊宁市| 赤壁市| 峨边| 云阳县| 隆尧县| 江门市| 招远市| 青海省| 广昌县| 乌苏市| 盐城市| 株洲市| 晋州市| 宁武县| 林州市| 喀喇沁旗| 惠东县| 梅州市| 墨竹工卡县| 宜兴市| 蒙山县| 马关县| 普兰县| 安新县| 仁怀市| 通辽市| 乌兰浩特市| 河南省| 色达县| 屏山县| 中阳县| 岳普湖县| 金秀|