Skip to content

Commit

Permalink
fixing commandline invocation in case of erroneous parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Zimmermann committed Oct 6, 2021
1 parent ddf3e5d commit ff19dca
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
11 changes: 11 additions & 0 deletions deidentifier-pipeline/src/main/java/org/ratschlab/DeidCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ratschlab;

import java.util.concurrent.Callable;

public class DeidCmd implements Callable<Integer> {
@Override
public Integer call() {
org.ratschlab.util.Utils.tieSystemOutAndErrToLog();
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.stream.Stream;

@CommandLine.Command(description = "Annotate Corpus", name = "annotate")
public class AnnotationCmd extends DbCommands implements Callable<Integer> {
public class AnnotationCmd extends DbCommands {
private static final Logger log = LoggerFactory.getLogger(AnnotationCmd.class);

@CommandLine.Option(names = {"-i"}, description = "Input corpus dir")
Expand Down Expand Up @@ -106,6 +106,8 @@ private PipelineWorkflow<?> readFromFiles(List<WorkflowConcern> concerns, Serial

@Override
public Integer call() {
super.call();

if(corpusInputDirPath == null && databaseConfigPath == null) {
System.err.println("Need at least -i or -d");
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public Integer call() {
}

public static void main(String[] args) {
org.ratschlab.util.Utils.tieSystemOutAndErrToLog();
int exitCode = CommandLine.call(new DeidMain(), args);
Integer exitCode = CommandLine.call(new DeidMain(), args);
if(exitCode == null) {
System.exit(2);
}
System.exit(exitCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import gate.Gate;
import gate.util.GateException;
import org.ratschlab.DeidCmd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;

@CommandLine.Command(description = "Tests a pipeline", name = "test")
public class PipelineTesterCmd implements Callable<Integer> {
public class PipelineTesterCmd extends DeidCmd {
private static final Logger log = LoggerFactory.getLogger(PipelineTesterCmd.class);

@CommandLine.Parameters(index = "0", description = "Pipeline Configuration File")
Expand All @@ -29,6 +29,8 @@ public static void main(String[] args) {

@Override
public Integer call() {
super.call();

try {
Gate.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.stream.Stream;

@CommandLine.Command(mixinStandardHelpOptions = true, description = "Roundtrip test between JSON <--> GATE format", name = "conversioncheck")
public class ConversionCheckCmd extends DbCommands implements Callable<Integer> {
public class ConversionCheckCmd extends DbCommands {

private static final Logger log = LoggerFactory.getLogger(ConversionCheckCmd.class);

Expand All @@ -30,6 +30,8 @@ public class ConversionCheckCmd extends DbCommands implements Callable<Integer>

@Override
public Integer call() {
super.call();

try {
Gate.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gate.corpora.DocumentJsonUtils;
import gate.util.GateException;
import org.apache.commons.lang.NotImplementedException;
import org.ratschlab.DeidCmd;
import org.ratschlab.gate.GateTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,7 +18,7 @@
import java.util.stream.Stream;

@CommandLine.Command(description = "Convert reports into different formats", name = "convert")
public class ConversionCmd implements Callable<Integer> {
public class ConversionCmd extends DeidCmd {
private static final Logger log = LoggerFactory.getLogger(ConversionCmd.class);

@CommandLine.Option(names = {"-i"}, description = "Input dir", required = true)
Expand Down Expand Up @@ -90,6 +91,7 @@ protected static void convertGateCorpusToGateJson(File inputDir, File outputDir)

@Override
public Integer call() {
super.call();
try {
Gate.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.stream.Stream;

@CommandLine.Command(description = "Import reports from database", name = "import")
public class ImportCmd extends DbCommands implements Callable<Integer> {
public class ImportCmd extends DbCommands {

private static final Logger log = LoggerFactory.getLogger(ImportCmd.class);

Expand All @@ -46,6 +46,8 @@ public static void main(String[] args) {

@Override
public Integer call() {
super.call();

try {
Gate.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gate.*;
import gate.creole.SerialAnalyserController;
import gate.util.GateException;
import org.ratschlab.DeidCmd;
import org.ratschlab.deidentifier.annotation.features.FeatureKeysDate;
import org.ratschlab.deidentifier.pipelines.PipelineFactory;
import org.ratschlab.deidentifier.sources.KisimFormat;
Expand All @@ -30,7 +31,7 @@
import java.util.stream.Stream;

@CommandLine.Command(description = "Apply Substitution to Annotated Corpus", name = "substitute")
public class SubstitutionCmd implements Callable<Integer> {
public class SubstitutionCmd extends DeidCmd {
private static final Logger log = LoggerFactory.getLogger(SubstitutionCmd.class);

@CommandLine.Parameters(index = "0", description = "Corpus Dir")
Expand Down Expand Up @@ -102,7 +103,8 @@ public static Set<String> loadDocTypeSet(File path) throws IOException {

@Override
public Integer call() {
// TODO: really?
super.call();

if(outputDir != null && outputDir.exists()) {
try {
Files.delete(outputDir.toPath());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.ratschlab.deidentifier.utils;

import org.ratschlab.DeidCmd;
import picocli.CommandLine;

import java.util.stream.Stream;

public class DbCommands {
public class DbCommands extends DeidCmd {
@CommandLine.Option(names = {"-d"}, description = "DB config path")
protected String databaseConfigPath = "";

Expand Down

0 comments on commit ff19dca

Please sign in to comment.