2012-11-21 3 views
0

나는 약 ngrams를 컴파일하고자하는 약 500 문장이 있습니다. 정지 단어를 제거하는 데 문제가 있습니다. lucene StandardFilter와 StopFilter를 추가하려고 시도했지만 여전히 같은 문제가 있습니다.Java Lucene Stop Words 필터

for(String curS: Sentences) 
{ 
      reader = new StringReader(curS); 
      tokenizer = new StandardTokenizer(Version.LUCENE_36, reader); 
      tokenizer = new StandardFilter(Version.LUCENE_36, tokenizer); 
      tokenizer = new StopFilter(Version.LUCENE_36, tokenizer, stopWords); 
      tokenizer = new ShingleFilter(tokenizer, 2, 3); 
      charTermAttribute = tokenizer.addAttribute(CharTermAttribute.class); 

    while(tokenizer.incrementToken()) 
    { 
     curNGram = charTermAttribute.toString().toString(); 
     nGrams.add(curNGram);     //store each token into an ArrayList 
    } 
} 

예를 들어, 내가 테스트하고 첫 구절은 다음과 같습니다 : "에 수신 모든 사람은"여기 내 코드입니다. 이 예에서 curNGram은 "For"로 설정되어 있는데, 이는 내 목록 stopWords에서 정지 단어입니다. 또한이 예제에서 "every"는 중지 단어이므로 "person"이 첫 번째 ngram이어야합니다.

  1. StopFiler를 사용할 때 왜 내 단어가 내 목록에 추가됩니까?

모든 도움을 주실 수 있습니다!

+0

stopWords 생성 방법은 무엇입니까? [StopFilter.makeStopSet] (http://lucene.apache.org/core/3_6_0/api/all/org/apache/lucene/analysis/StopFilter.html#makeStopSet (org.apache.lucene.util))을 사용하여 생성합니까? .Version, % 20java.util.List, % 20boolean))? – femtoRgon

+0

정적 함수를 사용하여 줄 단위로 txt 파일을 읽었습니다. – CodeKingPlusPlus

답변

1

내게 올린 내용은 괜찮아 보입니다. 따라서 stopWords가 원하는 정보를 필터에 제공하지 않는 것으로 의심됩니다. 당신이하지 생각처럼,이 제품에 사용할 수있는 형식으로 넣어해야 보인다 목록이 생성 중지 단어 (I '는 말을'이라는 한 것)의 당신을 가정

//Let's say we read the stop words into an array list (A simple array, or any list implementation should be fine) 
List<String> words = new ArrayList(); 
//Read the file into words. 
Set stopWords = StopFilter.makeStopSet(Version.LUCENE_36, words, true); 

:

같은 시도 StopFilter.

이미 stopWords를 생성하셨습니까?

+0

이것은 내 출력 중 일부에 대해 작동하는 것으로 보입니다. 단 하나의 단어를 제외하고는 같은 단어가 나오기 때문에 밑줄이나 밑줄이 하나 더 생깁니다. 예를 들어, USA, USA_, USA__를 모두 구별되는 값으로 가져옵니다. – CodeKingPlusPlus

+0

API에서 ShingleFilter의 의도 된 동작입니다 : "이 필터는 필러 토큰 (termtext"_ "이있는 토큰)을 삽입하여 위치 증분> 1을 처리하며 0의 위치 증분을 처리하지 않습니다. 이것은 단어가 중지 필터에 의해 제거 되었기 때문에 ShingleFilter가 그 위치를 유지합니다. – femtoRgon

+0

원한다면 stopfilter.setEnablePositionIncrements (false)로 비활성화 할 수 있다고 생각합니다. – femtoRgon