Example usage for org.apache.commons.cli Option Option

List of usage examples for org.apache.commons.cli Option Option

Introduction

In this page you can find the example usage for org.apache.commons.cli Option Option.

Prototype

public Option(String opt, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:com.jug.MoMA.java

/**
 * PROJECT MAIN/* w w w  . j  ava 2  s.c om*/
 *
 * @param args
 */
public static void main(final String[] args) {
    if (showIJ)
        new ImageJ();

    //      // ===== set look and feel ========================================================================
    //      try {
    //         // Set cross-platform Java L&F (also called "Metal")
    //         UIManager.setLookAndFeel(
    //               UIManager.getCrossPlatformLookAndFeelClassName() );
    //      } catch ( final UnsupportedLookAndFeelException e ) {
    //         // handle exception
    //      } catch ( final ClassNotFoundException e ) {
    //         // handle exception
    //      } catch ( final InstantiationException e ) {
    //         // handle exception
    //      } catch ( final IllegalAccessException e ) {
    //         // handle exception
    //      }

    // ===== command line parsing ======================================================================

    // create Options object & the parser
    final Options options = new Options();
    final CommandLineParser parser = new BasicParser();
    // defining command line options
    final Option help = new Option("help", "print this message");

    final Option headless = new Option("h", "headless", false,
            "start without user interface (note: input-folder must be given!)");
    headless.setRequired(false);

    final Option timeFirst = new Option("tmin", "min_time", true, "first time-point to be processed");
    timeFirst.setRequired(false);

    final Option timeLast = new Option("tmax", "max_time", true, "last time-point to be processed");
    timeLast.setRequired(false);

    final Option optRange = new Option("orange", "opt_range", true, "initial optimization range");
    optRange.setRequired(false);

    final Option numChannelsOption = new Option("c", "channels", true,
            "number of channels to be loaded and analyzed.");
    numChannelsOption.setRequired(true);

    final Option minChannelIdxOption = new Option("cmin", "min_channel", true,
            "the smallest channel index (usually 0 or 1, default is 1).");
    minChannelIdxOption.setRequired(false);

    final Option infolder = new Option("i", "infolder", true, "folder to read data from");
    infolder.setRequired(false);

    final Option outfolder = new Option("o", "outfolder", true,
            "folder to write preprocessed data to (equals infolder if not given)");
    outfolder.setRequired(false);

    final Option userProps = new Option("p", "props", true, "properties file to be loaded (mm.properties)");
    userProps.setRequired(false);

    options.addOption(help);
    options.addOption(headless);
    options.addOption(numChannelsOption);
    options.addOption(minChannelIdxOption);
    options.addOption(timeFirst);
    options.addOption(timeLast);
    options.addOption(optRange);
    options.addOption(infolder);
    options.addOption(outfolder);
    options.addOption(userProps);
    // get the commands parsed
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (final ParseException e1) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "... [-p props-file] -i in-folder [-o out-folder] -c <num-channels> [-cmin start-channel-ids] [-tmin idx] [-tmax idx] [-orange num-frames] [-headless]",
                "", options, "Error: " + e1.getMessage());
        System.exit(0);
    }

    if (cmd.hasOption("help")) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("... -i <in-folder> -o [out-folder] [-headless]", options);
        System.exit(0);
    }

    if (cmd.hasOption("h")) {
        System.out.println(">>> Starting MM in headless mode.");
        HEADLESS = true;
        if (!cmd.hasOption("i")) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Headless-mode requires option '-i <in-folder>'...", options);
            System.exit(0);
        }
    }

    File inputFolder = null;
    if (cmd.hasOption("i")) {
        inputFolder = new File(cmd.getOptionValue("i"));

        if (!inputFolder.isDirectory()) {
            System.out.println("Error: Input folder is not a directory!");
            System.exit(2);
        }
        if (!inputFolder.canRead()) {
            System.out.println("Error: Input folder cannot be read!");
            System.exit(2);
        }
    }

    File outputFolder = null;
    if (!cmd.hasOption("o")) {
        if (inputFolder == null) {
            System.out.println(
                    "Error: Output folder would be set to a 'null' input folder! Please check your command line arguments...");
            System.exit(3);
        }
        outputFolder = inputFolder;
        STATS_OUTPUT_PATH = outputFolder.getAbsolutePath();
    } else {
        outputFolder = new File(cmd.getOptionValue("o"));

        if (!outputFolder.isDirectory()) {
            System.out.println("Error: Output folder is not a directory!");
            System.exit(3);
        }
        if (!inputFolder.canWrite()) {
            System.out.println("Error: Output folder cannot be written to!");
            System.exit(3);
        }

        STATS_OUTPUT_PATH = outputFolder.getAbsolutePath();
    }

    fileUserProps = null;
    if (cmd.hasOption("p")) {
        fileUserProps = new File(cmd.getOptionValue("p"));
    }

    if (cmd.hasOption("cmin")) {
        minChannelIdx = Integer.parseInt(cmd.getOptionValue("cmin"));
    }
    if (cmd.hasOption("c")) {
        numChannels = Integer.parseInt(cmd.getOptionValue("c"));
    }

    if (cmd.hasOption("tmin")) {
        minTime = Integer.parseInt(cmd.getOptionValue("tmin"));
    }
    if (cmd.hasOption("tmax")) {
        maxTime = Integer.parseInt(cmd.getOptionValue("tmax"));
    }

    if (cmd.hasOption("orange")) {
        initOptRange = Integer.parseInt(cmd.getOptionValue("orange"));
    }

    // ******** CHECK GUROBI ********* CHECK GUROBI ********* CHECK GUROBI *********
    final String jlp = System.getProperty("java.library.path");
    //      System.out.println( jlp );
    try {
        new GRBEnv("MoMA_gurobi.log");
    } catch (final GRBException e) {
        final String msgs = "Initial Gurobi test threw exception... check your Gruobi setup!\n\nJava library path: "
                + jlp;
        if (HEADLESS) {
            System.out.println(msgs);
        } else {
            JOptionPane.showMessageDialog(MoMA.guiFrame, msgs, "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
        }
        e.printStackTrace();
        System.exit(98);
    } catch (final UnsatisfiedLinkError ulr) {
        final String msgs = "Could initialize Gurobi.\n"
                + "You might not have installed Gurobi properly or you miss a valid license.\n"
                + "Please visit 'www.gurobi.com' for further information.\n\n" + ulr.getMessage()
                + "\nJava library path: " + jlp;
        if (HEADLESS) {
            System.out.println(msgs);
        } else {
            JOptionPane.showMessageDialog(MoMA.guiFrame, msgs, "Gurobi Error?", JOptionPane.ERROR_MESSAGE);
            ulr.printStackTrace();
        }
        System.out.println("\n>>>>> Java library path: " + jlp + "\n");
        System.exit(99);
    }
    // ******* END CHECK GUROBI **** END CHECK GUROBI **** END CHECK GUROBI ********

    final MoMA main = new MoMA();
    if (!HEADLESS) {
        guiFrame = new JFrame();
        main.initMainWindow(guiFrame);
    }

    System.out.println("VERSION: " + VERSION_STRING);

    props = main.loadParams();
    BGREM_TEMPLATE_XMIN = Integer
            .parseInt(props.getProperty("BGREM_TEMPLATE_XMIN", Integer.toString(BGREM_TEMPLATE_XMIN)));
    BGREM_TEMPLATE_XMAX = Integer
            .parseInt(props.getProperty("BGREM_TEMPLATE_XMAX", Integer.toString(BGREM_TEMPLATE_XMAX)));
    BGREM_X_OFFSET = Integer.parseInt(props.getProperty("BGREM_X_OFFSET", Integer.toString(BGREM_X_OFFSET)));
    GL_WIDTH_IN_PIXELS = Integer
            .parseInt(props.getProperty("GL_WIDTH_IN_PIXELS", Integer.toString(GL_WIDTH_IN_PIXELS)));
    MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS = Integer.parseInt(props.getProperty(
            "MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS", Integer.toString(MOTHER_CELL_BOTTOM_TRICK_MAX_PIXELS)));
    GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS = Integer
            .parseInt(props.getProperty("GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS",
                    Integer.toString(GL_FLUORESCENCE_COLLECTION_WIDTH_IN_PIXELS)));
    GL_OFFSET_BOTTOM = Integer
            .parseInt(props.getProperty("GL_OFFSET_BOTTOM", Integer.toString(GL_OFFSET_BOTTOM)));
    if (GL_OFFSET_BOTTOM == -1) {
        GL_OFFSET_BOTTOM_AUTODETECT = true;
    } else {
        GL_OFFSET_BOTTOM_AUTODETECT = false;
    }
    GL_OFFSET_TOP = Integer.parseInt(props.getProperty("GL_OFFSET_TOP", Integer.toString(GL_OFFSET_TOP)));
    GL_OFFSET_LATERAL = Integer
            .parseInt(props.getProperty("GL_OFFSET_LATERAL", Integer.toString(GL_OFFSET_LATERAL)));
    MIN_CELL_LENGTH = Integer.parseInt(props.getProperty("MIN_CELL_LENGTH", Integer.toString(MIN_CELL_LENGTH)));
    MIN_GAP_CONTRAST = Float
            .parseFloat(props.getProperty("MIN_GAP_CONTRAST", Float.toString(MIN_GAP_CONTRAST)));
    SIGMA_PRE_SEGMENTATION_X = Float.parseFloat(
            props.getProperty("SIGMA_PRE_SEGMENTATION_X", Float.toString(SIGMA_PRE_SEGMENTATION_X)));
    SIGMA_PRE_SEGMENTATION_Y = Float.parseFloat(
            props.getProperty("SIGMA_PRE_SEGMENTATION_Y", Float.toString(SIGMA_PRE_SEGMENTATION_Y)));
    SIGMA_GL_DETECTION_X = Float
            .parseFloat(props.getProperty("SIGMA_GL_DETECTION_X", Float.toString(SIGMA_GL_DETECTION_X)));
    SIGMA_GL_DETECTION_Y = Float
            .parseFloat(props.getProperty("SIGMA_GL_DETECTION_Y", Float.toString(SIGMA_GL_DETECTION_Y)));
    SEGMENTATION_MIX_CT_INTO_PMFRF = Float.parseFloat(props.getProperty("SEGMENTATION_MIX_CT_INTO_PMFRF",
            Float.toString(SEGMENTATION_MIX_CT_INTO_PMFRF)));
    SEGMENTATION_CLASSIFIER_MODEL_FILE = props.getProperty("SEGMENTATION_CLASSIFIER_MODEL_FILE",
            SEGMENTATION_CLASSIFIER_MODEL_FILE);
    CELLSIZE_CLASSIFIER_MODEL_FILE = props.getProperty("CELLSIZE_CLASSIFIER_MODEL_FILE",
            CELLSIZE_CLASSIFIER_MODEL_FILE);
    DEFAULT_PATH = props.getProperty("DEFAULT_PATH", DEFAULT_PATH);

    GUROBI_TIME_LIMIT = Double
            .parseDouble(props.getProperty("GUROBI_TIME_LIMIT", Double.toString(GUROBI_TIME_LIMIT)));
    GUROBI_MAX_OPTIMALITY_GAP = Double.parseDouble(
            props.getProperty("GUROBI_MAX_OPTIMALITY_GAP", Double.toString(GUROBI_MAX_OPTIMALITY_GAP)));

    GUI_POS_X = Integer.parseInt(props.getProperty("GUI_POS_X", Integer.toString(DEFAULT_GUI_POS_X)));
    GUI_POS_Y = Integer.parseInt(props.getProperty("GUI_POS_Y", Integer.toString(DEFAULT_GUI_POS_X)));
    GUI_WIDTH = Integer.parseInt(props.getProperty("GUI_WIDTH", Integer.toString(GUI_WIDTH)));
    GUI_HEIGHT = Integer.parseInt(props.getProperty("GUI_HEIGHT", Integer.toString(GUI_HEIGHT)));
    GUI_CONSOLE_WIDTH = Integer
            .parseInt(props.getProperty("GUI_CONSOLE_WIDTH", Integer.toString(GUI_CONSOLE_WIDTH)));

    if (!HEADLESS) {
        // Iterate over all currently attached monitors and check if sceen
        // position is actually possible,
        // otherwise fall back to the DEFAULT values and ignore the ones
        // coming from the properties-file.
        boolean pos_ok = false;
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice[] gs = ge.getScreenDevices();
        for (int i = 0; i < gs.length; i++) {
            if (gs[i].getDefaultConfiguration().getBounds()
                    .contains(new java.awt.Point(GUI_POS_X, GUI_POS_Y))) {
                pos_ok = true;
            }
        }
        // None of the screens contained the top-left window coordinates -->
        // fall back onto default values...
        if (!pos_ok) {
            GUI_POS_X = DEFAULT_GUI_POS_X;
            GUI_POS_Y = DEFAULT_GUI_POS_Y;
        }
    }

    String path = props.getProperty("import_path", System.getProperty("user.home"));
    if (inputFolder == null || inputFolder.equals("")) {
        inputFolder = main.showStartupDialog(guiFrame, path);
    }
    System.out.println("Default filename decoration = " + inputFolder.getName());
    defaultFilenameDecoration = inputFolder.getName();
    path = inputFolder.getAbsolutePath();
    props.setProperty("import_path", path);

    GrowthLineSegmentationMagic.setClassifier(SEGMENTATION_CLASSIFIER_MODEL_FILE, "");

    if (!HEADLESS) {
        // Setting up console window...
        main.initConsoleWindow();
        main.showConsoleWindow(true);
    }

    // ------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------
    final MoMAModel mmm = new MoMAModel(main);
    instance = main;
    try {
        main.processDataFromFolder(path, minTime, maxTime, minChannelIdx, numChannels);
    } catch (final Exception e) {
        e.printStackTrace();
        System.exit(11);
    }
    // ------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------

    // show loaded and annotated data
    if (showIJ) {
        new ImageJ();
        ImageJFunctions.show(main.imgRaw, "Rotated & cropped raw data");
        // ImageJFunctions.show( main.imgTemp, "Temporary" );
        // ImageJFunctions.show( main.imgAnnotated, "Annotated ARGB data" );

        // main.getCellSegmentedChannelImgs()
        // ImageJFunctions.show( main.imgClassified, "Classification" );
        // ImageJFunctions.show( main.getCellSegmentedChannelImgs(), "Segmentation" );
    }

    gui = new MoMAGui(mmm);

    if (!HEADLESS) {
        System.out.print("Build GUI...");
        main.showConsoleWindow(false);

        //         final JFrameSnapper snapper = new JFrameSnapper();
        //         snapper.addFrame( main.frameConsoleWindow );
        //         snapper.addFrame( guiFrame );

        gui.setVisible(true);
        guiFrame.add(gui);
        guiFrame.setSize(GUI_WIDTH, GUI_HEIGHT);
        guiFrame.setLocation(GUI_POS_X, GUI_POS_Y);
        guiFrame.setVisible(true);

        //         SwingUtilities.invokeLater( new Runnable() {
        //
        //            @Override
        //            public void run() {
        //               snapper.snapFrames( main.frameConsoleWindow, guiFrame, JFrameSnapper.EAST );
        //            }
        //         } );
        System.out.println(" done!");
    } else {
        //         final String name = inputFolder.getName();

        gui.exportHtmlOverview();
        gui.exportDataFiles();

        instance.saveParams();

        System.exit(0);
    }
}

