• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kermitt2 / grobid / 385

pending completion
385

push

circleci

review incremental training

3 of 3 new or added lines in 2 files covered. (100.0%)

14846 of 37503 relevant lines covered (39.59%)

0.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.06
/grobid-core/src/main/java/org/grobid/core/jni/WapitiModel.java
1
package org.grobid.core.jni;
2

3
import fr.limsi.wapiti.SWIGTYPE_p_mdl_t;
4
import fr.limsi.wapiti.Wapiti;
5
import org.grobid.core.GrobidModel;
6
import org.grobid.core.GrobidModels;
7
import org.grobid.core.exceptions.GrobidException;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10

11
import java.io.File;
12

13
public class WapitiModel {
14
    public static final Logger LOGGER = LoggerFactory.getLogger(WapitiModel.class);
1✔
15

16
    private SWIGTYPE_p_mdl_t model;
17
    private File modelFile;
18

19
    public WapitiModel(File modelFile) {
×
20
        this.modelFile = modelFile;
×
21
        init();
×
22
    }
×
23

24
    public WapitiModel(GrobidModel grobidModel) {
1✔
25
        modelFile = new File(grobidModel.getModelPath());
1✔
26
        init();
1✔
27
    }
1✔
28

29
    private synchronized void init() {
30
        if (model != null) {
1✔
31
            return;
×
32
        }
33
        if (!modelFile.exists() || modelFile.isDirectory()) {
1✔
34
            throw new GrobidException("Model file does not exists or is a directory: " + modelFile.getAbsolutePath());
×
35
        }
36
        LOGGER.info("Loading model: " + modelFile + " (size: " + modelFile.length() + ")");
1✔
37
        model = WapitiWrapper.getModel(modelFile);
1✔
38
    }
1✔
39

40
    public String label(String data) {
41
        if (model == null) {
1✔
42
            LOGGER.warn("Model has been already closed, reopening: " + modelFile.getAbsolutePath());
×
43
            init();
×
44
        }
45
        String label = WapitiWrapper.label(model, data).trim();
1✔
46
        //TODO: VZ: Grobid currently expects tabs as separators whereas wapiti uses spaces for separating features.
47
        // for now it is safer to replace, although it does not look nice
48
        label = label.replaceAll(" ", "\t");
1✔
49
        return label;
1✔
50
    }
51

52
    public synchronized void close() {
53
        if (model != null) {
1✔
54
            Wapiti.freeModel(model);
1✔
55
            model = null;
1✔
56
        }
57
    }
1✔
58

59
    public static void train(File template, File trainingData, File outputModel) {
60
        train(template, trainingData, outputModel, "");
×
61
    }
×
62

63
    public static void train(File template, File trainingData, File outputModel, String params) {
64
                String args = String.format("train " + params + " -p %s %s %s", template.getAbsolutePath(), trainingData.getAbsolutePath(), outputModel.getAbsolutePath());
×
65
                //System.out.println("Training with equivalent command line: \n" + "wapiti " + args);
66
                Wapiti.runWapiti(args);
×
67
    }
×
68

69

70

71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc