aboutsummaryrefslogtreecommitdiffstats
path: root/linguistics/src/main/java/com/yahoo/language/opennlp/OpenNlpLinguistics.java
blob: 1c7c71c00b62f8608277be9048ef311676e92ae2 (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
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.language.opennlp;

import com.google.inject.Inject;
import com.yahoo.language.detect.Detector;
import com.yahoo.language.process.Tokenizer;
import com.yahoo.language.simple.SimpleDetector;
import com.yahoo.language.simple.SimpleLinguistics;

/**
 * Returns a linguistics implementation based on OpenNlp,
 * and (optionally, default on) Optimaize for language detection.
 */
public class OpenNlpLinguistics extends SimpleLinguistics {

    private final Detector detector;

    public OpenNlpLinguistics() {
        this(true);
    }

    @Inject
    public OpenNlpLinguistics(OpennlpLinguisticsConfig config) {
        this(config.detector().enableOptimaize());
    }

    public OpenNlpLinguistics(boolean enableOptimaize) {
        this(enableOptimaize ? new OptimaizeDetector() : new SimpleDetector());
    }

    private OpenNlpLinguistics(Detector detector) {
        this.detector = detector;
    }

    @Override
    public Tokenizer getTokenizer() {
        return new OpenNlpTokenizer(getNormalizer(), getTransformer());
    }

    @Override
    public Detector getDetector() { return detector; }

}