From source file:cc.wikitools.lucene.hadoop.SearchWikipediaHdfs.java

@SuppressWarnings("static-access")
@Override/*from   w  w  w  .  j  a va  2 s.  co  m*/
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("query text").create(QUERY_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return")
            .create(NUM_RESULTS_OPTION));

    options.addOption(new Option(VERBOSE_OPTION, "print out complete document"));
    options.addOption(new Option(TITLE_OPTION, "search title"));
    options.addOption(new Option(ARTICLE_OPTION, "search article"));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(QUERY_OPTION) || !cmdline.hasOption(INDEX_OPTION)
            || !cmdline.hasOption(QUERY_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(SearchWikipediaHdfs.class.getName(), options);
        System.exit(-1);
    }

    String indexLocation = cmdline.getOptionValue(INDEX_OPTION);
    String queryText = cmdline.getOptionValue(QUERY_OPTION);
    int numResults = cmdline.hasOption(NUM_RESULTS_OPTION)
            ? Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION))
            : DEFAULT_NUM_RESULTS;
    boolean verbose = cmdline.hasOption(VERBOSE_OPTION);
    boolean searchArticle = !cmdline.hasOption(TITLE_OPTION);

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    HdfsWikipediaSearcher searcher = new HdfsWikipediaSearcher(new Path(indexLocation), getConf());
    TopDocs rs = null;
    if (searchArticle) {
        rs = searcher.searchArticle(queryText, numResults);
    } else {
        rs = searcher.searchTitle(queryText, numResults);
    }

    int i = 1;
    for (ScoreDoc scoreDoc : rs.scoreDocs) {
        Document hit = searcher.doc(scoreDoc.doc);

        out.println(String.format("%d. %s (id = %s) %f", i, hit.getField(IndexField.TITLE.name).stringValue(),
                hit.getField(IndexField.ID.name).stringValue(), scoreDoc.score));
        if (verbose) {
            out.println("# " + hit.toString().replaceAll("[\\n\\r]+", " "));
        }
        i++;
    }

    searcher.close();
    out.close();

    return 0;
}

