forked from datacommonsorg/import
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLint.java
More file actions
81 lines (73 loc) · 3.21 KB
/
Lint.java
File metadata and controls
81 lines (73 loc) · 3.21 KB
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
73
74
75
76
77
78
79
80
81
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.datacommons.tool;
import freemarker.template.TemplateException;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.datacommons.util.FileGroup;
import picocli.CommandLine;
@CommandLine.Command(
name = "lint",
description = "Run various checks on input MCF/TMCF/CSV/JSON-LD files")
class Lint implements Callable<Integer> {
private static final Logger logger = LogManager.getLogger(Lint.class);
@CommandLine.Parameters(
arity = "1..*",
description =
("List of input files. The file extensions are used to infer the format. "
+ "Valid extensions include .mcf for Instance MCF, .tmcf for Template MCF, "
+ ".jsonld for JSON-LD instances, "
+ ".csv for tabular text files delimited by comma (overridden with -d), and .tsv "
+ "for tab-delimited tabular files."))
private File[] files;
@CommandLine.Option(
names = {"-d", "--delimiter"},
description =
"Delimiter of the input CSV files. Default is ',' for .csv files and '\\t' for "
+ ".tsv files.",
scope = CommandLine.ScopeType.INHERIT)
private Character delimiter;
@CommandLine.ParentCommand private Main parent;
@CommandLine.Spec CommandLine.Model.CommandSpec spec; // injected by picocli
@Override
public Integer call() throws IOException, TemplateException {
if (!parent.outputDir.exists()) {
parent.outputDir.mkdirs();
}
Args args = new Args();
args.doExistenceChecks = parent.doExistenceChecks;
args.resolutionMode = parent.resolutionMode;
args.doCoordinatesResolution = parent.doCoordinatesResolution;
args.doStatChecks = parent.doStatChecks;
args.samplePlaces = parent.samplePlaces;
args.numThreads = parent.numThreads;
if (args.samplePlaces != null && !args.doStatChecks) {
logger.warn(
"Sample places entered without stat checks being enabled. Sample places will be unused.");
}
args.verbose = parent.verbose;
args.fileGroup = FileGroup.build(files, spec, delimiter, logger);
args.outputDir = parent.outputDir.toPath();
args.generateSummaryReport = parent.generateSummaryReport;
args.generateOptimizedGraph = parent.generateOptimizedGraph;
args.checkObservationAbout = parent.checkObservationAbout;
args.allowNonNumericStatVarObservation = parent.allowNonNumericStatVarObservation;
args.checkMeasurementResult = parent.checkMeasurementResult;
args.includeRuntimeMetadata = parent.includeRuntimeMetadata;
return Processor.process(args);
}
}