org.linqs.psl.cli.CommandLineLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of psl-cli Show documentation
Show all versions of psl-cli Show documentation
The command line interface module of the PSL software from the LINQS research group.
/*
* This file is part of the PSL software.
* Copyright 2011-2015 University of Maryland
* Copyright 2013-2022 The Regents of the University of California
*
* 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
*
* http://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.linqs.psl.cli;
import org.linqs.psl.config.Config;
import org.linqs.psl.config.RuntimeOptions;
import org.linqs.psl.runtime.Runtime;
import org.linqs.psl.util.Version;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import java.util.Comparator;
import java.util.Map;
/**
* Load the command line options into PSL Config's configuration values
* and log4j configuration appropriately.
*/
public class CommandLineLoader {
// Command line options.
public static final String OPTION_HELP = "h";
public static final String OPTION_HELP_LONG = "help";
public static final String OPERATION_INFER = "i";
public static final String OPERATION_INFER_LONG = "infer";
public static final String OPERATION_LEARN = "l";
public static final String OPERATION_LEARN_LONG = "learn";
public static final String OPTION_DATA = "d";
public static final String OPTION_DATA_LONG = "data";
public static final String OPTION_DB_H2_PATH = "h2path";
public static final String OPTION_DB_POSTGRESQL_NAME = "postgres";
public static final String OPTION_EVAL = "e";
public static final String OPTION_EVAL_LONG = "eval";
public static final String OPTION_INT_IDS = "int";
public static final String OPTION_INT_IDS_LONG = "int-ids";
public static final String OPTION_LOG4J = "4j";
public static final String OPTION_LOG4J_LONG = "log4j";
public static final String OPTION_MODEL = "m";
public static final String OPTION_MODEL_LONG = "model";
public static final String OPTION_OUTPUT_DIR = "o";
public static final String OPTION_OUTPUT_DIR_LONG = "output";
public static final String OPTION_OUTPUT_GROUND_RULES_LONG = "groundrules";
public static final String OPTION_OUTPUT_SATISFACTION_LONG = "satisfaction";
public static final String OPTION_PROPERTIES = "D";
public static final String OPTION_PROPERTIES_FILE = "p";
public static final String OPTION_PROPERTIES_FILE_LONG = "properties";
public static final String OPTION_SKIP_ATOM_COMMIT_LONG = "skipAtomCommit";
public static final String OPTION_VERSION = "v";
public static final String OPTION_VERSION_LONG = "version";
private static Options options = setupOptions();
private CommandLine parsedOptions;
public CommandLineLoader(String[] args) {
try {
parsedOptions = parseOptions(args);
if (parsedOptions == null) {
return;
}
} catch (Exception ex) {
System.err.println("Unexpected exception!");
ex.printStackTrace(System.err);
}
initConfig();
}
/**
* Returns the supported Options object.
*/
public static Options getOptions() {
return options;
}
/**
* Returns the parsedOptions object.
*/
public CommandLine getParsedOptions() {
return parsedOptions;
}
/**
* Loads configuration.
*/
private void initConfig() {
// Load any options specified directly on the command line (override standing options).
for (Map.Entry