From source file:info.extensiblecatalog.OAIToolkit.importer.CLIProcessor.java

/**
 * Setup the command line options object
 * @return the command line options object
 *///  w ww  . ja va2 s  .  c  om
public static Options getCommandLineOptions() {

    Option convert = new Option("convert", "Flag to convert file(s) with raw MARC records into MARCXML");

    OptionBuilder.withArgName("modify");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Flag to modify MARCXML file(s) with XSLT transromation with the"
            + "given XSLT files before loading into the OAI repository");
    Option modify = OptionBuilder.create("modify");

    Option load = new Option("load", "Flag to load file(s) into the OAI repository");

    Option production = new Option("production", "Flag to switch production mode. It means, that the"
            + "toolkit won't create any temporary files (except error"
            + " records) so it read MARC records, process it, and put "
            + "directly to the database or the target file format [DEPRECATED: OPTION IS NO LONGER AVAILABLE]");

    OptionBuilder.withArgName("source");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory where the toolkit looks " + "for files to process");
    Option source = OptionBuilder.create("source");

    OptionBuilder.withArgName("destination");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory that the toolkit moves the source files into "
            + "as it successfully completes the processing of each file.");
    Option destination = OptionBuilder.create("destination");

    OptionBuilder.withArgName("destination_xml");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("The directory that the toolkit places " + "MARCXML versions of the source data.");
    Option destination_xml = OptionBuilder.create("destination_xml");

    OptionBuilder.withArgName("destination_modifiedxml");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "The directory that the toolkit places " + "modified MARCXML versions of the source data.");
    Option destination_modifiedxml = OptionBuilder.create("destination_modifiedxml");

    OptionBuilder.withArgName("error");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory that the toolkit moves files into when "
            + "there is a processing error for that file.");
    Option error = OptionBuilder.create("error");

    OptionBuilder.hasArg();
    OptionBuilder.withArgName("error_xml");
    OptionBuilder.withDescription("The directory that the toolkit places MARCXML versions of "
            + "the source data, if that MARCXML file was unable to be "
            + "loaded into the OAI repository due to an error condition.");
    Option error_xml = OptionBuilder.create("error_xml");

    OptionBuilder.hasArg();
    OptionBuilder.withArgName("error_modifiedxml");
    OptionBuilder.withDescription("The directory that the toolkit places MARCXML versions of "
            + "the source data, if that MARCXML file was unable to be "
            + "loaded into the OAI repository due to an error condition.");
    Option error_modifiedxml = OptionBuilder.create("error_modifiedxml");

    OptionBuilder.withArgName("log");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory of log files for " + "warnings and errors");
    Option log = OptionBuilder.create("log");

    Option log_detail = new Option("log_detail", "Flag to offer more detailed processing log information");

    OptionBuilder.withArgName("marc_schema");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("XML Schema file for MARCXML validation");
    Option marc_schema = OptionBuilder.create("marc_schema");

    OptionBuilder.withArgName("marc_encoding");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The encoding of the MARC file");
    Option marc_encoding = OptionBuilder.create("marc_encoding");

    OptionBuilder.withArgName("char_conversion");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "The character conversion method. " + "Possible values: MARC8 (Ansel), ISO5426, ISO6937, none");
    Option char_conversion = OptionBuilder.create("char_conversion");

    OptionBuilder.withArgName("split_size");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("How many records can an XML file" + " contain?");
    Option split_size = OptionBuilder.create("split_size");

    OptionBuilder.withArgName("lucene_index");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Lucene index directory.");
    Option lucene_index = OptionBuilder.create("lucene_index");

    //OptionBuilder.withArgName("storage_type");
    //OptionBuilder.hasArg();
    //OptionBuilder.withDescription("The storage type of records: MySQL," +
    //" mixed, Lucene.");
    //Option storage_type = OptionBuilder.create("storage_type");

    Option indent_xml = new Option("indent_xml", "Flag to indent XML");

    Option xml_version_11 = new Option("xml_version_11", "Flag to create XML 1.1 instead of 1.0");

    Option translate_leader_bad_chars_to_zero = new Option("translate_leader_bad_chars_to_zero",
            "Change the Bad characters in the leader to zeros");

    Option translate_nonleader_bad_chars_to_spaces = new Option("translate_nonleader_bad_chars_to_spaces",
            "Change the Bad characters in the control and the data fields to spaces");

    Option modify_validation = new Option("modify_validation", "Perform validation check during modify step");

    OptionBuilder.withArgName("replace_repository_code");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Replace repository code.");
    Option replace_repository_code = OptionBuilder.create("replace_repository_code");

    OptionBuilder.withArgName("convert_dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory of marc files after " + "process.");
    Option convert_dir = OptionBuilder.create("convert_dir");

    Option fileof_deleted_records = new Option("fileof_deleted_records",
            "The source marc file should be considered as deleted");

    Option lucene_statistics = new Option("lucene_statistics", "Statistics for Lucene Database");

    Option lucene_dump_ids = new Option("lucene_dump_ids", "List all ids (001s) to standard output");

    OptionBuilder.withArgName("load_dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory of marcxml files after" + " process.");
    Option load_dir = OptionBuilder.create("load_dir");

    OptionBuilder.withArgName("modify_dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The directory of modified marcxml " + "files after process.");
    Option modify_dir = OptionBuilder.create("modify_dir");

    OptionBuilder.withArgName("error_suffix");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The suffix of directory name of error" + " files after process.");
    Option error_suffix = OptionBuilder.create("error_suffix");

    OptionBuilder.withArgName("destination_suffix");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The suffix of directory name of files" + " after process.");
    Option destination_suffix = OptionBuilder.create("destination_suffix");

    OptionBuilder.withArgName("default_repository_code");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The default value of " + "repository code (field 003).");
    Option default_repository_code = OptionBuilder.create("default_repository_code");

    Option delete = new Option("delete", "Delete temporary files?");

    Option ignore_repository_code = new Option("ignore_repository_code", "Do not merge 003 and 001 together.");

    Option help = new Option("help", "list available options");

    Options options = new Options();
    options.addOption(production);
    options.addOption(convert);
    options.addOption(modify);
    options.addOption(load);
    options.addOption(source);
    options.addOption(destination);
    options.addOption(destination_xml);
    options.addOption(error);
    options.addOption(error_xml);
    options.addOption(log);
    options.addOption(log_detail);
    options.addOption(marc_schema);
    options.addOption(marc_encoding);
    options.addOption(char_conversion);
    options.addOption(split_size);
    options.addOption(lucene_index);
    //options.addOption(storage_type);
    options.addOption(indent_xml);
    options.addOption(xml_version_11);
    options.addOption(translate_leader_bad_chars_to_zero);
    options.addOption(modify_validation);
    options.addOption(translate_nonleader_bad_chars_to_spaces);
    options.addOption(fileof_deleted_records);
    options.addOption(lucene_statistics);
    options.addOption(lucene_dump_ids);
    options.addOption(replace_repository_code);
    options.addOption(convert_dir);
    options.addOption(load_dir);
    options.addOption(modify_dir);
    options.addOption(error_suffix);
    options.addOption(destination_suffix);
    options.addOption(delete);
    options.addOption(destination_modifiedxml);
    options.addOption(error_modifiedxml);
    options.addOption(default_repository_code);
    options.addOption(ignore_repository_code);
    options.addOption(help);

    return options;
}

