/
TaggerFactory.java
63 lines (53 loc) · 2.23 KB
/
TaggerFactory.java
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
package org.grobid.core.engines.tagging;
import org.grobid.core.GrobidModel;
import org.grobid.core.GrobidModels;
import org.grobid.core.utilities.GrobidProperties;
import org.grobid.core.main.LibraryLoader;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Factory for a sequence labelling, aka a tagger, instance.
* Supported implementations are CRF (CRFPP, Wapiti) and Deep Learning (DeLFT)
*
*/
public class TaggerFactory {
public static final Logger LOGGER = LoggerFactory.getLogger(TaggerFactory.class);
private static Map<GrobidModel, GenericTagger> cache = new HashMap<>();
private TaggerFactory() {}
public static synchronized GenericTagger getTagger(GrobidModel model) {
return getTagger(model, GrobidProperties.getGrobidCRFEngine(model), GrobidProperties.getDelftArchitecture());
}
public static synchronized GenericTagger getTagger(GrobidModel model, GrobidCRFEngine engine) {
return getTagger(model, engine, GrobidProperties.getDelftArchitecture());
}
public static synchronized GenericTagger getTagger(GrobidModel model, GrobidCRFEngine engine, String architecture) {
GenericTagger t = cache.get(model);
if (t == null) {
if(model.equals(GrobidModels.DUMMY)) {
return new DummyTagger(model);
}
if(engine != null) {
switch (engine) {
case CRFPP:
t = new CRFPPTagger(model);
break;
case WAPITI:
t = new WapitiTagger(model);
break;
case DELFT:
t = new DeLFTTagger(model, architecture);
break;
default:
throw new IllegalStateException("Unsupported Grobid sequence labelling engine: " + GrobidProperties.getGrobidCRFEngine());
}
cache.put(model, t);
} else {
throw new IllegalStateException("Unsupported or null Grobid sequence labelling engine: " + GrobidProperties.getGrobidCRFEngine());
}
}
return t;
}
}