mawiesne commented on code in PR #1163:
URL: https://github.com/apache/opennlp/pull/1163#discussion_r3612072102


##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/PorterStemmerFactory.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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 opennlp.tools.stemmer;
+
+import opennlp.tools.commons.ThreadSafe;
+
+/**
+ * A thread-safe factory for {@link PorterStemmer} instances.
+ */
+@ThreadSafe
+public record PorterStemmerFactory() implements StemmerFactory {

Review Comment:
   Why is this factory a record? It seems odd to me. Lets make this a simple 
class instead.



##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/DelegatingStemmer.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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 opennlp.tools.stemmer;
+
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import opennlp.tools.util.OwnerOrPerThreadState;
+
+/**
+ * Shared plumbing for {@link Stemmer} wrappers that route each call to a 
per-thread payload minted
+ * from a {@link StemmerFactory}, following the {@link OwnerOrPerThreadState} 
pattern of the
+ * thread-safe {@code *ME} components. Subclasses differ only in the payload 
they carry per thread
+ * and in what {@link #stem(CharSequence)} does with it.
+ *
+ * @param <P> the per-thread payload: a bare delegate stemmer, or a delegate 
paired with per-thread
+ *     working state such as a cache.
+ */
+abstract class DelegatingStemmer<P> implements Stemmer {
+
+  /** The per-thread payload holder. */
+  final OwnerOrPerThreadState<P> state;

Review Comment:
   Please check if this field can be declared protected. If so, change it 
accordingly.



##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/snowball/SnowballStemmerFactory.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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 opennlp.tools.stemmer.snowball;
+
+import opennlp.tools.commons.ThreadSafe;
+import opennlp.tools.stemmer.Stemmer;
+import opennlp.tools.stemmer.StemmerFactory;
+
+/**
+ * A thread-safe factory that captures a Snowball stemmer configuration for 
APIs that accept a
+ * {@link StemmerFactory}.
+ *
+ * <p>Use this factory for the classic one-stemmer-per-thread pattern: {@link 
#newStemmer()}
+ * returns a plain, thread-confined stemmer without the per-call thread 
routing of the
+ * shareable {@link SnowballStemmer}.</p>
+ *
+ * @param algorithm The Snowball algorithm. Must not be {@code null}.
+ * @param repeat    How many times to apply the stemmer per word; must be 
positive.
+ */
+@ThreadSafe
+public record SnowballStemmerFactory(SnowballStemmer.ALGORITHM algorithm, int 
repeat)

Review Comment:
   Why is this factory a record? It seems odd to me. Lets make this a class 
instead.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to