From source file:basic.PartitionGraph.java

/**
 * Runs this tool.//from www .j a va  2  s .co m
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(RANGE, "use range partitioner"));

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(NUM_PARTITIONS)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

    Job job = Job.getInstance(conf);
    job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath);
    job.setJarByClass(PartitionGraph.class);

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

    job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNode.class);

    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(PageRankNode.class);

    if (useRange) {
        job.setPartitionerClass(RangePartitioner.class);
    }

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:edu.umd.gorden2.PartitionGraph.java

/**
 * Runs this tool./* w w w  .ja  v  a  2  s  .  c o  m*/
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(RANGE, "use range partitioner"));

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(NUM_PARTITIONS)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

    Job job = Job.getInstance(conf);
    job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath);
    job.setJarByClass(PartitionGraph.class);

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

    job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNode.class);

    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(PageRankNode.class);

    //if (useRange) {
    //job.setPartitionerClass(RangePartitioner.class);
    //}

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:edu.fullerton.timeseriesapp.TimeSeriesCommandLine.java

boolean parseCommand(String[] args, String programName, String version) {
    ret = true;/*  w  w  w  .  j  a v a  2s .  c  o m*/

    Options options = new Options();

    options.addOption(new Option("help", "print this message"));
    options.addOption(new Option("version", "print the version information and exit"));

    options.addOption(new Option("semilog", "log scale Y-axis"));
    options.addOption(
            new Option("nodetrend", "Do not detrend (subtract linear fit) the data before transform."));

    options.addOption(
            OptionBuilder.withArgName("out").hasArg().withDescription("output filename").create("outfile"));
    options.addOption(OptionBuilder.withArgName("geometry").hasArg()
            .withDescription("image size <X>x<Y> [default=640x480]").create("geom"));

    options.addOption(OptionBuilder.withArgName("channel").hasArgs()
            .withDescription("channel <name,type> multiples accepted").create("chan"));
    options.addOption(OptionBuilder.withArgName("server").hasArg()
            .withDescription("server <URL> [default=best match]").create("server"));
    options.addOption(OptionBuilder.withArgName("ctype").hasArg()
            .withDescription("channel type eg (raw, rds, minute-trend [default=best match]").create("ctype"));

    options.addOption(
            OptionBuilder.withArgName("start").hasArg().withDescription("GPS start time").create("start"));
    options.addOption(
            OptionBuilder.withArgName("duration").hasArg().withDescription("duration (seconds)").create("dur"));
    options.addOption(OptionBuilder.withArgName("xticks").hasArg()
            .withDescription("tick marks/grid lines on time axis").create("xticks"));
    options.addOption(OptionBuilder.withArgName("yticks").hasArg()
            .withDescription("tick marks/grid lines on freq axis").create("yticks"));
    options.addOption(OptionBuilder.withArgName("timeaxis").hasArg()
            .withDescription("time axis label (utc, gps, dt [default=dt]").create("timeaxis"));

    CommandLineParser parser = new GnuParser();

    wantHelp = false;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Command parsing failed.  Reason: " + exp.getMessage());
        wantHelp = true;
        line = null;
    }
    if (line != null) {
        if (line.hasOption("version")) {
            System.out.println(programName + " - version " + version);
            ret = false;
        }

        wantHelp = line.hasOption("help");
        logX = line.hasOption("logfreq");
        logY = line.hasOption("logpower");
        detrend = !line.hasOption("nodetrend");

        startGPS = getIntegerOpt("start");
        duration = getIntegerOpt("dur");
        xTicks = getIntegerOpt("xticks");
        yTicks = getIntegerOpt("yticks");

        secPerFFT = getFloatOpt("secpfft");
        overlap = getFloatOpt("overlap");
        fmin = getFloatOpt("fmin");
        fmax = getFloatOpt("fmax");

        if (line.hasOption("outfile")) {
            ofileName = line.getOptionValue("outfile");
        }
        String val;

        Matcher m;

        if (line.hasOption("geom")) {
            val = line.getOptionValue("geom");
            Pattern gp = Pattern.compile("(\\d+)x(\\d+)");
            m = gp.matcher(val);
            if (m.find()) {
                String sx = m.group(1);
                String sy = m.group(2);
                if (sx.matches(intpat) && sy.matches(intpat)) {
                    outX = Integer.parseInt(sx);
                    outY = Integer.parseInt(sy);
                } else {
                    ermsg += "can't parse geometry value (" + val + ")";
                    wantHelp = true;
                    ret = false;
                }
            } else {
                ermsg += "can't parse geometry value (" + val + ")";
                wantHelp = true;
                ret = false;
            }
        }

        if (line.hasOption("chan")) {
            channelNames = line.getOptionValues("chan");
        }
        if (line.hasOption("server")) {
            server = line.getOptionValue("server");
        }

        if (line.hasOption("ctype")) {
            cType = line.getOptionValue("ctype");
        }
        if (line.hasOption("timeaxis")) {
            timeAxis = line.getOptionValue("timeaxis");
        } else {
            timeAxis = "dt";
        }

    }
    if (!ermsg.isEmpty()) {
        System.out.println("Command error:\n" + ermsg);
        wantHelp = true;
        ret = false;
    }
    if (wantHelp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(programName, options);
        ret = false;
    }
    return ret;

}

From source file:edu.umd.shrawanraina.PartitionGraph.java

/**
 * Runs this tool./*from ww w.  j a v  a  2  s.c  o  m*/
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(RANGE, "use range partitioner"));

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(NUM_PARTITIONS)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

    Job job = Job.getInstance(conf);
    job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath);
    job.setJarByClass(PartitionGraph.class);

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

    job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNodeUpd.class);

    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(PageRankNodeUpd.class);

    if (useRange) {
        job.setPartitionerClass(RangePartitioner.class);
    }

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:edu.umd.honghongie.PartitionGraph.java

/**
 * Runs this tool./*from w w  w  .j  av a 2 s.c o m*/
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(RANGE, "use range partitioner"));

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(NUM_PARTITIONS)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

    Job job = Job.getInstance(conf);
    job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath);
    job.setJarByClass(PartitionGraph.class);

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

    job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNode.class);

    job.setOutputKeyClass(IntWritable.class);
    //  job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(PageRankNode.class);

    if (useRange) {
        job.setPartitionerClass(RangePartitioner.class);
    }

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}