blob: 94b9bf6ce656a71d7e221ea8ac19429f3d273490 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.parser;
import com.yahoo.language.Linguistics;
import com.yahoo.language.simple.SimpleLinguistics;
import com.yahoo.prelude.IndexFacts;
import com.yahoo.prelude.query.parser.SpecialTokens;
import com.yahoo.search.Searcher;
import com.yahoo.search.searchchain.Execution;
/**
* This class encapsulates the environment of a {@link Parser}. In case you are creating a parser from within a
* {@link Searcher}, you can use the {@link #fromExecutionContext(Execution.Context)} factory for convenience.
*
* @author Simon Thoresen Hult
*/
public final class ParserEnvironment {
private IndexFacts indexFacts = new IndexFacts();
private Linguistics linguistics = new SimpleLinguistics();
private SpecialTokens specialTokens = new SpecialTokens();
public IndexFacts getIndexFacts() {
return indexFacts;
}
public ParserEnvironment setIndexFacts(IndexFacts indexFacts) {
this.indexFacts = indexFacts;
return this;
}
public Linguistics getLinguistics() {
return linguistics;
}
public ParserEnvironment setLinguistics(Linguistics linguistics) {
this.linguistics = linguistics;
return this;
}
public SpecialTokens getSpecialTokens() {
return specialTokens;
}
public ParserEnvironment setSpecialTokens(SpecialTokens specialTokens) {
this.specialTokens = specialTokens;
return this;
}
public static ParserEnvironment fromExecutionContext(Execution.Context context) {
ParserEnvironment env = new ParserEnvironment();
if (context == null) return env;
if (context.getIndexFacts() != null)
env.setIndexFacts(context.getIndexFacts());
if (context.getLinguistics() != null)
env.setLinguistics(context.getLinguistics());
if (context.getTokenRegistry() != null)
env.setSpecialTokens(context.getTokenRegistry().getSpecialTokens("default"));
return env;
}
public static ParserEnvironment fromParserEnvironment(ParserEnvironment environment) {
return new ParserEnvironment()
.setIndexFacts(environment.indexFacts)
.setLinguistics(environment.linguistics)
.setSpecialTokens(environment.specialTokens);
}
}
|