1 package org.apache.lucene.analysis.ar;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import java.io.StringReader;
23 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
24 import org.apache.lucene.analysis.CharArraySet;
25 import org.apache.lucene.analysis.KeywordMarkerFilter;
28 * Test the Arabic Normalization Filter
31 public class TestArabicStemFilter extends BaseTokenStreamTestCase {
33 public void testAlPrefix() throws IOException {
34 check("الحسن", "حسن");
37 public void testWalPrefix() throws IOException {
38 check("والحسن", "حسن");
41 public void testBalPrefix() throws IOException {
42 check("بالحسن", "حسن");
45 public void testKalPrefix() throws IOException {
46 check("كالحسن", "حسن");
49 public void testFalPrefix() throws IOException {
50 check("فالحسن", "حسن");
53 public void testLlPrefix() throws IOException {
54 check("للاخر", "اخر");
57 public void testWaPrefix() throws IOException {
61 public void testAhSuffix() throws IOException {
62 check("زوجها", "زوج");
65 public void testAnSuffix() throws IOException {
66 check("ساهدان", "ساهد");
69 public void testAtSuffix() throws IOException {
70 check("ساهدات", "ساهد");
73 public void testWnSuffix() throws IOException {
74 check("ساهدون", "ساهد");
77 public void testYnSuffix() throws IOException {
78 check("ساهدين", "ساهد");
81 public void testYhSuffix() throws IOException {
82 check("ساهديه", "ساهد");
85 public void testYpSuffix() throws IOException {
86 check("ساهدية", "ساهد");
89 public void testHSuffix() throws IOException {
90 check("ساهده", "ساهد");
93 public void testPSuffix() throws IOException {
94 check("ساهدة", "ساهد");
97 public void testYSuffix() throws IOException {
98 check("ساهدي", "ساهد");
101 public void testComboPrefSuf() throws IOException {
102 check("وساهدون", "ساهد");
105 public void testComboSuf() throws IOException {
106 check("ساهدهات", "ساهد");
109 public void testShouldntStem() throws IOException {
113 public void testNonArabic() throws IOException {
114 check("English", "English");
117 public void testWithKeywordAttribute() throws IOException {
118 CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
120 ArabicLetterTokenizer tokenStream = new ArabicLetterTokenizer(TEST_VERSION_CURRENT, new StringReader("ساهدهات"));
122 ArabicStemFilter filter = new ArabicStemFilter(new KeywordMarkerFilter(tokenStream, set));
123 assertTokenStreamContents(filter, new String[]{"ساهدهات"});
126 private void check(final String input, final String expected) throws IOException {
127 ArabicLetterTokenizer tokenStream = new ArabicLetterTokenizer(TEST_VERSION_CURRENT, new StringReader(input));
128 ArabicStemFilter filter = new ArabicStemFilter(tokenStream);
129 assertTokenStreamContents(filter, new String[]{expected});