add builder method for setting word transitions
This commit is contained in:
parent
a646f233a5
commit
4be3e115b6
@ -222,6 +222,8 @@ public class Trie {
|
|||||||
private final TrieConfig trieConfig = new TrieConfig();
|
private final TrieConfig trieConfig = new TrieConfig();
|
||||||
|
|
||||||
private final Trie trie = new Trie(trieConfig);
|
private final Trie trie = new Trie(trieConfig);
|
||||||
|
|
||||||
|
private boolean hasAddedKeyword = false;
|
||||||
|
|
||||||
private TrieBuilder() {}
|
private TrieBuilder() {}
|
||||||
|
|
||||||
@ -240,11 +242,21 @@ public class Trie {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrieBuilder addKeyword(String keyword) {
|
public TrieBuilder wordTransitions() {
|
||||||
trie.addKeyword(keyword);
|
if (hasAddedKeyword) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unable to switch to word transitions after keywords added");
|
||||||
|
}
|
||||||
|
this.trieConfig.setWordTransitions(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TrieBuilder addKeyword(String keyword) {
|
||||||
|
trie.addKeyword(keyword);
|
||||||
|
hasAddedKeyword = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Trie build() {
|
public Trie build() {
|
||||||
trie.constructFailureStates();
|
trie.constructFailureStates();
|
||||||
return trie;
|
return trie;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user