fix the off by ones

This commit is contained in:
Douglas Lovell 2015-10-29 15:29:44 -06:00
parent 7514478a65
commit dd5f9b25fa

View File

@ -65,7 +65,6 @@ public class Trie {
t = new CharacterTransition(cur); t = new CharacterTransition(cur);
cur = ct.next(); cur = ct.next();
} }
return t; return t;
} }
} }
@ -105,7 +104,7 @@ public class Trie {
} }
public int position() { public int position() {
return match.length(); return match.length() - 1;
} }
public boolean isWholeWord(int start) { public boolean isWholeWord(int start) {
@ -113,7 +112,7 @@ public class Trie {
lookahead = kwt.nextTransition(); lookahead = kwt.nextTransition();
} }
return ((start == 0 || return ((start == 0 ||
Character.isSpaceChar(match.codePointAt(start))) && Character.isSpaceChar(match.codePointAt(start-1))) &&
(lookahead == null || lookahead.isWordSeparator())); (lookahead == null || lookahead.isWordSeparator()));
} }
} }
@ -182,7 +181,7 @@ public class Trie {
Collection<String> emits = currentState.emit(); Collection<String> emits = currentState.emit();
for (String emit : emits) { for (String emit : emits) {
int position = tknz.position(); int position = tknz.position();
int start = tknz.position() - emit.length() + 1; int start = position - emit.length() + 1;
boolean isWholeWord = tknz.isWholeWord(start); boolean isWholeWord = tknz.isWholeWord(start);
if (isWholeWord || !trieConfig.isOnlyWholeWords()) { if (isWholeWord || !trieConfig.isOnlyWholeWords()) {
emitCandidateHolder.addCandidate( emitCandidateHolder.addCandidate(