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 static org.apache.lucene.analysis.util.StemmerUtil.*;
23 * Normalizer for Arabic.
25 * Normalization is done in-place for efficiency, operating on a termbuffer.
27 * Normalization is defined as:
29 * <li> Normalization of hamza with alef seat to a bare alef.
30 * <li> Normalization of teh marbuta to heh
31 * <li> Normalization of dotless yeh (alef maksura) to yeh.
32 * <li> Removal of Arabic diacritics (the harakat)
33 * <li> Removal of tatweel (stretching character).
37 public class ArabicNormalizer {
38 public static final char ALEF = '\u0627';
39 public static final char ALEF_MADDA = '\u0622';
40 public static final char ALEF_HAMZA_ABOVE = '\u0623';
41 public static final char ALEF_HAMZA_BELOW = '\u0625';
43 public static final char YEH = '\u064A';
44 public static final char DOTLESS_YEH = '\u0649';
46 public static final char TEH_MARBUTA = '\u0629';
47 public static final char HEH = '\u0647';
49 public static final char TATWEEL = '\u0640';
51 public static final char FATHATAN = '\u064B';
52 public static final char DAMMATAN = '\u064C';
53 public static final char KASRATAN = '\u064D';
54 public static final char FATHA = '\u064E';
55 public static final char DAMMA = '\u064F';
56 public static final char KASRA = '\u0650';
57 public static final char SHADDA = '\u0651';
58 public static final char SUKUN = '\u0652';
61 * Normalize an input buffer of Arabic text
63 * @param s input buffer
64 * @param len length of input buffer
65 * @return length of input buffer after normalization
67 public int normalize(char s[], int len) {
69 for (int i = 0; i < len; i++) {
72 case ALEF_HAMZA_ABOVE:
73 case ALEF_HAMZA_BELOW:
91 len = delete(s, i, len);