Skip to content

Commit

Permalink
Added more documentations.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvb2univpitt committed Dec 11, 2022
1 parent 631961b commit 75d8525
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 189 deletions.
16 changes: 8 additions & 8 deletions src/main/java/edu/pitt/dbmi/causal/cmd/CmdOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private CmdOptions() {
/**
* Get an instance of the command-line options.
*
* @return
* @return CmdOptions instance
*/
public static CmdOptions getInstance() {
if (instance == null) {
Expand All @@ -75,7 +75,7 @@ public static void clear() {
* Get multi-character name options for a given name..
*
* @param param multi-character name
* @return
* @return command-line option
*/
public Option getLongOption(String param) {
return options.get(param);
Expand Down Expand Up @@ -249,7 +249,7 @@ private void addRequiredOptions() {
/**
* Get the application required options from the stored options.
*
* @return
* @return required command-line options
*/
public List<Option> getRequiredOptions() {
return options.entrySet().stream()
Expand All @@ -261,7 +261,7 @@ public List<Option> getRequiredOptions() {
/**
* Get the names of all the datatypes.
*
* @return
* @return datatype description
*/
private String getDataTypeDesc() {
return "Data type: " + DataTypes.getInstance().getNames().stream()
Expand All @@ -271,7 +271,7 @@ private String getDataTypeDesc() {
/**
* Get the names of all the delimiters.
*
* @return
* @return names of delimiters
*/
private String getDelimiterDesc() {
return "Delimiter: " + Delimiters.getInstance().getNames().stream()
Expand All @@ -281,7 +281,7 @@ private String getDelimiterDesc() {
/**
* Get the names of all the scores.
*
* @return
* @return description for score
*/
private String getScoreDesc() {
return "Score: " + TetradScores.getInstance().getCommands().stream()
Expand All @@ -291,7 +291,7 @@ private String getScoreDesc() {
/**
* Get the names of all the independence test.
*
* @return
* @return description for test of independence
*/
private String getIndependenceTestDesc() {
return "Independence Test: " + TetradIndependenceTests.getInstance().getCommands().stream()
Expand All @@ -301,7 +301,7 @@ private String getIndependenceTestDesc() {
/**
* Get the names of all the algorithms.
*
* @return
* @return description for algorithm
*/
private String getAlgorithmDesc() {
return "Algorithm: " + TetradAlgorithms.getInstance().getCommands().stream()
Expand Down
99 changes: 61 additions & 38 deletions src/main/java/edu/pitt/dbmi/causal/cmd/CmdParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public final class CmdParser {
private CmdParser() {
}

/**
* Parse user input command
*
* @param args user input command
* @return user input command values
* @throws CmdParserException when an error occurs while parsing
*/
public static CmdArgs parse(String[] args) throws CmdParserException {
CmdArgs cmdArgs = new CmdArgs();

Expand All @@ -80,10 +87,10 @@ public static CmdArgs parse(String[] args) throws CmdParserException {
/**
* Parse command-line options.
*
* @param cmd
* @param parseOptions
* @param cmdArgs
* @throws CmdParserException
* @param cmd command-line input
* @param parseOptions command-line options
* @param cmdArgs parsed command line arguments and values
* @throws CmdParserException when an error occurs while parsing
*/
private static void parseOptionalOptions(CommandLine cmd, ParseOptions parseOptions, CmdArgs cmdArgs) throws CmdParserException {
cmdArgs.knowledgeFile = cmd.hasOption(CmdParams.KNOWLEDGE)
Expand Down Expand Up @@ -143,10 +150,10 @@ private static void parseOptionalOptions(CommandLine cmd, ParseOptions parseOpti
/**
* Parse the required command-line options.
*
* @param cmd
* @param parseOptions
* @param cmdArgs
* @throws CmdParserException
* @param cmd command-line input
* @param parseOptions command-line options
* @param cmdArgs parsed command line arguments and values
* @throws CmdParserException when an error occurs while parsing
*/
private static void parseRequiredOptions(CommandLine cmd, ParseOptions parseOptions, CmdArgs cmdArgs) throws CmdParserException {
cmdArgs.dataType = DataTypes.getInstance().get(cmd.getOptionValue(CmdParams.DATA_TYPE));
Expand Down Expand Up @@ -176,9 +183,9 @@ private static void parseRequiredOptions(CommandLine cmd, ParseOptions parseOpti
/**
* Get the options for the help message.
*
* @param args
* @return
* @throws CmdParserException
* @param args user input command
* @return parsed command-line options
* @throws CmdParserException when an error occurs while parsing
*/
public static ParseOptions getHelpOptions(String[] args) throws CmdParserException {
CmdOptions cmdOptions = CmdOptions.getInstance();
Expand Down Expand Up @@ -338,8 +345,8 @@ private static ParseOptions getValidOptions(String[] args, Options options) thro
* Get the parameters for the algorithm, the algorithm's test, algorithm's
* score and bootstrap.
*
* @param algorithm
* @return
* @param algorithm algorithm to get the parameters for
* @return set of parameters related to the given algorithm
*/
private static Set<String> getAlgorithmRelatedParameters(Algorithm algorithm) {
if (algorithm == null) {
Expand Down Expand Up @@ -370,7 +377,7 @@ private static Set<String> getAlgorithmRelatedParameters(Algorithm algorithm) {
/**
* Add options for manipulating Tetrad output graph.
*
* @param opts
* @param opts options to add to
*/
private static void addGraphManipulationOptions(Options opts) {
opts.addOption(CmdOptions.getInstance().getLongOption(CmdParams.CHOOSE_DAG_IN_PATTERN));
Expand All @@ -393,6 +400,12 @@ private static String getValidPrefix(CommandLine cmd, CmdArgs cmdArgs, ParseOpti
}
}

/**
* Extract class name.
*
* @param clazz class to extract name from
* @return class name
*/
private static String extractName(Class clazz) {
String name = clazz.getName();
String[] fields = name.toLowerCase().split("\\.");
Expand All @@ -404,10 +417,11 @@ private static String extractName(Class clazz) {
* Get all the parameters related to the selected algorithm, test, and
* score.
*
* @param cmdArgs
* @param parseOptions
* @return
* @throws CmdParserException
* @param cmdArgs parsed command line arguments and values
* @param parseOptions command-line options
* @return set of parameters relating to the given algorithm, test and score
* from the command-line.
* @throws CmdParserException when an error occurs while parsing
*/
private static Set<String> getAllRelatedParameters(CmdArgs cmdArgs, ParseOptions parseOptions) throws CmdParserException {
try {
Expand All @@ -422,11 +436,11 @@ private static Set<String> getAllRelatedParameters(CmdArgs cmdArgs, ParseOptions
* for the parameters if user use the "--default" flag. Replace any value if
* user explicitly specified with parameter-arg input or flag.
*
* @param cmd
* @param cmdArgs
* @param parseOptions
* @return
* @throws CmdParserException
* @param cmd command-line input
* @param cmdArgs parsed command line arguments and values
* @param parseOptions command-line options
* @return a collection of valid parameters
* @throws CmdParserException when an error occurs while parsing
*/
private static Map<String, String> getValidParameters(CommandLine cmd, CmdArgs cmdArgs, ParseOptions parseOptions) throws CmdParserException {
Map<String, String> parametersWithValues = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Expand All @@ -439,6 +453,15 @@ private static Map<String, String> getValidParameters(CommandLine cmd, CmdArgs c
return parametersWithValues;
}

/**
* Set parameters based on user's input.
*
* @param parametersWithValues set of parameters and values
* @param parameters set of parameters
* @param cmd command-line input
* @param parseOptions command-line options
* @throws CmdParserException when an error occurs while parsing
*/
private static void setUserParameterValues(Map<String, String> parametersWithValues, Set<String> parameters, CommandLine cmd, ParseOptions parseOptions) throws CmdParserException {
ParamDescriptions paramDescriptions = ParamDescriptions.getInstance();
Options opts = parseOptions.getOptions();
Expand Down Expand Up @@ -531,11 +554,11 @@ private static void setParametersAndValues(Map<String, String> parametersWithVal
* Extract the thread number from the command-line option and check to make
* sure the number is valid.
*
* @param value
* @param parseOptions
* @param cmdParam
* @return
* @throws CmdParserException
* @param value number of threads taken from the command-line
* @param parseOptions command-line options
* @param cmdParam command-line parameter
* @return number of thread from the command-line input that is valid
* @throws CmdParserException when an error occurs while parsing
*/
private static int getValidThreadNumber(String value, ParseOptions parseOptions, String cmdParam) throws CmdParserException {
int numOfThreads = 0;
Expand Down Expand Up @@ -564,11 +587,11 @@ private static int getValidThreadNumber(String value, ParseOptions parseOptions,
* Extract the delimiter charactor from the command-line option and make
* sure the character is valid.
*
* @param quoteChar
* @param parseOptions
* @param cmdParam
* @return
* @throws CmdParserException
* @param quoteChar character from the command-line
* @param parseOptions command-line options
* @param cmdParam command-line parameter
* @return character from the command-line input that is valid
* @throws CmdParserException when an error occurs while parsing
*/
private static char getValidChar(String quoteChar, ParseOptions parseOptions, String cmdParam) throws CmdParserException {
char c = 0;
Expand All @@ -591,11 +614,11 @@ private static char getValidChar(String quoteChar, ParseOptions parseOptions, St
* Extract the file location from the command-line option and make sure the
* file is valid.
*
* @param filePath
* @param parseOptions
* @param cmdParam
* @return
* @throws CmdParserException
* @param filePath path to where the file is from the command-line input
* @param parseOptions command-line options
* @param cmdParam command-line parameter
* @return the path of the file from the command-line input that exists
* @throws CmdParserException when an error occurs while parsing
*/
private static Path getValidFile(String filePath, ParseOptions parseOptions, String cmdParam) throws CmdParserException {
Path file = Paths.get(filePath);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/edu/pitt/dbmi/causal/cmd/OptionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private OptionFactory() {
/**
* Create the required options for the help message.
*
* @return
* @return required options
*/
public static Option createRequiredHelpOpt() {
Option opt = CmdOptions.getInstance().getLongOption(CmdParams.HELP);
Expand All @@ -56,10 +56,10 @@ public static Option createRequiredHelpOpt() {
}

/**
* Create the required indepedence test options.
* Create the required options for the test of independence.
*
* @param dataType
* @return
* @param dataType data type
* @return options required options for the test of independence
*/
public static Option createRequiredTestOpt(DataType dataType) {
List<String> commands = TetradIndependenceTests.getInstance().getCommands(dataType);
Expand All @@ -78,8 +78,8 @@ public static Option createRequiredTestOpt(DataType dataType) {
/**
* Create the required score options.
*
* @param dataType
* @return
* @param dataType data type
* @return options required options for the score
*/
public static Option createRequiredScoreOpt(DataType dataType) {
List<String> commands = TetradScores.getInstance().getCommands(dataType);
Expand All @@ -98,7 +98,7 @@ public static Option createRequiredScoreOpt(DataType dataType) {
/**
* Create the required option for the number of category for mixed data.
*
* @return
* @return required option for number of categories.
*/
public static Option createRequiredNumCategoryOpt() {
Option opt = CmdOptions.getInstance().getLongOption(CmdParams.NUM_CATEGORIES);
Expand Down
51 changes: 26 additions & 25 deletions src/main/java/edu/pitt/dbmi/causal/cmd/data/DataFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ private DataFiles() {
/**
* Read in metadata file.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return metadata
* @throws IOException when errors occur during reading file
*/
public static Metadata readInMetadata(CmdArgs cmdArgs, PrintStream out) throws IOException {
Path file = cmdArgs.getMetadataFile();
Expand All @@ -94,10 +94,10 @@ public static Metadata readInMetadata(CmdArgs cmdArgs, PrintStream out) throws I
/**
* Read in knowledge file.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return knowledge information from file
* @throws IOException when errors occur during reading file
*/
public static IKnowledge readInKnowledge(CmdArgs cmdArgs, PrintStream out) throws IOException {
Path file = cmdArgs.getKnowledgeFile();
Expand All @@ -115,11 +115,12 @@ public static IKnowledge readInKnowledge(CmdArgs cmdArgs, PrintStream out) throw
/**
* Read in datasets files.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @throws AlgorithmRunException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return list of datasets read in from files
* @throws IOException when errors occur during reading file
* @throws AlgorithmRunException when dataset is not supported by the given
* algorithm from command-line
*/
public static List<DataModel> readInDatasets(CmdArgs cmdArgs, PrintStream out) throws IOException, AlgorithmRunException {
DataType dataType = cmdArgs.getDataType();
Expand All @@ -139,10 +140,10 @@ public static List<DataModel> readInDatasets(CmdArgs cmdArgs, PrintStream out) t
/**
* Read in tabular dataset files.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return list of datasets read in from files
* @throws IOException when errors occur during reading file
*/
private static List<DataModel> readInTabularData(CmdArgs cmdArgs, PrintStream out) throws IOException {
List<DataModel> dataModels = new LinkedList<>();
Expand Down Expand Up @@ -204,10 +205,10 @@ private static List<DataModel> readInTabularData(CmdArgs cmdArgs, PrintStream ou
/**
* Read in covariances files.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return list of datasets read in from files
* @throws IOException when errors occur during reading file
*/
private static List<DataModel> readInCovarianceFile(CmdArgs cmdArgs, PrintStream out) throws IOException {
List<DataModel> dataModels = new LinkedList<>();
Expand All @@ -234,10 +235,10 @@ private static List<DataModel> readInCovarianceFile(CmdArgs cmdArgs, PrintStream
/**
* Read in exclude-variable file.
*
* @param cmdArgs
* @param out
* @return
* @throws IOException
* @param cmdArgs command-line arguments
* @param out output stream to write message to
* @return set of variables to exclude reading in
* @throws IOException when errors occur during reading file
*/
public static Set<String> readInVariablesToExclude(CmdArgs cmdArgs, PrintStream out) throws IOException {
Set<String> variablesToExclude = new HashSet<>();
Expand Down
Loading

0 comments on commit 75d8525

Please sign in to comment.