59
59
* Rules are typically loaded from resource files. These are UTF-8 encoded text files. They are systematically
60
60
* named following the pattern:
61
61
* </p>
62
- * <blockquote>org/apache/commons/codec/language/bm/${NameType#getName}_${RuleType#getName}_${language}.txt</blockquote>
62
+ * <blockquote>/ org/apache/commons/codec/language/bm/${NameType#getName}_${RuleType#getName}_${language}.txt</blockquote>
63
63
* <p>
64
64
* The format of these resources is the following:
65
65
* </p>
84
84
*/
85
85
public class Rule {
86
86
87
+ /**
88
+ * A phoneme.
89
+ */
87
90
public static final class Phoneme implements PhonemeExpr {
88
91
92
+ /**
93
+ * The Phoneme Comparator.
94
+ */
89
95
public static final Comparator <Phoneme > COMPARATOR = (o1 , o2 ) -> {
90
96
final int o1Length = o1 .phonemeText .length ();
91
97
final int o2Length = o2 .phonemeText .length ();
@@ -105,30 +111,61 @@ public static final class Phoneme implements PhonemeExpr {
105
111
106
112
return 0 ;
107
113
};
114
+
108
115
private final StringBuilder phonemeText ;
109
116
110
117
private final Languages .LanguageSet languages ;
111
118
119
+ /**
120
+ * Constructs a new instance.
121
+ *
122
+ * @param phonemeText The phoneme text.
123
+ * @param languages A language set.
124
+ */
112
125
public Phoneme (final CharSequence phonemeText , final Languages .LanguageSet languages ) {
113
126
this .phonemeText = new StringBuilder (phonemeText );
114
127
this .languages = languages ;
115
128
}
116
129
130
+ /**
131
+ * Constructs a new instance.
132
+ *
133
+ * @param phonemeLeft The left phoneme text.
134
+ * @param phonemeRight The right phoneme text.
135
+ */
117
136
public Phoneme (final Phoneme phonemeLeft , final Phoneme phonemeRight ) {
118
137
this (phonemeLeft .phonemeText , phonemeLeft .languages );
119
138
this .phonemeText .append (phonemeRight .phonemeText );
120
139
}
121
140
141
+ /**
142
+ * Constructs a new instance.
143
+ *
144
+ * @param phonemeLeft The left phoneme text.
145
+ * @param phonemeRight The right phoneme text.
146
+ * @param languages A language set.
147
+ */
122
148
public Phoneme (final Phoneme phonemeLeft , final Phoneme phonemeRight , final Languages .LanguageSet languages ) {
123
149
this (phonemeLeft .phonemeText , languages );
124
150
this .phonemeText .append (phonemeRight .phonemeText );
125
151
}
126
152
127
- public Phoneme append (final CharSequence str ) {
128
- this .phonemeText .append (str );
153
+ /**
154
+ * Appends the sequence to the phone text.
155
+ *
156
+ * @param sequence The sequence to append.
157
+ * @return this instance.
158
+ */
159
+ public Phoneme append (final CharSequence sequence ) {
160
+ this .phonemeText .append (sequence );
129
161
return this ;
130
162
}
131
163
164
+ /**
165
+ * Gets the language set.
166
+ *
167
+ * @return the language set.
168
+ */
132
169
public Languages .LanguageSet getLanguages () {
133
170
return this .languages ;
134
171
}
@@ -138,6 +175,11 @@ public Iterable<Phoneme> getPhonemes() {
138
175
return Collections .singleton (this );
139
176
}
140
177
178
+ /**
179
+ * Gets the phoneme text sequence.
180
+ *
181
+ * @return the phoneme text sequence.
182
+ */
141
183
public CharSequence getPhonemeText () {
142
184
return this .phonemeText ;
143
185
}
@@ -177,7 +219,16 @@ public String toString() {
177
219
}
178
220
}
179
221
222
+ /**
223
+ * A phoneme expression.
224
+ */
180
225
public interface PhonemeExpr {
226
+
227
+ /**
228
+ * Gets an iteration of phonemes.
229
+ *
230
+ * @return an iteration of phonemes.
231
+ */
181
232
Iterable <Phoneme > getPhonemes ();
182
233
183
234
/**
@@ -192,10 +243,18 @@ default int size() {
192
243
}
193
244
}
194
245
246
+ /**
247
+ * A list of phonemes.
248
+ */
195
249
public static final class PhonemeList implements PhonemeExpr {
196
250
197
251
private final List <Phoneme > phonemeList ;
198
252
253
+ /**
254
+ * Constructs a new instance.
255
+ *
256
+ * @param phonemes the phoneme list.
257
+ */
199
258
public PhonemeList (final List <Phoneme > phonemes ) {
200
259
this .phonemeList = phonemes ;
201
260
}
@@ -215,11 +274,24 @@ public int size() {
215
274
* A minimal wrapper around the functionality of Pattern that we use, to allow for alternate implementations.
216
275
*/
217
276
public interface RPattern {
277
+
278
+ /**
279
+ * Tests whether the given input matches this instance.
280
+ *
281
+ * @param input the input to test.
282
+ * @return whether the given input matches this instance.
283
+ */
218
284
boolean isMatch (CharSequence input );
219
285
}
220
286
287
+ /**
288
+ * Always matches.
289
+ */
221
290
public static final RPattern ALL_STRINGS_RMATCHER = input -> true ;
222
291
292
+ /**
293
+ * Unused.
294
+ */
223
295
public static final String ALL = "ALL" ;
224
296
225
297
private static final String DOUBLE_QUOTE = "\" " ;
0 commit comments