Issue #7 Ignore keywords in the trie that are null or empty
This commit is contained in:
parent
a4fcfe8f20
commit
d7421ead0f
@ -47,6 +47,9 @@ public class Trie {
|
||||
}
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
if (keyword == null || keyword.length() == 0) {
|
||||
return;
|
||||
}
|
||||
State currentState = this.rootState;
|
||||
for (Character character : keyword.toCharArray()) {
|
||||
currentState = currentState.addState(character);
|
||||
|
||||
@ -193,6 +193,19 @@ public class TrieTest {
|
||||
assertEquals(5, tokens.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroLengthTestBug7InGithubReportedByXCurry() {
|
||||
Trie trie = new Trie().removeOverlaps().onlyWholeWords().caseInsensitive();
|
||||
trie.addKeyword("");
|
||||
|
||||
Collection<Token> tokens = trie.tokenize("Try a natural lip and subtle bronzer to keep all the focus on those big bright eyes with NARS Eyeshadow Duo in Rated R And the winner is... Boots No7 Advanced Renewal Anti-ageing Glycolic Peel Kit ($25 amazon.com) won most-appealing peel.");
|
||||
for (Token token : tokens) {
|
||||
if (!token.isMatch()) {
|
||||
System.out.println("token: " + token.getFragment());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEmit(Emit next, int expectedStart, int expectedEnd, String expectedKeyword) {
|
||||
assertEquals(expectedStart, next.getStart());
|
||||
assertEquals(expectedEnd, next.getEnd());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user