1 package org.apache.lucene.analysis.miscellaneous;
3 import java.io.IOException;
4 import java.io.StringReader;
5 import java.util.HashMap;
8 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
9 import org.apache.lucene.analysis.KeywordTokenizer;
10 import org.apache.lucene.analysis.PorterStemFilter;
11 import org.apache.lucene.analysis.TokenStream;
12 import org.apache.lucene.analysis.Tokenizer;
15 * Licensed to the Apache Software Foundation (ASF) under one or more
16 * contributor license agreements. See the NOTICE file distributed with
17 * this work for additional information regarding copyright ownership.
18 * The ASF licenses this file to You under the Apache License, Version 2.0
19 * (the "License"); you may not use this file except in compliance with
20 * the License. You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS,
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
31 public class TestStemmerOverrideFilter extends BaseTokenStreamTestCase {
32 public void testOverride() throws IOException {
33 // lets make booked stem to books
34 // the override filter will convert "booked" to "books",
35 // but also mark it with KeywordAttribute so Porter will not change it.
36 Map<String,String> dictionary = new HashMap<String,String>();
37 dictionary.put("booked", "books");
38 Tokenizer tokenizer = new KeywordTokenizer(new StringReader("booked"));
39 TokenStream stream = new PorterStemFilter(
40 new StemmerOverrideFilter(TEST_VERSION_CURRENT, tokenizer, dictionary));
41 assertTokenStreamContents(stream, new String[] { "books" });