com.gsinnovations.howdah.DefaultOptionCreator.java Source code

Java tutorial

Introduction

Here is the source code for com.gsinnovations.howdah.DefaultOptionCreator.java

Source

//Taken from Mahout (http://mahout.apache.org)
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gsinnovations.howdah;

import org.apache.commons.cli2.Option;
import org.apache.commons.cli2.builder.ArgumentBuilder;
import org.apache.commons.cli2.builder.DefaultOptionBuilder;

public final class DefaultOptionCreator {

    public static final String INPUT_OPTION = "input";
    public static final String MAX_REDUCERS_OPTION = "maxRed";

    public static final String OUTPUT_OPTION = "output";
    public static final String OVERWRITE_OPTION = "overwrite";

    public static final String SEQUENTIAL_METHOD = "sequential";
    public static final String MAPREDUCE_METHOD = "mapreduce";

    private DefaultOptionCreator() {
    }

    /**
     * Returns a default command line option for help. Used by all clustering jobs and many others
     * */
    public static Option helpOption() {
        return new DefaultOptionBuilder().withLongName("help").withDescription("Print out help").withShortName("h")
                .create();
    }

    /**
     * Returns a default command line option for input directory specification. Used by all clustering jobs plus others
     */
    public static DefaultOptionBuilder inputOption() {
        return new DefaultOptionBuilder().withLongName(INPUT_OPTION).withRequired(false).withShortName("i")
                .withArgument(new ArgumentBuilder().withName(INPUT_OPTION).withMinimum(1).withMaximum(1).create())
                .withDescription("Path to job input directory.");
    }

    /**
     * Returns a default command line option for output directory specification. Used by all clustering jobs plus others
     */
    public static DefaultOptionBuilder outputOption() {
        return new DefaultOptionBuilder().withLongName(OUTPUT_OPTION).withRequired(false).withShortName("o")
                .withArgument(new ArgumentBuilder().withName(OUTPUT_OPTION).withMinimum(1).withMaximum(1).create())
                .withDescription("The directory pathname for output.");
    }

    /**
     * Returns a default command line option for output directory overwriting. Used by all clustering jobs
     */
    public static DefaultOptionBuilder overwriteOption() {
        return new DefaultOptionBuilder().withLongName(OVERWRITE_OPTION).withRequired(false)
                .withDescription("If present, overwrite the output directory before running job")
                .withShortName("ow");
    }

    /**
     * Returns a default command line option for specifying the max number of reducers.
     * Used by Dirichlet, FuzzyKmeans, Kmeans and LDA
     */
    public static DefaultOptionBuilder numReducersOption() {
        return new DefaultOptionBuilder().withLongName(MAX_REDUCERS_OPTION).withRequired(false).withShortName("r")
                .withArgument(new ArgumentBuilder().withName(MAX_REDUCERS_OPTION).withDefault("2").withMinimum(1)
                        .withMaximum(1).create())
                .withDescription("The number of reduce tasks. Defaults to 2");
    }

}