Skip to content

Commit

Permalink
OPENNLP-1701: Re-generates Snowball Stemmer Code (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 authored Jan 26, 2025
1 parent 4839a21 commit 6daacd3
Show file tree
Hide file tree
Showing 24 changed files with 750 additions and 580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package opennlp.tools.stemmer.snowball;

/**
* Parent class of all snowball stemmers, which must implement <code>stem</code>
*/
abstract class AbstractSnowballStemmer extends SnowballProgram {
public abstract boolean stem();

static final long serialVersionUID = 2016072500L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*/

// Generated by Snowball (build from 867c4ec70debd4daa7fb4d5a9f7759b47887d0b9)
// Generated by Snowball (build from 9a22f0d3f44cda36677829328fe2642750114d57)
package opennlp.tools.stemmer.snowball;

import java.lang.reflect.Method;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Locale;

/**
* Internal class used by Snowball stemmers
*/
public class Among {
public final char[] s; /* search string */
public final int substring_i; /* index to longest matching substring */
public final int result; /* result of the lookup */
public final Method method; /* method to use if substring matches */

public Among(String s, int substring_i, int result) {
this.s = s.toCharArray();
this.substring_i = substring_i;
Expand All @@ -49,14 +50,30 @@ public Among(String s, int substring_i, int result) {
}

public Among(String s, int substring_i, int result, String methodname,
Class<? extends AbstractSnowballStemmer> programclass) {
MethodHandles.Lookup methodobject) {
this.s = s.toCharArray();
this.substring_i = substring_i;
this.result = result;
try {
this.method = programclass.getDeclaredMethod(methodname);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
final Class<? extends SnowballProgram> clazz = methodobject.lookupClass().asSubclass(SnowballProgram.class);
if (methodname.length() > 0) {
try {
this.method = methodobject.findVirtual(clazz, methodname, MethodType.methodType(boolean.class))
.asType(MethodType.methodType(boolean.class, SnowballProgram.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException(String.format(Locale.ENGLISH,
"Snowball program '%s' is broken, cannot access method: boolean %s()",
clazz.getSimpleName(), methodname
), e);
}
} else {
this.method = null;
}
}
}

final char[] s; /* search string */
final int substring_i; /* index to longest matching substring */
final int result; /* result of the lookup */

// Make sure this is not accessible outside package for Java security reasons!
final MethodHandle method; /* method to use if substring matches */
};
Loading

0 comments on commit 6daacd3

Please sign in to comment.