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

pkiraly / metadata-qa-marc / #1527

22 Aug 2025 02:21PM UTC coverage: 90.345%. Remained the same
#1527

push

pkiraly
Improve timeline handling

5191 of 6416 new or added lines in 219 files covered. (80.91%)

886 existing lines in 78 files now uncovered.

36717 of 40641 relevant lines covered (90.34%)

0.9 hits per line

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

0.0
/src/main/java/de/gwdg/metadataqa/marc/cli/BLClassificationAnalysis.java
1
package de.gwdg.metadataqa.marc.cli;
2

3
import de.gwdg.metadataqa.marc.analysis.BLClassifier;
4
import de.gwdg.metadataqa.marc.cli.parameters.CommonParameters;
5
import de.gwdg.metadataqa.marc.cli.processor.BibliographicInputProcessor;
6
import de.gwdg.metadataqa.marc.cli.utils.RecordIterator;
7
import de.gwdg.metadataqa.marc.dao.record.BibliographicRecord;
8
import de.gwdg.metadataqa.marc.model.validation.ValidationError;
9
import org.apache.commons.cli.Options;
10
import org.apache.commons.cli.ParseException;
11
import org.apache.commons.io.FileUtils;
12
import org.marc4j.marc.Record;
13

14
import java.io.File;
15
import java.io.IOException;
16
import java.io.Serializable;
17
import java.nio.charset.StandardCharsets;
18
import java.nio.file.Files;
19
import java.nio.file.Path;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.logging.Level;
23
import java.util.logging.Logger;
24

25
import static de.gwdg.metadataqa.marc.Utils.createRow;
26

27
public class BLClassificationAnalysis extends QACli<CommonParameters> implements BibliographicInputProcessor, Serializable {
28

29
  private static final Logger logger = Logger.getLogger(
×
30
    BLClassificationAnalysis.class.getCanonicalName()
×
31
  );
32
  public static final String BL_CLASSIFIER_FILE = "bl-classifier.csv";
33
  private final Options options;
34
  private final boolean readyToProcess;
35
  private File output = null;
×
36
  private BLClassifier classifier = null;
×
37

38
  public BLClassificationAnalysis(String[] args) throws ParseException {
×
39
    parameters = new CommonParameters(args);
×
40
    options = parameters.getOptions();
×
41
    classifier = new BLClassifier();
×
42
    readyToProcess = true;
×
43
  }
×
44

45
  public static void main(String[] args) {
46
    BibliographicInputProcessor processor = null;
×
47
    try {
48
      processor = new BLClassificationAnalysis(args);
×
49
    } catch (ParseException e) {
×
50
      System.err.println("ERROR. " + e.getLocalizedMessage());
×
51
      System.exit(1);
×
52
    }
×
53

54
    if (processor.getParameters().getArgs().length < 1) {
×
55
      System.err.println("Please provide a MARC file name!");
×
56
      System.exit(1);
×
57
    }
58
    if (processor.getParameters().doHelp()) {
×
59
      processor.printHelp(processor.getParameters().getOptions());
×
60
      System.exit(0);
×
61
    }
62

63
    RecordIterator iterator = new RecordIterator(processor);
×
64
    iterator.start();
×
65
  }
×
66

67
  @Override
68
  public CommonParameters getParameters() {
69
    return parameters;
×
70
  }
71

72
  @Override
73
  public void processRecord(Record marc4jRecord, int recordNumber) throws IOException {
74
    // do nothing
75
  }
×
76

77
  @Override
78
  public void processRecord(BibliographicRecord marcRecord, int recordNumber, List<ValidationError> errors) throws IOException {
79
    // do nothing
80
  }
×
81

82
  @Override
83
  public void processRecord(BibliographicRecord marcRecord, int recordNumber) throws IOException {
84
    logger.info(".");
×
85
    if (parameters.getRecordIgnorator().isIgnorable(marcRecord))
×
86
      return;
×
87
    String blClass = classifier.classify(marcRecord);
×
88
    String id = parameters.getTrimId()
×
89
      ? marcRecord.getId().trim()
×
90
      : marcRecord.getId();
×
91

92
    print(createRow(id, blClass));
×
93
  }
×
94

95
  private void print(String message) {
96
    try {
97
      FileUtils.writeStringToFile(output, message, StandardCharsets.UTF_8, true);
×
98
    } catch (IOException e) {
×
99
      logger.log(Level.WARNING, "print", e);
×
100
    }
×
101
  }
×
102

103
  @Override
104
  public void beforeIteration() {
105
    logger.info(parameters.formatParameters());
×
106
    // printFields();
107

108
    output = new File(parameters.getOutputDir(), BL_CLASSIFIER_FILE);
×
NEW
109
    if (output.exists())
×
110
      try {
NEW
111
        Files.delete(output.toPath());
×
NEW
112
      } catch (IOException e) {
×
NEW
113
        logger.log(Level.SEVERE, "The output file ({}) has not been deleted", output.getAbsolutePath());
×
NEW
114
      }
×
115
  }
×
116

117
  @Override
118
  public void fileOpened(Path path) {
119
    logger.info("file opened: " + path);
×
UNCOV
120
  }
×
121

122
  @Override
123
  public void fileProcessed() {
124
    logger.info("file processed");
×
UNCOV
125
  }
×
126

127
  @Override
128
  public void afterIteration(int numberOfprocessedRecords, long duration) {
129
    saveParameters("bl-classifications.params.json", parameters, Map.of("numberOfprocessedRecords", numberOfprocessedRecords, "duration", duration));
×
UNCOV
130
    logger.info("after iteration: " + numberOfprocessedRecords);
×
UNCOV
131
  }
×
132

133
  @Override
134
  public void printHelp(Options options) {
135

UNCOV
136
  }
×
137

138
  @Override
139
  public boolean readyToProcess() {
140
    return readyToProcess;
×
141
  }
142
}
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

© 2026 Coveralls, Inc