Package opennlp.tools.stopword
Class DictionaryStopwordFilter.Builder
java.lang.Object
opennlp.tools.stopword.DictionaryStopwordFilter.Builder
- Enclosing class:
DictionaryStopwordFilter
Fluent builder for
DictionaryStopwordFilter. Accumulates
add / remove operations together with a case-sensitivity
setting; build() produces an immutable filter that reflects the
accumulated state.
Operations are applied at build() time in the order
"all adds, then all removes". Within each phase, insertion order is
preserved but is not externally observable.
-
Method Summary
Modifier and TypeMethodDescriptionAdds one entry (1-gram or n-gram).addAll(Collection<String[]> entries) Adds a bulk of entries.build()caseSensitive(boolean cs) load(InputStream in, Charset cs) Reads one-per-line stopword entries fromin(whitespace separates tokens of a multi-word entry; blank and#-prefixed lines are skipped) and schedules them for addition.Schedules removal of one entry (applied after all adds atbuild()time).removeAll(Collection<String[]> entries) Schedules a bulk of removals.
-
Method Details
-
caseSensitive
- Parameters:
cs- Whether the resulting filter performs case-sensitive matching. Defaults tofalse.- Returns:
- This builder.
-
add
Adds one entry (1-gram or n-gram).- Parameters:
tokens- The tokens forming the entry. Must not benullor empty.- Returns:
- This builder.
- Throws:
IllegalArgumentException- iftokensisnullor empty.
-
addAll
Adds a bulk of entries.- Parameters:
entries- The entries to add. Must not benull.- Returns:
- This builder.
- Throws:
IllegalArgumentException- ifentriesisnull, or if any element isnullor empty.
-
remove
Schedules removal of one entry (applied after all adds atbuild()time).- Parameters:
tokens- The tokens forming the entry to remove.- Returns:
- This builder.
- Throws:
IllegalArgumentException- iftokensisnullor empty.
-
removeAll
Schedules a bulk of removals.- Parameters:
entries- The entries to remove. Must not benull.- Returns:
- This builder.
- Throws:
IllegalArgumentException- ifentriesisnull, or if any element isnullor empty.
-
load
Reads one-per-line stopword entries fromin(whitespace separates tokens of a multi-word entry; blank and#-prefixed lines are skipped) and schedules them for addition.- Parameters:
in- The input stream to read from. Must not benull.cs- TheCharsetto decode with. Must not benull.- Returns:
- This builder.
- Throws:
IllegalArgumentException- ifinorcsisnull.IOException- If an IO error occurs while reading.
-
build
- Returns:
- A new immutable
DictionaryStopwordFilterreflecting the accumulated state.
-