@@ -65,6 +65,9 @@ private List<Weighted<Root<String>>> findSimilarDictionaryEntries(
65
65
String word , WordCase originalCase ) {
66
66
Comparator <Weighted <Root <String >>> natural = Comparator .naturalOrder ();
67
67
PriorityQueue <Weighted <Root <String >>> roots = new PriorityQueue <>(natural .reversed ());
68
+ List <Root <String >> entries = new ArrayList <>();
69
+ boolean ignoreTitleCaseRoots = originalCase == WordCase .LOWER && !dictionary .hasLanguage ("de" );
70
+ EnumSet <NGramOptions > options = EnumSet .of (NGramOptions .LONGER_WORSE );
68
71
69
72
IntsRefFSTEnum <IntsRef > fstEnum = new IntsRefFSTEnum <>(dictionary .words );
70
73
InputOutput <IntsRef > mapping ;
@@ -78,18 +81,15 @@ private List<Weighted<Root<String>>> findSimilarDictionaryEntries(
78
81
}
79
82
80
83
String root = toString (key );
81
- List < Root < String >> entries = filterSuitableEntries (root , mapping .output );
84
+ filterSuitableEntries (root , mapping .output , entries );
82
85
if (entries .isEmpty ()) continue ;
83
86
84
- if (originalCase == WordCase .LOWER
85
- && WordCase .caseOf (root ) == WordCase .TITLE
86
- && !dictionary .hasLanguage ("de" )) {
87
+ if (ignoreTitleCaseRoots && WordCase .caseOf (root ) == WordCase .TITLE ) {
87
88
continue ;
88
89
}
89
90
90
91
String lower = dictionary .toLowerCase (root );
91
- int sc =
92
- ngram (3 , word , lower , EnumSet .of (NGramOptions .LONGER_WORSE )) + commonPrefix (word , root );
92
+ int sc = ngram (3 , word , lower , options ) + commonPrefix (word , root );
93
93
94
94
if (roots .size () == MAX_ROOTS && sc < roots .peek ().score ) {
95
95
continue ;
@@ -129,8 +129,8 @@ private static String toString(IntsRef key) {
129
129
return new String (chars );
130
130
}
131
131
132
- private List < Root < String >> filterSuitableEntries (String word , IntsRef forms ) {
133
- List < Root < String >> result = new ArrayList <> ();
132
+ private void filterSuitableEntries (String word , IntsRef forms , List < Root < String >> result ) {
133
+ result . clear ();
134
134
for (int i = 0 ; i < forms .length ; i += dictionary .formStep ()) {
135
135
int entryId = forms .ints [forms .offset + i ];
136
136
if (dictionary .hasFlag (entryId , dictionary .forbiddenword )
@@ -141,8 +141,6 @@ private List<Root<String>> filterSuitableEntries(String word, IntsRef forms) {
141
141
}
142
142
result .add (new Root <>(word , entryId ));
143
143
}
144
-
145
- return result ;
146
144
}
147
145
148
146
private List <Weighted <String >> expandRoots (
0 commit comments