raminmjj commented on code in PR #571:
URL: https://github.com/apache/lucenenet/pull/571#discussion_r878235765


##########
src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianStemmer.cs:
##########
@@ -0,0 +1,118 @@
+// Lucene version compatibility level 4.8.1
+using Lucene.Net.Analysis.Util;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+
+namespace Lucene.Net.Analysis.Fa
+{
+    /*
+     * 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.
+     */
+
+    /// <summary>
+    /// Stemmer for Persian.
+    /// <para/>
+    /// Stemming is done in-place for efficiency, operating on a termbuffer.
+    /// <para/>
+    /// Stemming is defined as:
+    /// <list type="bullet">
+    ///     <item><description> Removal of attached definite article, 
conjunction, and prepositions.</description></item>
+    ///     <item><description> Stemming of common 
suffixes.</description></item>
+    /// </list>
+    /// </summary>
+    public class PersianStemmer
+    {
+        private const char ALEF = '\u0627';
+        private const char HEH = '\u0647';
+        private const char TEH = '\u062A';
+        private const char REH = '\u0631';
+        private const char NOON = '\u0646';
+        private const char YEH = '\u064A';
+        private const char ZWNJ = '\u200c'; // ZERO WIDTH NON-JOINER character
+
+        // LUCENENET: Avoid static constructors (see 
https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
+        public static IList<char[]> Suffixes { get; } = InitializeSuffix();
+
+        private static IList<char[]> InitializeSuffix()
+        {
+            return new JCG.List<char[]>(){
+                ("" + ALEF + TEH).ToCharArray(),
+                ("" + ALEF + NOON).ToCharArray(),
+                ("" + TEH + REH + YEH + NOON).ToCharArray(),
+                ("" + TEH + REH).ToCharArray(),
+                ("" + YEH + YEH).ToCharArray(),
+                ("" + YEH).ToCharArray(),
+                ("" + HEH + ALEF).ToCharArray(),
+                ("" + ZWNJ).ToCharArray()
+            };
+        }
+
+        /// <summary>
+        /// Stem an input buffer of Persian text.
+        /// </summary>
+        /// <param name="s"> input buffer </param>
+        /// <param name="len"> length of input buffer </param>
+        /// <returns> length of input buffer after normalization </returns>
+        public virtual int Stem(char[] s, int len)
+        {
+            len = StemSuffix(s, len);
+
+            return len;
+        }
+
+        /// <summary>
+        /// Stem suffix(es) off an Persian word. </summary>
+        /// <param name="s"> input buffer </param>
+        /// <param name="len"> length of input buffer </param>
+        /// <returns> new length of input buffer after stemming </returns>
+        public virtual int StemSuffix(char[] s, int len)
+        {
+            for (int i = 0; i < Suffixes.Count; i++)
+            {
+                if (EndsWithCheckLength(s, len, Suffixes[i]))
+                {
+                    len = StemmerUtil.DeleteN(s, len - Suffixes[i].Length, 
len, Suffixes[i].Length);
+                }
+            }
+            return len;
+        }
+
+        /// <summary>
+        /// Returns true if the suffix matches and can be stemmed </summary>
+        /// <param name="s"> input buffer </param>
+        /// <param name="len"> length of input buffer </param>
+        /// <param name="suffix"> suffix to check </param>
+        /// <returns> true if the suffix matches and can be stemmed </returns>
+        internal virtual bool EndsWithCheckLength(char[] s, int len, char[] 
suffix)
+        {
+            if (len < suffix.Length + 2) // all suffixes require at least 2 
characters after stemming
+            {
+                return false;
+            }
+            else
+            {
+                for (int i = 0; i < suffix.Length; i++)

Review Comment:
   Sorry, but the "Equals" method is not compatible with the Java version.
   The Java version allows us to set the start index for the source and 
destination arrays, as well as the length for the destination.



-- 
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: dev-unsubscr...@lucenenet.apache.org

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

Reply via email to