From 28214ad770f6690b115ba8609deec7f0c360b364 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Mon, 30 Jan 2023 09:37:15 +0100 Subject: [PATCH] Remove unnecessary toLowerCase in isStopWord --- .../marginalia/util/language/WordPatterns.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/marginalia_nu/src/main/java/nu/marginalia/util/language/WordPatterns.java b/marginalia_nu/src/main/java/nu/marginalia/util/language/WordPatterns.java index 4766706e..c2fc0045 100644 --- a/marginalia_nu/src/main/java/nu/marginalia/util/language/WordPatterns.java +++ b/marginalia_nu/src/main/java/nu/marginalia/util/language/WordPatterns.java @@ -1,5 +1,7 @@ package nu.marginalia.util.language; +import org.apache.commons.lang3.StringUtils; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -123,14 +125,24 @@ public class WordPatterns { if (!filter(s)) { return true; } - if (isTopWord(s)) { + + String sLc; + if (StringUtils.isAllLowerCase(s)) { + sLc = s; + } + else { + sLc = s.toLowerCase(); + } + + if (isTopWord(sLc)) { return true; } + return false; } - public static boolean isTopWord(String s) { - return topWords.contains(s.toLowerCase()); + public static boolean isTopWord(String strLowerCase) { + return topWords.contains(strLowerCase); } }