List of usage examples for org.apache.commons.lang StringUtils isNotEmpty
public static boolean isNotEmpty(String str)
Checks if a String is not empty ("") and not null.
From source file:Main.java
public static void main(String[] args) { String var1 = null; String var2 = ""; String var3 = " \t\t\t"; String var4 = "Hello World"; System.out.println("var1 is blank? = " + StringUtils.isBlank(var1)); System.out.println("var2 is blank? = " + StringUtils.isBlank(var2)); System.out.println("var3 is blank? = " + StringUtils.isBlank(var3)); System.out.println("var4 is blank? = " + StringUtils.isBlank(var4)); System.out.println("var1 is not blank? = " + StringUtils.isNotBlank(var1)); System.out.println("var2 is not blank? = " + StringUtils.isNotBlank(var2)); System.out.println("var3 is not blank? = " + StringUtils.isNotBlank(var3)); System.out.println("var4 is not blank? = " + StringUtils.isNotBlank(var4)); System.out.println("var1 is empty? = " + StringUtils.isEmpty(var1)); System.out.println("var2 is empty? = " + StringUtils.isEmpty(var2)); System.out.println("var3 is empty? = " + StringUtils.isEmpty(var3)); System.out.println("var4 is empty? = " + StringUtils.isEmpty(var4)); System.out.println("var1 is not empty? = " + StringUtils.isNotEmpty(var1)); System.out.println("var2 is not empty? = " + StringUtils.isNotEmpty(var2)); System.out.println("var3 is not empty? = " + StringUtils.isNotEmpty(var3)); System.out.println("var4 is not empty? = " + StringUtils.isNotEmpty(var4)); }
From source file:gr.seab.r2rml.beans.Main.java
public static void main(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {/*from w ww .j a v a2 s .c om*/ CommandLine line = cmdParser.parse(cmdOptions, args); if (line.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("r2rml-parser\n", cmdOptions); System.exit(0); } if (line.hasOption("p")) { propertiesFile = line.getOptionValue("p"); } } catch (ParseException e1) { //e1.printStackTrace(); log.error("Error parsing command line arguments."); System.exit(1); } try { if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); } } catch (FileNotFoundException e) { //e.printStackTrace(); log.error("Properties file not found (" + propertiesFile + ")."); System.exit(1); } catch (IOException e) { //e.printStackTrace(); log.error("Error reading properties file (" + propertiesFile + ")."); System.exit(1); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:de.erdesignerng.visual.ERDesigner.java
public static void main(String[] args) throws IllegalAccessException, TransformerException, IOException, ParserConfigurationException, SAXException { String theFilenameToOpen = null; if (args != null) { for (String theArgument : args) { LOGGER.info("Was called with argument :" + theArgument); }// w ww. j av a 2s .co m // In WebStart mode or standalone, there can be two options // -open <filename> // -print <filename> if (args.length == 2) { if ("-open".equals(args[0]) || "-print".equals(args[0])) { theFilenameToOpen = args[1]; } } } // Disable D3D rendering pipeline System.setProperty("sun.java2d.d3d", "false"); //Show LOGO DefaultSplashScreen theScreen = new DefaultSplashScreen("/de/erdesignerng/splashscreen.jpg"); theScreen.setVisible(true); DataTypeIO.getInstance().loadUserTypes(); final ERDesignerMainFrame frame = new ERDesignerMainFrame(); frame.setModel(frame.createNewModel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { Thread.sleep(1000); } catch (InterruptedException e) { // Just wait here :-) } theScreen.setVisible(false); frame.setVisible(true); if (StringUtils.isNotEmpty(theFilenameToOpen)) { frame.commandOpenFile(new File(theFilenameToOpen)); } }
From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java
public static void main(String[] args) { Options options = new Options(); options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS"); options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project"); options.addOption(OVERWRITE_OPT, "overwrite", false, "overwrite existing messages by changed messages from XLS file"); options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory"); options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations"); options.addOption(LOG_FILE_OPT, "logFile", true, "log file"); options.addOption(LANGUAGES_OPT, "languages", true, "list of locales separated by comma, for example: 'de,fr'"); CommandLineParser parser = new DefaultParser(); CommandLine cmd;//from w w w . jav a2 s .com try { cmd = parser.parse(options, args); if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT) || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) { System.out.println("Please provide either 'read' or 'write' option"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT)); if (cmd.hasOption(READ_OPT)) { LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); localizationsBatch.setScanLocalizationIds(languages); LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT)); } else if (cmd.hasOption(WRITE_OPT)) { LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); sourceLocalization.setScanLocalizationIds(languages); LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT), cmd.getOptionValue(PROJECT_DIR_OPT)); fileLocalization.setScanLocalizationIds(languages); LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization, fileLocalization); String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT)) ? cmd.getOptionValue(LOG_FILE_OPT) : "log.xls"; fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT)); } } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } }
From source file:ml.shifu.shifu.util.ShifuCLI.java
/** * Main entry for the whole framework.//from w ww .jav a2 s .c om * * @throws IOException */ public static void main(String[] args) { // invalid input and help options if (args.length < 1 || (isHelpOption(args[0]))) { printUsage(); System.exit(args.length < 1 ? -1 : 0); } // process -v and -version conditions manually if (isVersionOption(args[0])) { printVersionString(); System.exit(0); } CommandLineParser parser = new GnuParser(); Options opts = buildModelSetOptions(args); CommandLine cmd = null; try { cmd = parser.parse(opts, args); } catch (ParseException e) { log.error("Invalid command options. Please check help message."); printUsage(); System.exit(1); } try { if (args[0].equals(NEW) && args.length >= 2 && StringUtils.isNotEmpty(args[1])) { // modelset step String modelName = args[1]; int status = createNewModel(modelName, cmd.getOptionValue(MODELSET_CMD_TYPE), cmd.getOptionValue(MODELSET_CMD_M)); if (status == 0) { printModelSetCreatedSuccessfulLog(modelName); } // copyModel(manager, cmd.getOptionValues(MODELSET_CMD_CP)); } else { if (args[0].equals(MODELSET_CMD_CP) && args.length >= 3 && StringUtils.isNotEmpty(args[1]) && StringUtils.isNotEmpty(args[2])) { String newModelSetName = args[2]; // modelset step copyModel(new String[] { args[1], newModelSetName }); printModelSetCopiedSuccessfulLog(newModelSetName); } else if (args[0].equals(INIT_CMD)) { // init step if (cmd.getOptions() == null || cmd.getOptions().length == 0) { int status = initializeModel(); if (status == 0) { log.info( "ModelSet initilization is successful. Please continue next step by using 'shifu stats'."); } } else if (cmd.hasOption(INIT_CMD_MODEL)) { initializeModelParam(); } else { log.error("Invalid command, please check help message."); printUsage(); } } else if (args[0].equals(STATS_CMD)) { // stats step calModelStats(); log.info( "Do model set statistics successfully. Please continue next step by using 'shifu varselect'."); } else if (args[0].equals(NORMALIZE_CMD)) { // normalize step normalizeTrainData(); log.info( "Do model set normalization successfully. Please continue next step by using 'shifu train'."); } else if (args[0].equals(VARSELECT_CMD)) { // variable selected step selectModelVar(); log.info( "Do model set variables selection successfully. Please continue next step by using 'shifu normalize'."); } else if (args[0].equals(TRAIN_CMD)) { // train step trainModel(cmd.hasOption(TRAIN_CMD_DRY), cmd.hasOption(TRAIN_CMD_DEBUG)); log.info( "Do model set training successfully. Please continue next step by using 'shifu posttrain' or if no need posttrain you can go through with 'shifu eval'."); } else if (args[0].equals(POSTTRAIN_CMD)) { // post train step postTrainModel(); log.info( "Do model set post-training successfully. Please configurate your eval set in ModelConfig.json and continue next step by using 'shifu eval' or 'shifu eval -new <eval set>' to create a new eval set."); } else if (args[0].equals(SAVE)) { String newModelSetName = args.length >= 2 ? args[1] : null; saveCurrentModel(newModelSetName); } else if (args[0].equals(SWITCH)) { String newModelSetName = args[1]; switchCurrentModel(newModelSetName); } else if (args[0].equals(SHOW)) { ManageModelProcessor p = new ManageModelProcessor(ModelAction.SHOW, null); p.run(); } else if (args[0].equals(EVAL_CMD)) { // eval step if (args.length == 1) { //run everything runEvalSet(cmd.hasOption(TRAIN_CMD_DRY)); log.info("Run eval performance with all eval sets successfully."); } else if (cmd.getOptionValue(MODELSET_CMD_NEW) != null) { //create new eval createNewEvalSet(cmd.getOptionValue(MODELSET_CMD_NEW)); log.info( "Create eval set successfully. You can configurate EvalConfig.json or directly run 'shifu eval -run <evalSetName>' to get performance info."); } else if (cmd.hasOption(EVAL_CMD_RUN)) { runEvalSet(cmd.getOptionValue(EVAL_CMD_RUN), cmd.hasOption(TRAIN_CMD_DRY)); log.info("Finish run eval performance with eval set {}.", cmd.getOptionValue(EVAL_CMD_RUN)); } else if (cmd.hasOption(SCORE)) { //run score runEvalScore(cmd.getOptionValue(SCORE)); log.info("Finish run score with eval set {}.", cmd.getOptionValue(SCORE)); } else if (cmd.hasOption(CONFMAT)) { //run confusion matrix runEvalConfMat(cmd.getOptionValue(CONFMAT)); log.info("Finish run confusion matrix with eval set {}.", cmd.getOptionValue(CONFMAT)); } else if (cmd.hasOption(PERF)) { //run perfermance runEvalPerf(cmd.getOptionValue(PERF)); log.info("Finish run performance maxtrix with eval set {}.", cmd.getOptionValue(PERF)); } else if (cmd.hasOption(LIST)) { //list all evaluation sets listEvalSet(); } else if (cmd.hasOption(DELETE)) { // delete some evaluation set deleteEvalSet(cmd.getOptionValue(DELETE)); } else { log.error("Invalid command, please check help message."); printUsage(); } } else { log.error("Invalid command, please check help message."); printUsage(); } } } catch (ShifuException e) { // need define error code in each step. log.error(e.getError().toString(), e.getCause()); exceptionExit(e); } catch (Exception e) { exceptionExit(e); } }
From source file:com.baidu.rigel.biplatform.ma.file.serv.FileServer.java
/** * /*w w w. j av a 2s . c o m*/ * ???server * * @param args */ public static void main(String[] args) throws Exception { // if (args.length != 1) { // LOGGER.error("can not get enough parameters for starting file server"); // printUsage(); // System.exit(-1); // } FileInputStream fis = null; String classLocation = FileServer.class.getProtectionDomain().getCodeSource().getLocation().toString(); final File configFile = new File(classLocation + "/../conf/fileserver.conf"); Properties properties = new Properties(); try { if (configFile.exists()) { fis = new FileInputStream(configFile); } else if (StringUtils.isNotEmpty(args[0])) { fis = new FileInputStream(args[0]); } else { printUsage(); throw new RuntimeException("can't find correct file server configuration file!"); } properties.load(fis); } finally { if (fis != null) { fis.close(); } } int port = -1; try { port = Integer.valueOf(properties.getProperty(PORT_NUM_KEY)); } catch (NumberFormatException e) { LOGGER.error("parameter is not correct, [port = {}]", args[0]); System.exit(-1); } String location = properties.getProperty(ROOT_DIR_KEY); if (StringUtils.isEmpty(location)) { LOGGER.error("the location can not be empty"); System.exit(-1); } File f = new File(location); if (!f.exists() && !f.mkdirs()) { LOGGER.error("invalidation location [{}] please verify the input", args[1]); System.exit(-1); } startServer(location, port); }
From source file:com.mindcognition.mindraider.MindRaiderApplication.java
/** * The main procedure.//from www.ja va 2s.c om * * @param args * program arguments. */ public static void main(String[] args) { boolean help = false; boolean debugMode = false; // analyze arguments if (args != null) { // while there are some arguments try to consume them int i = 0; while (i < args.length) { if (ARG_HELP.equals(args[i]) || "--help".equals(args[i]) //$NON-NLS-1$ || "/h".equals(args[i]) || "/?".equals(args[i])) { //$NON-NLS-1$ //$NON-NLS-2$ help = true; } else { if (ARG_PROFILE.equals(args[i])) { // take next arg - there is path to the profile i++; MindRaider.profilesDirectory = args[i]; } else { if (ARG_TWIKI_IMPORT.equals(args[i])) { // take next arg - there is path to the twiki file // to be imported i++; String command = args[i]; if (StringUtils.isNotEmpty(command)) { new Commander(COMMAND_TWIKI_IMPORT + command); } else { System.err.println(MindRaiderApplication.getString("MindRaiderApplication.0") //$NON-NLS-1$ + command + MindRaiderApplication.getString("MindRaiderApplication.1")); //$NON-NLS-1$ } System.exit(0); } else { if (ARG_DEBUG.equals(args[i])) { debugMode = true; } else { System.out.println( MindRaiderApplication.getString("MindRaiderApplication.11") + args[i]); //$NON-NLS-1$ help = true; } } } } i++; } // process arguments if (help) { help(); return; } } // reset log4j configuration try { BasicConfigurator.resetConfiguration(); if (debugMode) { PropertyConfigurator.configure(System.getProperty("log4j.configuration.debug")); //$NON-NLS-1$ } else { String log4jconfig = System.getProperty("log4j.configuration"); PropertyConfigurator.configure(log4jconfig); //$NON-NLS-1$ } } catch (Throwable e) { logger.debug(getString(MindRaiderApplication.getString("MindRaiderApplication.2"))); //$NON-NLS-1$ BasicConfigurator.resetConfiguration(); } logger.debug(MindRaider.getTitle()); String javaVersion; try { javaVersion = System.getProperty("java.version"); //$NON-NLS-1$ } catch (NullPointerException e) { javaVersion = ""; //$NON-NLS-1$ } logger.debug(getString("MindRaiderApplication.javaVersion", new Object[] { javaVersion, System.getProperty("java.vendor"), System.getProperty("java.home") })); if (javaVersion.compareTo("1.1.2") < 0) { logger.debug(getString("MindRaiderApplication.swing112version")); return; } // initialization if (MindRaiderConstants.EARLY_ACCESS) { MindRaider.setUser(System.getProperty("user.name"), System.getProperty("user.home") + File.separator + MindRaiderConstants.MR + "-eap"); //$NON-NLS-1$ } else { MindRaider.setUser(System.getProperty("user.name"), System //$NON-NLS-1$ .getProperty("user.home")); //$NON-NLS-1$ } MindRaider.setInstallationDirectory(System.getProperty("user.dir")); //$NON-NLS-1$ logger.debug(getString("MindRaiderApplication.installationDirectory", MindRaider.installationDirectory)); logger.debug(getString("MindRaiderApplication.profileName", MindRaider.user.getName())); logger.debug(getString("MindRaiderApplication.userHome", MindRaider.user.getHome())); MindRaider.eapProfilesDirectory = System.getProperty("user.home") + File.separator + MindRaiderConstants.MR + "-eap" + File.separator + ".mindraider.profile.eap"; // set profile if (MindRaider.profilesDirectory == null) { if (MindRaiderConstants.EARLY_ACCESS) { MindRaider.profilesDirectory = MindRaider.eapProfilesDirectory; } else { MindRaider.profilesDirectory = MindRaider.user.getHome() + File.separator + ".mindraider.profile"; //$NON-NLS-1$ } } MindRaider.setMainJFrame(MindRaiderMainWindow.getInstance()); }
From source file:com.nimbits.MainClass.java
public static void main(final String[] args) throws IOException, XMPPException, NimbitsException { final HashMap<String, String> argsMap = new HashMap<String, String>(); if (args == null || args.length == 0) { printUsage();/*w w w . j av a 2s. c o m*/ return; } else { processArgs(args, argsMap); } if (argsMap.containsKey(Parameters.i.getText())) { String[] fileArgs = KeyFile.processKeyFile(argsMap); processArgs(fileArgs, argsMap); } final boolean verbose = argsMap.containsKey(Parameters.verbose.getText()); final boolean listen = argsMap.containsKey(Parameters.listen.getText()); final String host = argsMap.containsKey(Parameters.host.getText()) ? argsMap.get(Parameters.host.getText()) : Path.PATH_NIMBITS_PUBLIC_SERVER; final String emailParam = argsMap.containsKey(Parameters.email.getText()) ? argsMap.get(Parameters.email.getText()) : null; final String key = argsMap.containsKey(Parameters.key.getText()) ? argsMap.get(Parameters.key.getText()) : null; final String appId = argsMap.containsKey(Parameters.appid.getText()) ? argsMap.get(Parameters.appid.getText()) : null; final String password = argsMap.containsKey(Parameters.password.getText()) ? argsMap.get(Parameters.password.getText()) : null; final String protocol = argsMap.containsKey(Parameters.protocol.getText()) ? argsMap.get(Parameters.protocol.getText()) : null; if (StringUtils.isEmpty(emailParam)) { throw new NimbitsException("you must specify an account i.e. email=test@example.com"); } if (StringUtils.isNotEmpty(host) && StringUtils.isNotEmpty(emailParam) & StringUtils.isNotEmpty(key)) { createClient(host, emailParam, key, password); } // // if (!loggedIn) { // out(true, "Access Denied."); // return; // } if (argsMap.containsKey(Parameters.action.getText())) { Action action = Action.valueOf(argsMap.get(Parameters.action.getText())); switch (action) { case read: case readValue: case readGps: case readJson: case readNote: readValue(argsMap, action); break; case record: case recordValue: recordValue(argsMap, verbose); break; case listen: listen(appId, protocol, emailParam); break; default: printUsage(); } } else if (argsMap.containsKey(Parameters.genkey.getText()) && argsMap.containsKey(Parameters.out.getText())) { out(true, KeyFile.genKey(argsMap)); } out(true, "exiting"); }
From source file:com.cws.esolutions.core.main.EmailUtility.java
public static final void main(final String[] args) { final String methodName = EmailUtility.CNAME + "#main(final String[] args)"; if (DEBUG) {//from w w w. j av a 2 s . c o m DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", (Object) args); } if (args.length == 0) { HelpFormatter usage = new HelpFormatter(); usage.printHelp(EmailUtility.CNAME, options, true); return; } try { CommandLineParser parser = new PosixParser(); CommandLine commandLine = parser.parse(options, args); URL xmlURL = null; JAXBContext context = null; Unmarshaller marshaller = null; CoreConfigurationData configData = null; xmlURL = FileUtils.getFile(commandLine.getOptionValue("config")).toURI().toURL(); context = JAXBContext.newInstance(CoreConfigurationData.class); marshaller = context.createUnmarshaller(); configData = (CoreConfigurationData) marshaller.unmarshal(xmlURL); EmailMessage message = new EmailMessage(); message.setMessageTo(new ArrayList<String>(Arrays.asList(commandLine.getOptionValues("to")))); message.setMessageSubject(commandLine.getOptionValue("subject")); message.setMessageBody((String) commandLine.getArgList().get(0)); message.setEmailAddr((StringUtils.isNotEmpty(commandLine.getOptionValue("from"))) ? new ArrayList<String>(Arrays.asList(commandLine.getOptionValue("from"))) : new ArrayList<String>(Arrays.asList(configData.getMailConfig().getMailFrom()))); if (DEBUG) { DEBUGGER.debug("EmailMessage: {}", message); } try { EmailUtils.sendEmailMessage(configData.getMailConfig(), message, false); } catch (MessagingException mx) { System.err.println( "An error occurred while sending the requested message. Exception: " + mx.getMessage()); } } catch (ParseException px) { px.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(EmailUtility.CNAME, options, true); } catch (MalformedURLException mx) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(EmailUtility.CNAME, options, true); } catch (JAXBException jx) { jx.printStackTrace(); System.err.println("An error occurred while loading the provided configuration file. Cannot continue."); } }
From source file:ml.shifu.shifu.ShifuCLI.java
public static void main(String[] args) { String[] cleanedArgs = cleanArgs(args); // invalid input and help options if (cleanedArgs.length < 1 || (isHelpOption(cleanedArgs[0]))) { printUsage();//from w w w .j a va2 s. c o m System.exit(cleanedArgs.length < 1 ? -1 : 0); } // process -v and -version conditions manually if (isVersionOption(cleanedArgs[0])) { printLogoAndVersion(); System.exit(0); } CommandLineParser parser = new GnuParser(); Options opts = buildModelSetOptions(); CommandLine cmd = null; try { cmd = parser.parse(opts, cleanedArgs); } catch (ParseException e) { log.error("Invalid command options. Please check help message."); printUsage(); System.exit(1); } int status = 0; try { if (cleanedArgs[0].equals(NEW) && cleanedArgs.length >= 2 && StringUtils.isNotEmpty(cleanedArgs[1])) { // modelset step String modelName = cleanedArgs[1]; status = createNewModel(modelName, cmd.getOptionValue(MODELSET_CMD_TYPE), cmd.getOptionValue(MODELSET_CMD_M)); if (status == 0) { printModelSetCreatedSuccessfulLog(modelName); } else { log.warn("Error in create new model set, please check your shifu config or report issue"); } System.exit(status); // copyModel(manager, cmd.getOptionValues(MODELSET_CMD_CP)); } else { if (cleanedArgs[0].equals(MODELSET_CMD_CP) && cleanedArgs.length >= 3 && StringUtils.isNotEmpty(cleanedArgs[1]) && StringUtils.isNotEmpty(cleanedArgs[2])) { String newModelSetName = cleanedArgs[2]; // modelset step copyModel(new String[] { cleanedArgs[1], newModelSetName }); printModelSetCopiedSuccessfulLog(newModelSetName); } else if (cleanedArgs[0].equals(INIT_CMD)) { // init step if (cmd.getOptions() == null || cmd.getOptions().length == 0) { status = initializeModel(); if (status == 0) { log.info( "ModelSet initialization is successful. Please continue next step by using 'shifu stats'."); } else { log.warn( "Error in ModelSet initialization, please check your shifu config or report issue"); } } else if (cmd.hasOption(INIT_CMD_MODEL)) { initializeModelParam(); } else { log.error("Invalid command, please check help message."); printUsage(); } } else if (cleanedArgs[0].equals(STATS_CMD)) { Map<String, Object> params = new HashMap<String, Object>(); params.put(Constants.IS_COMPUTE_CORR, cmd.hasOption(CORRELATION) || cmd.hasOption(SHORT_CORRELATION)); params.put(Constants.IS_REBIN, cmd.hasOption(REBIN)); params.put(Constants.REQUEST_VARS, cmd.getOptionValue(VARS)); params.put(Constants.EXPECTED_BIN_NUM, cmd.getOptionValue(N)); params.put(Constants.IV_KEEP_RATIO, cmd.getOptionValue(IVR)); params.put(Constants.MINIMUM_BIN_INST_CNT, cmd.getOptionValue(BIC)); params.put(Constants.IS_COMPUTE_PSI, cmd.hasOption(PSI) || cmd.hasOption(SHORT_PSI)); // stats step status = calModelStats(params); if (status == 0) { if (cmd.hasOption(CORRELATION) || cmd.hasOption(SHORT_CORRELATION)) { log.info( "Do model set correlation computing successfully. Please continue next step by using 'shifu normalize or shifu norm'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'"); } if (cmd.hasOption(PSI) || cmd.hasOption(SHORT_PSI)) { log.info( "Do model set psi computing successfully. Please continue next step by using 'shifu normalize or shifu norm'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'"); } else { log.info( "Do model set statistic successfully. Please continue next step by using 'shifu normalize or shifu norm or shifu transform'. For tree ensemble model, no need do norm, please continue next step by using 'shifu varsel'"); } } else { log.warn( "Error in model set stats computation, please report issue on http:/github.com/shifuml/shifu/issues."); } } else if (cleanedArgs[0].equals(NORMALIZE_CMD) || cleanedArgs[0].equals(NORM_CMD) || cleanedArgs[0].equals(TRANSFORM_CMD)) { // normalize step Map<String, Object> params = new HashMap<String, Object>(); params.put(Constants.IS_TO_SHUFFLE_DATA, cmd.hasOption(SHUFFLE)); status = normalizeTrainData(params); if (status == 0) { log.info( "Do model set normalization successfully. Please continue next step by using 'shifu varselect or shifu varsel'."); } else { log.warn( "Error in model set stats computation, please report issue on http:/github.com/shifuml/shifu/issues."); } } else if (cleanedArgs[0].equals(VARSELECT_CMD) || cleanedArgs[0].equals(VARSEL_CMD)) { Map<String, Object> params = new HashMap<String, Object>(); params.put(Constants.IS_TO_RESET, cmd.hasOption(RESET)); params.put(Constants.IS_TO_LIST, cmd.hasOption(LIST)); params.put(Constants.IS_TO_FILTER_AUTO, cmd.hasOption(FILTER_AUTO)); params.put(Constants.IS_TO_RECOVER_AUTO, cmd.hasOption(RECOVER_AUTO)); params.put(Constants.RECURSIVE_CNT, cmd.getOptionValue(RECURSIVE)); // variable selected step status = selectModelVar(params); if (status == 0) { log.info( "Do model set variables selection successfully. Please continue next step by using 'shifu train'."); } else { log.info("Do variable selection with error, please check error message or report issue."); } } else if (cleanedArgs[0].equals(TRAIN_CMD)) { // train step status = trainModel(cmd.hasOption(TRAIN_CMD_DRY), cmd.hasOption(TRAIN_CMD_DEBUG), cmd.hasOption(SHUFFLE)); if (status == 0) { log.info( "Do model set training successfully. Please continue next step by using 'shifu posttrain' or if no need posttrain you can go through with 'shifu eval'."); } else { log.info("Do model training with error, please check error message or report issue."); } } else if (cleanedArgs[0].equals(CMD_ENCODE)) { Map<String, Object> params = new HashMap<String, Object>(); params.put(ModelDataEncodeProcessor.ENCODE_DATA_SET, cmd.getOptionValue(EVAL_CMD_RUN)); params.put(ModelDataEncodeProcessor.ENCODE_REF_MODEL, cmd.getOptionValue(REF)); status = runEncode(params); } else if (cleanedArgs[0].equals(CMD_COMBO)) { if (cmd.hasOption(MODELSET_CMD_NEW)) { log.info("Create new commbo models"); status = createNewCombo(cmd.getOptionValue(MODELSET_CMD_NEW)); } else if (cmd.hasOption(INIT_CMD)) { log.info("Init commbo models"); status = initComboModels(); } else if (cmd.hasOption(EVAL_CMD_RUN)) { log.info("Run combo model - with toShuffle: {}, with toResume: {}", opts.hasOption(SHUFFLE), opts.hasOption(RESUME)); status = runComboModels(cmd.hasOption(SHUFFLE), cmd.hasOption(RESUME)); // train combo models } else if (cmd.hasOption(EVAL_CMD)) { log.info("Eval combo model."); // eval combo model performance status = evalComboModels(cmd.hasOption(RESUME)); } else { log.error("Invalid command usage."); printUsage(); } } else if (cleanedArgs[0].equals(POSTTRAIN_CMD)) { // post train step status = postTrainModel(); if (status == 0) { log.info( "Do model set post-training successfully. Please configure your eval set in ModelConfig.json and continue next step by using 'shifu eval' or 'shifu eval -new <eval set>' to create a new eval set."); } else { log.info("Do model post training with error, please check error message or report issue."); } } else if (cleanedArgs[0].equals(SAVE)) { String newModelSetName = cleanedArgs.length >= 2 ? cleanedArgs[1] : null; saveCurrentModel(newModelSetName); } else if (cleanedArgs[0].equals(SWITCH)) { String newModelSetName = cleanedArgs[1]; switchCurrentModel(newModelSetName); } else if (cleanedArgs[0].equals(SHOW)) { ManageModelProcessor p = new ManageModelProcessor(ModelAction.SHOW, null); p.run(); } else if (cleanedArgs[0].equals(EVAL_CMD)) { Map<String, Object> params = new HashMap<String, Object>(); // eval step if (cleanedArgs.length == 1) { // run everything status = runEvalSet(cmd.hasOption(TRAIN_CMD_DRY)); if (status == 0) { log.info("Run eval performance with all eval sets successfully."); } else { log.info("Do evaluation with error, please check error message or report issue."); } } else if (cmd.getOptionValue(MODELSET_CMD_NEW) != null) { // create new eval createNewEvalSet(cmd.getOptionValue(MODELSET_CMD_NEW)); log.info( "Create eval set successfully. You can configure EvalConfig.json or directly run 'shifu eval -run <evalSetName>' to get performance info."); } else if (cmd.hasOption(EVAL_CMD_RUN)) { runEvalSet(cmd.getOptionValue(EVAL_CMD_RUN), cmd.hasOption(TRAIN_CMD_DRY)); log.info("Finish run eval performance with eval set {}.", cmd.getOptionValue(EVAL_CMD_RUN)); } else if (cmd.hasOption(SCORE)) { params.put(EvalModelProcessor.NOSORT, cmd.hasOption(NOSORT)); // run score runEvalScore(cmd.getOptionValue(SCORE), params); log.info("Finish run score with eval set {}.", cmd.getOptionValue(SCORE)); } else if (cmd.hasOption(CONFMAT)) { // run confusion matrix runEvalConfMat(cmd.getOptionValue(CONFMAT)); log.info("Finish run confusion matrix with eval set {}.", cmd.getOptionValue(CONFMAT)); } else if (cmd.hasOption(PERF)) { // run perfermance runEvalPerf(cmd.getOptionValue(PERF)); log.info("Finish run performance maxtrix with eval set {}.", cmd.getOptionValue(PERF)); } else if (cmd.hasOption(LIST)) { // list all evaluation sets listEvalSet(); } else if (cmd.hasOption(DELETE)) { // delete some evaluation set deleteEvalSet(cmd.getOptionValue(DELETE)); } else if (cmd.hasOption(NORM)) { runEvalNorm(cmd.getOptionValue(NORM), cmd.hasOption(STRICT)); } else { log.error("Invalid command, please check help message."); printUsage(); } } else if (cleanedArgs[0].equals(CMD_EXPORT)) { Map<String, Object> params = new HashMap<String, Object>(); params.put(ExportModelProcessor.IS_CONCISE, cmd.hasOption(EXPORT_CONCISE)); params.put(ExportModelProcessor.REQUEST_VARS, cmd.getOptionValue(VARS)); params.put(ExportModelProcessor.EXPECTED_BIN_NUM, cmd.getOptionValue(N)); params.put(ExportModelProcessor.IV_KEEP_RATIO, cmd.getOptionValue(IVR)); params.put(ExportModelProcessor.MINIMUM_BIN_INST_CNT, cmd.getOptionValue(BIC)); status = exportModel(cmd.getOptionValue(MODELSET_CMD_TYPE), params); if (status == 0) { log.info("Export models/columnstats/corr successfully."); } else { log.warn("Fail to export models/columnstats/corr, please check or report issue."); } } else if (cleanedArgs[0].equals(CMD_TEST)) { Map<String, Object> params = new HashMap<String, Object>(); params.put(ShifuTestProcessor.IS_TO_TEST_FILTER, cmd.hasOption(FILTER)); params.put(ShifuTestProcessor.TEST_TARGET, cmd.getOptionValue(FILTER)); params.put(ShifuTestProcessor.TEST_RECORD_CNT, cmd.getOptionValue(N)); status = runShifuTest(params); if (status == 0) { log.info("Run test for Shifu Successfully."); } else { log.warn("Fail to run Shifu test."); } } else if (cleanedArgs[0].equals(CMD_CONVERT)) { int optType = -1; if (cmd.hasOption(TO_ZIPB)) { optType = 1; } else if (cmd.hasOption(TO_TREEB)) { optType = 2; } String[] convertArgs = new String[2]; int j = 0; for (int i = 1; i < cleanedArgs.length; i++) { if (!cleanedArgs[i].startsWith("-")) { convertArgs[j++] = cleanedArgs[i]; } } if (optType < 0 || StringUtils.isBlank(convertArgs[0]) || StringUtils.isBlank(convertArgs[1])) { printUsage(); } else { status = runShifuConvert(optType, convertArgs[0], convertArgs[1]); } } else if (cleanedArgs[0].equals(CMD_ANALYSIS)) { if (cmd.hasOption(FI)) { String modelPath = cmd.getOptionValue(FI); analysisModelFi(modelPath); } } else { log.error("Invalid command, please check help message."); printUsage(); } } // for some case jvm cannot stop System.exit(status); } catch (ShifuException e) { // need define error code in each step. log.error(e.getError().toString() + "; msg: " + e.getMessage(), e.getCause()); exceptionExit(e); } catch (Exception e) { exceptionExit(e); } }