mocobeta commented on code in PR #540:
URL: https://github.com/apache/lucene/pull/540#discussion_r866835280


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/fa/PersianStemmer.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.analysis.fa;
+
+import static org.apache.lucene.analysis.util.StemmerUtil.*;
+
+/**
+ * Stemmer for Persian.
+ *
+ * <p>Stemming is done in-place for efficiency, operating on a termbuffer.
+ *
+ * <p>Stemming is defined as:
+ *
+ * <ul>
+ *   <li>Removal of attached definite article, conjunction, and prepositions.
+ *   <li>Stemming of common suffixes.
+ * </ul>
+ */
+public class PersianStemmer {
+  public static final char ALEF = '\u0627';
+  public static final char HEH = '\u0647';
+  public static final char TEH = '\u062A';
+  public static final char REH = '\u0631';
+  public static final char NOON = '\u0646';
+  public static final char YEH = '\u064A';
+  public static final char ZWNJ = '\u200c';
+
+  public static final char[][] suffixes = {
+    ("" + ALEF + TEH).toCharArray(),
+    ("" + ALEF + NOON).toCharArray(),
+    ("" + TEH + REH + YEH + NOON).toCharArray(),
+    ("" + TEH + REH).toCharArray(),
+    ("" + YEH + YEH).toCharArray(),
+    ("" + YEH).toCharArray(),
+    ("" + HEH + ALEF).toCharArray(),
+    ("" + ZWNJ).toCharArray(),
+  };

Review Comment:
   Thanks for the pointer. I haven't noticed that.
   The original ArabicStemmer was added in 2010 and those `public static` 
constants seem unchanged since then. It's a bad practice in these days to 
unnecessarily expose constants/variables/methods; especially it isn't safe to 
expose the `suffixes` char array - it's substantially mutable, although this is 
marked as final.
   Please keep class members private as far as possible. I will open an issue 
for `ArabicStemmer` to make those members private.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to