use of com.joliciel.talismane.Talismane.ProcessingOption in project talismane by joliciel-informatique.
the class TalismaneMain method execute.
/**
* Execute by processing command line options with a given default config.
*
* @param args
* the command-line options
*/
public void execute(String[] args) throws IOException, ReflectiveOperationException, TalismaneException, JoranException {
if (args.length > 0) {
Set<String> argSet = new HashSet<>(Arrays.asList(args));
if (argSet.contains("--serializeLexicon")) {
LexiconReader.main(args);
return;
}
if (argSet.contains("--testLexicon")) {
LexiconDeserializer.main(args);
return;
}
if (argSet.contains("--serializeDiacriticizer")) {
Diacriticizer.main(args);
return;
}
if (argSet.contains("--testDiacriticizer")) {
Diacriticizer.main(args);
return;
}
}
OptionSet options = parser.parse(args);
if (args.length == 0 || options.has("help")) {
parser.printHelpOn(System.out);
return;
}
String sessionId = options.valueOf(sessionIdOption);
Map<String, Object> values = new HashMap<>();
if (options.has("analyse"))
values.put("talismane.core." + sessionId + ".command", Command.analyse.name());
if (options.has("train"))
values.put("talismane.core." + sessionId + ".command", Command.train.name());
if (options.has("evaluate"))
values.put("talismane.core." + sessionId + ".command", Command.evaluate.name());
if (options.has("compare"))
values.put("talismane.core." + sessionId + ".command", Command.compare.name());
if (options.has("process"))
values.put("talismane.core." + sessionId + ".command", Command.process.name());
if (options.has(moduleOption))
values.put("talismane.core." + sessionId + ".module", options.valueOf(moduleOption).name());
if (options.has(startModuleOption)) {
values.put("talismane.core." + sessionId + ".analysis.start-module", options.valueOf(startModuleOption).name());
values.put("talismane.core." + sessionId + ".pos-tagger.evaluate.start-module", options.valueOf(startModuleOption).name());
values.put("talismane.core." + sessionId + ".parser.evaluate.start-module", options.valueOf(startModuleOption).name());
}
if (options.has(endModuleOption))
values.put("talismane.core." + sessionId + ".analysis.end-module", options.valueOf(endModuleOption).name());
if (options.has(modeOption))
values.put("talismane.core." + sessionId + ".mode", options.valueOf(modeOption).name());
if (options.has(portOption))
values.put("talismane.core." + sessionId + ".port", options.valueOf(portOption));
if (options.has(localeOption))
values.put("talismane.core." + sessionId + ".locale", options.valueOf(localeOption));
if (options.has(encodingOption))
values.put("talismane.core." + sessionId + ".encoding", options.valueOf(encodingOption));
if (options.has(inputEncodingOption))
values.put("talismane.core." + sessionId + ".input-encoding", options.valueOf(inputEncodingOption));
if (options.has(outputEncodingOption))
values.put("talismane.core." + sessionId + ".output-encoding", options.valueOf(outputEncodingOption));
if (options.has(languageModelOption))
values.put("talismane.core." + sessionId + ".language-detector.model", options.valueOf(languageModelOption).getPath());
if (options.has(sentenceModelOption))
values.put("talismane.core." + sessionId + ".sentence-detector.model", options.valueOf(sentenceModelOption).getPath());
if (options.has(tokeniserModelOption))
values.put("talismane.core." + sessionId + ".tokeniser.model", options.valueOf(tokeniserModelOption).getPath());
if (options.has(posTaggerModelOption))
values.put("talismane.core." + sessionId + ".pos-tagger.model", options.valueOf(posTaggerModelOption).getPath());
if (options.has(parserModelOption))
values.put("talismane.core." + sessionId + ".parser.model", options.valueOf(parserModelOption).getPath());
if (options.has(lexiconOption)) {
List<String> lexiconPaths = options.valuesOf(lexiconOption).stream().map(f -> f.getPath()).collect(Collectors.toList());
values.put("talismane.core." + sessionId + ".lexicons", lexiconPaths);
}
if (options.has(textAnnotatorsOption)) {
List<String> textAnnotatorPaths = options.valuesOf(textAnnotatorsOption).stream().map(f -> f.getPath()).collect(Collectors.toList());
values.put("talismane.core." + sessionId + ".annotators.text-annotators", textAnnotatorPaths);
}
if (options.has(sentenceAnnotatorsOption)) {
List<String> sentenceAnnotatorPaths = options.valuesOf(sentenceAnnotatorsOption).stream().map(f -> f.getPath()).collect(Collectors.toList());
values.put("talismane.core." + sessionId + ".annotators.sentence-annotators", sentenceAnnotatorPaths);
}
List<String> inputLocations = Arrays.asList("talismane.core." + sessionId + ".input", "talismane.core." + sessionId + ".language-detector.input", "talismane.core." + sessionId + ".language-detector.train", "talismane.core." + sessionId + ".language-detector.evaluate", "talismane.core." + sessionId + ".sentence-detector.input", "talismane.core." + sessionId + ".sentence-detector.train", "talismane.core." + sessionId + ".sentence-detector.evaluate", "talismane.core." + sessionId + ".tokeniser.input", "talismane.core." + sessionId + ".tokeniser.train", "talismane.core." + sessionId + ".tokeniser.evaluate", "talismane.core." + sessionId + ".pos-tagger.input", "talismane.core." + sessionId + ".pos-tagger.train", "talismane.core." + sessionId + ".pos-tagger.evaluate", "talismane.core." + sessionId + ".parser.input", "talismane.core." + sessionId + ".parser.train", "talismane.core." + sessionId + ".parser.evaluate");
List<String> outputLocations = Arrays.asList("talismane.core." + sessionId + ".output", "talismane.core." + sessionId + ".language-detector.output", "talismane.core." + sessionId + ".sentence-detector.output", "talismane.core." + sessionId + ".tokeniser.output", "talismane.core." + sessionId + ".pos-tagger.output", "talismane.core." + sessionId + ".parser.output");
if (options.has(newlineOption))
values.put("talismane.core." + sessionId + ".newline", options.valueOf(newlineOption));
if (options.has(processByDefaultOption))
values.put("talismane.core." + sessionId + ".analysis.process-by-default", options.valueOf(processByDefaultOption));
if (options.has(blockSizeOption))
values.put("talismane.core." + sessionId + ".block-size", options.valueOf(blockSizeOption));
if (options.has(sentenceCountOption))
for (String inputLocation : inputLocations) values.put(inputLocation + ".sentence-count", options.valueOf(sentenceCountOption));
if (options.has(startSentenceOption))
for (String inputLocation : inputLocations) values.put(inputLocation + ".start-sentence", options.valueOf(startSentenceOption));
if (options.has(crossValidationSizeOption))
for (String inputLocation : inputLocations) values.put(inputLocation + ".cross-validation.fold-count", options.valueOf(crossValidationSizeOption));
if (options.has(includeIndexOption))
for (String inputLocation : inputLocations) values.put(inputLocation + ".cross-validation.include-index", options.valueOf(includeIndexOption));
if (options.has(excludeIndexOption))
for (String inputLocation : inputLocations) values.put(inputLocation + ".cross-validation.exclude-index", options.valueOf(excludeIndexOption));
if (options.has(builtInTemplateOption))
for (String outputLocation : outputLocations) values.put(outputLocation + ".built-in-template", options.valueOf(builtInTemplateOption).name());
if (options.has(templateOption))
for (String outputLocation : outputLocations) values.put(outputLocation + ".template", options.valueOf(templateOption).getPath());
if (options.has(posTaggerRulesOption)) {
List<String> posTaggerRulePaths = options.valuesOf(posTaggerRulesOption).stream().map(f -> f.getPath()).collect(Collectors.toList());
values.put("talismane.core." + sessionId + ".pos-tagger.rules", posTaggerRulePaths);
}
if (options.has(parserRulesOption)) {
List<String> parserRulePaths = options.valuesOf(parserRulesOption).stream().map(f -> f.getPath()).collect(Collectors.toList());
values.put("talismane.core." + sessionId + ".parser.rules", parserRulePaths);
}
if (options.has(suffixOption))
values.put("talismane.core." + sessionId + ".suffix", options.valueOf(suffixOption));
if (options.has(outputDividerOption))
for (String outputLocation : outputLocations) values.put(outputLocation + ".output-divider", options.valueOf(outputDividerOption));
if (options.has(beamWidthOption)) {
values.put("talismane.core." + sessionId + ".pos-tagger.beam-width", options.valueOf(beamWidthOption));
values.put("talismane.core." + sessionId + ".parser.beam-width", options.valueOf(beamWidthOption));
}
if (options.has(tokeniserBeamWidthOption))
values.put("talismane.core." + sessionId + ".tokeniser.beam-width", options.valueOf(tokeniserBeamWidthOption));
if (options.has(propagateBeamOption))
values.put("talismane.core." + sessionId + ".parser.propagate-pos-tagger-beam", options.valueOf(propagateBeamOption));
if (options.has(maxParseAnalysisTimeOption))
values.put("talismane.core." + sessionId + ".parser.max-analysis-time", options.valueOf(maxParseAnalysisTimeOption));
if (options.has(minFreeMemoryOption))
values.put("talismane.core." + sessionId + ".parser.min-free-memory", options.valueOf(minFreeMemoryOption));
if (options.has(earlyStopOption))
values.put("talismane.core." + sessionId + ".parser.early-stop", options.valueOf(earlyStopOption));
if (options.has(inputPatternFileOption) || options.has(inputPatternOption)) {
String inputRegex = null;
if (options.has(inputPatternFileOption)) {
InputStream inputPatternFile = new FileInputStream(options.valueOf(inputPatternFileOption));
try (Scanner inputPatternScanner = new Scanner(new BufferedReader(new InputStreamReader(inputPatternFile, "UTF-8")))) {
if (inputPatternScanner.hasNextLine()) {
inputRegex = inputPatternScanner.nextLine();
}
}
if (inputRegex == null)
throw new TalismaneException("No input pattern found in " + options.valueOf(inputPatternFileOption).getPath());
} else {
inputRegex = options.valueOf(inputPatternOption);
}
for (String inputLocation : inputLocations) values.put(inputLocation + ".input-pattern", inputRegex);
}
if (options.has(evalPatternFileOption) || options.has(evalPatternOption)) {
String evalRegex = null;
if (options.has(evalPatternFileOption)) {
InputStream evalPatternFile = new FileInputStream(options.valueOf(evalPatternFileOption));
try (Scanner evalPatternScanner = new Scanner(new BufferedReader(new InputStreamReader(evalPatternFile, "UTF-8")))) {
if (evalPatternScanner.hasNextLine()) {
evalRegex = evalPatternScanner.nextLine();
}
}
if (evalRegex == null)
throw new TalismaneException("No eval pattern found in " + options.valueOf(evalPatternFileOption).getPath());
} else {
evalRegex = options.valueOf(evalPatternOption);
}
values.put("talismane.core." + sessionId + ".sentence-detector.evaluate.input-pattern", evalRegex);
values.put("talismane.core." + sessionId + ".tokeniser.evaluate.input-pattern", evalRegex);
values.put("talismane.core." + sessionId + ".pos-tagger.evaluate.input-pattern", evalRegex);
values.put("talismane.core." + sessionId + ".parser.evaluate.input-pattern", evalRegex);
}
if (options.has(csvSeparatorOption))
values.put("talismane.core." + sessionId + ".csv.separator", options.valueOf(csvSeparatorOption));
if (options.has(csvEncodingOption))
values.put("talismane.core." + sessionId + ".csv.encoding", options.valueOf(csvEncodingOption));
if (options.has(csvLocaleOption))
values.put("talismane.core." + sessionId + ".csv.locale", options.valueOf(csvLocaleOption));
if (options.has(includeUnknownWordResultsOption))
values.put("talismane.core." + sessionId + ".pos-tagger.evaluate.include-unknown-word-results", options.valueOf(includeUnknownWordResultsOption));
if (options.has(includeLexiconCoverageOption))
values.put("talismane.core." + sessionId + ".pos-tagger.evaluate.include-lexicon-coverage", options.valueOf(includeLexiconCoverageOption));
if (options.has(labeledEvaluationOption))
values.put("talismane.core." + sessionId + ".parser.evaluate.labeled-evaluation", options.valueOf(labeledEvaluationOption));
if (options.has(processingOption))
values.put("talismane.core." + sessionId + ".output.option", options.valueOf(processingOption).name());
if (options.has(lexicalEntryRegexOption)) {
values.put("talismane.core." + sessionId + ".pos-tagger.input.corpus-lexical-entry-regex", options.valueOf(lexicalEntryRegexOption).getPath());
values.put("talismane.core." + sessionId + ".parser.input.corpus-lexical-entry-regex", options.valueOf(lexicalEntryRegexOption).getPath());
}
if (options.has(featuresOption)) {
values.put("talismane.core." + sessionId + ".language-detector.train.features", options.valueOf(featuresOption).getPath());
values.put("talismane.core." + sessionId + ".sentence-detector.train.features", options.valueOf(featuresOption).getPath());
values.put("talismane.core." + sessionId + ".tokeniser.train.features", options.valueOf(featuresOption).getPath());
values.put("talismane.core." + sessionId + ".pos-tagger.train.features", options.valueOf(featuresOption).getPath());
values.put("talismane.core." + sessionId + ".parser.train.features", options.valueOf(featuresOption).getPath());
}
if (options.has(tokeniserPatternsOption))
values.put("talismane.core." + sessionId + ".tokeniser.train.patterns", options.valueOf(tokeniserPatternsOption).getPath());
if (options.has(sentenceFileOption)) {
values.put("talismane.core." + sessionId + ".tokeniser.input.sentence-file", options.valueOf(sentenceFileOption).getPath());
values.put("talismane.core." + sessionId + ".pos-tagger.input.sentence-file", options.valueOf(sentenceFileOption).getPath());
values.put("talismane.core." + sessionId + ".parser.input.sentence-file", options.valueOf(sentenceFileOption).getPath());
}
if (options.has(languageCorpusMapOption))
values.put("talismane.core." + sessionId + ".language-detector.train.language-corpus-map", options.valueOf(languageCorpusMapOption).getPath());
if (options.has(predictTransitionsOption))
values.put("talismane.core." + sessionId + ".parser.input.predict-transitions", options.valueOf(predictTransitionsOption));
if (options.has(testWordsOption))
values.put("talismane.core." + sessionId + ".pos-tagger.output.test-words", options.valuesOf(testWordsOption));
if (options.has(algorithmOption)) {
values.put("talismane.machine-learning.algorithm", options.valueOf(algorithmOption).name());
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.algorithm", options.valueOf(algorithmOption).name());
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.algorithm", options.valueOf(algorithmOption).name());
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.algorithm", options.valueOf(algorithmOption).name());
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.algorithm", options.valueOf(algorithmOption).name());
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.algorithm", options.valueOf(algorithmOption).name());
}
if (options.has(cutoffOption)) {
values.put("talismane.machine-learning.cutoff", options.valueOf(cutoffOption));
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.cutoff", options.valueOf(cutoffOption));
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.cutoff", options.valueOf(cutoffOption));
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.cutoff", options.valueOf(cutoffOption));
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.cutoff", options.valueOf(cutoffOption));
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.cutoff", options.valueOf(cutoffOption));
}
if (options.has(linearSVMEpsilonOption)) {
values.put("talismane.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.LinearSVM.epsilon", options.valueOf(linearSVMEpsilonOption));
}
if (options.has(linearSVMCostOption)) {
values.put("talismane.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.LinearSVM.cost", options.valueOf(linearSVMCostOption));
}
if (options.has(oneVsRestOption)) {
values.put("talismane.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.LinearSVM.one-vs-rest", options.valueOf(oneVsRestOption));
}
if (options.has(iterationsOption)) {
values.put("talismane.machine-learning.iterations", options.valueOf(iterationsOption));
values.put("talismane.core." + sessionId + ".language-detector.train.machine-learning.iterations", options.valueOf(iterationsOption));
values.put("talismane.core." + sessionId + ".sentence-detector.train.machine-learning.iterations", options.valueOf(iterationsOption));
values.put("talismane.core." + sessionId + ".tokeniser.train.machine-learning.iterations", options.valueOf(iterationsOption));
values.put("talismane.core." + sessionId + ".pos-tagger.train.machine-learning.iterations", options.valueOf(iterationsOption));
values.put("talismane.core." + sessionId + ".parser.train.machine-learning.iterations", options.valueOf(iterationsOption));
}
if (options.has(logConfigFileSpec))
LogUtils.configureLogging(options.valueOf(logConfigFileSpec));
File inFile = null;
File outFile = null;
File outDir = null;
if (options.has(inFileOption))
inFile = options.valueOf(inFileOption);
if (options.has(outFileOption))
outFile = options.valueOf(outFileOption);
if (options.has(outDirOption))
outDir = options.valueOf(outDirOption);
File evalFile = inFile;
if (options.has(evalFileOption))
evalFile = options.valueOf(evalFileOption);
boolean keepDirectoryStructure = outFile != null && !outFile.getName().contains(".");
if (options.has(keepDirStructureOption))
keepDirectoryStructure = options.valueOf(keepDirStructureOption);
// System properties override configuration file keys when ConfigFactory.load() is called.
values.forEach((k, v) -> System.setProperty(k, v.toString()));
ConfigFactory.invalidateCaches();
this.execute(sessionId, inFile, outFile, outDir, evalFile, keepDirectoryStructure);
}
Aggregations