Search in sources :

Example 6 with StopFilter

use of org.apache.lucene.analysis.core.StopFilter in project cogcomp-nlp by CogComp.

the class MinimalAnalyzer method createComponents.

@Override
protected TokenStreamComponents createComponents(String fieldName) {
    final Tokenizer source = new StandardTokenizer();
    TokenStream result = new StandardFilter(source);
    result = new ASCIIFoldingFilter(result);
    result = new LowerCaseFilter(result);
    result = new EnglishPossessiveFilter(result);
    result = new StopFilter(result, stopwords);
    result = new WordDelimiterFilter(result, WordDelimiterFilter.ALPHA, null);
    result = new PorterStemFilter(result);
    return new TokenStreamComponents(source, result);
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) EnglishPossessiveFilter(org.apache.lucene.analysis.en.EnglishPossessiveFilter) WordDelimiterFilter(org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter) StandardTokenizer(org.apache.lucene.analysis.standard.StandardTokenizer) StopFilter(org.apache.lucene.analysis.core.StopFilter) StandardFilter(org.apache.lucene.analysis.standard.StandardFilter) PorterStemFilter(org.apache.lucene.analysis.en.PorterStemFilter) ASCIIFoldingFilter(org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter) Tokenizer(org.apache.lucene.analysis.Tokenizer) StandardTokenizer(org.apache.lucene.analysis.standard.StandardTokenizer) LowerCaseFilter(org.apache.lucene.analysis.core.LowerCaseFilter)

Example 7 with StopFilter

use of org.apache.lucene.analysis.core.StopFilter in project legato by DOREMUS-ANR.

the class Stemmer method stemTerms.

// static String stemTerm (String term) {
// PorterStemmer stemmer = new PorterStemmer();
// System.out.println(term + "   -->   "+stemmer.stem(term));
// return stemmer.stem(term);
// }
public static String stemTerms(String term) throws Exception {
    Analyzer analyzer = new StandardAnalyzer();
    TokenStream result = analyzer.tokenStream(null, term);
    result = new PorterStemFilter(result);
    result = new StopFilter(result, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
    CharTermAttribute resultAttr = result.addAttribute(CharTermAttribute.class);
    result.reset();
    String tokens = null;
    while (result.incrementToken()) {
        tokens = tokens + resultAttr.toString() + " ";
    }
    return tokens.trim();
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) StopFilter(org.apache.lucene.analysis.core.StopFilter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PorterStemFilter(org.apache.lucene.analysis.en.PorterStemFilter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StopAnalyzer(org.apache.lucene.analysis.core.StopAnalyzer)

Example 8 with StopFilter

use of org.apache.lucene.analysis.core.StopFilter in project nutch by apache.

the class LuceneAnalyzerUtil method createComponents.

@Override
protected TokenStreamComponents createComponents(String fieldName) {
    Tokenizer source = new ClassicTokenizer();
    TokenStream filter = new LowerCaseFilter(source);
    if (stopSet != null) {
        filter = new StopFilter(filter, stopSet);
    }
    switch(stemFilterType) {
        case PORTERSTEM_FILTER:
            filter = new PorterStemFilter(filter);
            break;
        case ENGLISHMINIMALSTEM_FILTER:
            filter = new EnglishMinimalStemFilter(filter);
            break;
        default:
            break;
    }
    return new TokenStreamComponents(source, filter);
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) StopFilter(org.apache.lucene.analysis.core.StopFilter) PorterStemFilter(org.apache.lucene.analysis.en.PorterStemFilter) ClassicTokenizer(org.apache.lucene.analysis.standard.ClassicTokenizer) Tokenizer(org.apache.lucene.analysis.Tokenizer) ClassicTokenizer(org.apache.lucene.analysis.standard.ClassicTokenizer) LowerCaseFilter(org.apache.lucene.analysis.core.LowerCaseFilter) EnglishMinimalStemFilter(org.apache.lucene.analysis.en.EnglishMinimalStemFilter)

Example 9 with StopFilter

use of org.apache.lucene.analysis.core.StopFilter in project Vidyavana by borsosl.

the class QueryAnalyzer method createComponents.

@Override
protected TokenStreamComponents createComponents(String fieldName) {
    Tokenizer tokenizer = new QueryTokenizer();
    TokenStream filter = new SeparateQueryOperatorFilter(tokenizer);
    filter = new StopFilter(filter, new CharArraySet(Arrays.asList("a", "az", "és"), false));
    return new TokenStreamComponents(tokenizer, filter);
}
Also used : CharArraySet(org.apache.lucene.analysis.util.CharArraySet) TokenStream(org.apache.lucene.analysis.TokenStream) StopFilter(org.apache.lucene.analysis.core.StopFilter) Tokenizer(org.apache.lucene.analysis.Tokenizer)

Aggregations

TokenStream (org.apache.lucene.analysis.TokenStream)9 StopFilter (org.apache.lucene.analysis.core.StopFilter)9 Tokenizer (org.apache.lucene.analysis.Tokenizer)6 LowerCaseFilter (org.apache.lucene.analysis.core.LowerCaseFilter)6 StandardTokenizer (org.apache.lucene.analysis.standard.StandardTokenizer)5 PorterStemFilter (org.apache.lucene.analysis.en.PorterStemFilter)4 ASCIIFoldingFilter (org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter)4 StandardFilter (org.apache.lucene.analysis.standard.StandardFilter)3 CharArraySet (org.apache.lucene.analysis.util.CharArraySet)3 EnglishPossessiveFilter (org.apache.lucene.analysis.en.EnglishPossessiveFilter)2 WordDelimiterFilter (org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Reader (java.io.Reader)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 KeywordTokenizer (org.apache.lucene.analysis.core.KeywordTokenizer)1 StopAnalyzer (org.apache.lucene.analysis.core.StopAnalyzer)1 EnglishMinimalStemFilter (org.apache.lucene.analysis.en.EnglishMinimalStemFilter)1 RemoveDuplicatesTokenFilter (org.apache.lucene.analysis.miscellaneous.RemoveDuplicatesTokenFilter)1 ClassicTokenizer (org.apache.lucene.analysis.standard.ClassicTokenizer)1 CharTermAttribute (org.apache.lucene.analysis.tokenattributes.CharTermAttribute)1