summaryrefslogtreecommitdiffstats
path: root/lucene-linguistics/src/main/java/com/yahoo/language/lucene/LuceneLinguistics.java
blob: 37d2f6abdd7f4c3742bdc096b7945ee1da9f3c72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.yahoo.language.lucene;

import com.google.inject.Inject;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.language.Linguistics;
import com.yahoo.language.process.*;
import com.yahoo.language.simple.SimpleLinguistics;
import org.apache.lucene.analysis.Analyzer;

import java.util.ArrayList;
import java.util.logging.Logger;

/**
 * Factory of Lucene based linguistics processor.
 * As described in the Linguistics docstring
 * > the tokenizer should typically stem, transform and normalize
 * The Stemmer, Transformer, Normalizer, and Segmenter implementations are mostly NOOP.
 *
 * TODO: docs for all available analysis components.
 * TODO: some registry for available language Analyzers.
 */
public class LuceneLinguistics extends SimpleLinguistics {

    private static final Logger log = Logger.getLogger(LuceneLinguistics.class.getName());
    private final Tokenizer tokenizer;
    private final LuceneAnalysisConfig config;

    @Inject
    public LuceneLinguistics(LuceneAnalysisConfig config, ComponentRegistry<Analyzer> analyzers) {
        log.info("Creating LuceneLinguistics with: " + config);
        this.config = config;
        this.tokenizer = new LuceneTokenizer(config, analyzers);
    }

    @Override
    public Tokenizer getTokenizer() { return tokenizer; }

    public LuceneAnalysisConfig getConfig() {
        return config;
    }

    @Override
    public boolean equals(Linguistics other) {
        return (other instanceof LuceneLinguistics)
                // Config actually determines if Linguistics are equal
                && config.equals(((LuceneLinguistics) other).getConfig()); }
}