In this thread가 나는 해결책을 받았다 : 시작점으로 루씬의 CachingTokenFilter를 사용
솔루션이 실제로 갈 수있는 올바른 방법이었다.
편집 : 죽은 링크가 수정되었습니다. 다음은 스레드의 사본입니다.
내 질문 : 새로운 TokenStream API와 "중지 문구 필터"를 구현하기 위해 노력하고있어
.
내가 N에 엿볼 수 있도록하고 싶습니다 현재 토큰 + N 다음 토큰은 "문구를 정지"(정지 문구 HashSet에 저장됩니다의 집합을) 일치하는 경우 모두 폐기 한 후, 참조 앞서 토큰 이 토큰은 스톱 구문과 일치하거나 일치하지 않는 경우 모두 유지합니다.
이 목적을 위해 나는 스트림의 시작점으로 돌아 가기 위해 captureState()와 restoreState() 을 사용하고 싶습니다.
나는이 API의 많은 조합을 시도했다. 내 마지막 시도는 코드 아래에 있는데 작동하지 않습니다.
static private HashSet<String> m_stop_phrases = new HashSet<String>();
static private int m_max_stop_phrase_length = 0;
...
public final boolean incrementToken() throws IOException {
if (!input.incrementToken())
return false;
Stack<State> stateStack = new Stack<State>();
StringBuilder match_string_builder = new StringBuilder();
int skippedPositions = 0;
boolean is_next_token = true;
while (is_next_token && match_string_builder.length() < m_max_stop_phrase_length) {
if (match_string_builder.length() > 0)
match_string_builder.append(" ");
match_string_builder.append(termAtt.term());
skippedPositions += posIncrAtt.getPositionIncrement();
stateStack.push(captureState());
is_next_token = input.incrementToken();
if (m_stop_phrases.contains(match_string_builder.toString())) {
// Stop phrase is found: skip the number of tokens
// without restoring the state
posIncrAtt.setPositionIncrement(posIncrAtt.getPositionIncrement() + skippedPositions);
return is_next_token;
}
}
// No stop phrase found: restore the stream
while (!stateStack.empty())
restoreState(stateStack.pop());
return true;
}
내는 " 문구를 정지"구현하는 조사해야 올바른 방향으로 필터링되어
?
정답 :
restoreState은 토큰의 내용이 아니라 전체 스트림을 복원합니다. 따라서 토큰 스트림을 롤백 할 수 없습니다 (이전 API 인 에서는 불가능 함). 코드 끝에서 while 루프는 exspect와 같이 작동하지 않습니다. 다시 작업 할 소스로 으로 다시 설정하여 다시 사용할 수있는 CachingTokenFilter를 사용할 수 있습니다.
그것이 링크 해답이 나쁜 이유입니다. 링크가 지금 죽었어. – Mysterion
@Mysterion은 죽은 링크를 수정하고 링크의 향후 문제를 피하기 위해 스레드 내용의 사본을보고했습니다. –