Example usage for java.util EnumMap EnumMap

List of usage examples for java.util EnumMap EnumMap

Introduction

In this page you can find the example usage for java.util EnumMap EnumMap.

Prototype

public EnumMap(Map<K, ? extends V> m) 

Source Link

Document

Creates an enum map initialized from the specified map.

Usage

From source file:pl.edu.icm.cermine.libsvm.training.SVMBodyBuilder.java

public static void main(String[] args) throws ParseException, AnalysisException, IOException {
    Options options = new Options();
    options.addOption("input", true, "input path");
    options.addOption("output", true, "output model path");
    options.addOption("kernel", true, "kernel type");
    options.addOption("g", true, "gamma");
    options.addOption("C", true, "C");
    options.addOption("degree", true, "degree");
    options.addOption("cross", false, "");
    options.addOption("ext", true, "degree");

    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(options, args);
    if (!line.hasOption("input") || !line.hasOption("output")) {
        System.err.println(/*from www . jav a  2 s  . com*/
                "Usage: SVMMetadataBuilder [-kernel <kernel type>] [-d <degree>] [-g <gamma>] [-C <error cost>] [-ext <extension>] -input <input dir> -output <path>");
        System.exit(1);
    }

    Double C = 8.0;
    if (line.hasOption("C")) {
        C = Double.valueOf(line.getOptionValue("C"));
    }
    Double gamma = 0.5;
    if (line.hasOption("g")) {
        gamma = Double.valueOf(line.getOptionValue("g"));
    }
    String inDir = line.getOptionValue("input");
    String outFile = line.getOptionValue("output");
    String degreeStr = line.getOptionValue("degree");
    Integer degree = -1;
    if (degreeStr != null && !degreeStr.isEmpty()) {
        degree = Integer.valueOf(degreeStr);
    }
    Integer kernelType = svm_parameter.RBF;
    if (line.hasOption("kernel")) {
        switch (Integer.valueOf(line.getOptionValue("kernel"))) {
        case 0:
            kernelType = svm_parameter.LINEAR;
            break;
        case 1:
            kernelType = svm_parameter.POLY;
            break;
        case 2:
            kernelType = svm_parameter.RBF;
            break;
        case 3:
            kernelType = svm_parameter.SIGMOID;
            break;
        default:
            throw new IllegalArgumentException("Invalid kernel value provided");
        }
    }
    if (kernelType == svm_parameter.POLY && degree == null) {
        System.err.println("Polynomial kernel requires the -degree option to be specified");
        System.exit(1);
    }

    String ext = "cxml";
    if (line.hasOption("ext")) {
        ext = line.getOptionValue("ext");
    }

    Map<BxZoneLabel, BxZoneLabel> map = new EnumMap<BxZoneLabel, BxZoneLabel>(BxZoneLabel.class);
    map.put(BxZoneLabel.BODY_ACKNOWLEDGMENT, BxZoneLabel.BODY_CONTENT);
    map.put(BxZoneLabel.BODY_CONFLICT_STMT, BxZoneLabel.BODY_CONTENT);
    map.put(BxZoneLabel.BODY_EQUATION, BxZoneLabel.BODY_JUNK);
    map.put(BxZoneLabel.BODY_FIGURE, BxZoneLabel.BODY_JUNK);
    map.put(BxZoneLabel.BODY_GLOSSARY, BxZoneLabel.BODY_JUNK);
    map.put(BxZoneLabel.BODY_TABLE, BxZoneLabel.BODY_JUNK);

    if (!line.hasOption("cross")) {
        File input = new File(inDir);
        List<TrainingSample<BxZoneLabel>> trainingSamples;
        if (input.isDirectory()) {
            DocumentsIterator it = new DocumentsIterator(inDir, ext);
            FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder = ContentFilterTools.VECTOR_BUILDER;
            trainingSamples = BxDocsToTrainingSamplesConverter.getZoneTrainingSamples(it.iterator(),
                    featureVectorBuilder, map);
        } else {
            trainingSamples = SVMZoneClassifier.loadProblem(inDir, ContentFilterTools.VECTOR_BUILDER);
        }

        trainingSamples = ClassificationUtils.filterElements(trainingSamples, BxZoneLabelCategory.CAT_BODY);
        SVMZoneClassifier classifier = getZoneClassifier(trainingSamples, kernelType, gamma, C, degree);
        classifier.saveModel(outFile);
    } else {
        int foldness = 5;
        List<TrainingSample<BxZoneLabel>>[] trainingSamplesSet = new List[foldness];

        for (int i = 0; i < foldness; i++) {

            File input = new File(inDir + "/" + i);
            List<TrainingSample<BxZoneLabel>> trainingSamples;
            if (input.isDirectory()) {
                DocumentsIterator it = new DocumentsIterator(inDir + "/" + i, ext);

                FeatureVectorBuilder<BxZone, BxPage> featureVectorBuilder = ContentFilterTools.VECTOR_BUILDER;
                trainingSamples = BxDocsToTrainingSamplesConverter.getZoneTrainingSamples(it.iterator(),
                        featureVectorBuilder, map);
            } else {
                trainingSamples = SVMZoneClassifier.loadProblem(inDir + "/" + i,
                        ContentFilterTools.VECTOR_BUILDER);
            }

            trainingSamples = ClassificationUtils.filterElements(trainingSamples, BxZoneLabelCategory.CAT_BODY);
            trainingSamplesSet[i] = trainingSamples;
        }

        for (int i = 0; i < foldness; i++) {
            List<TrainingSample<BxZoneLabel>> trainingSamples = new ArrayList<TrainingSample<BxZoneLabel>>();
            for (int j = 0; j < foldness; j++) {
                if (i != j) {
                    trainingSamples.addAll(trainingSamplesSet[j]);
                }
            }

            SVMZoneClassifier classifier = getZoneClassifier(trainingSamples, kernelType, gamma, C, degree);
            classifier.saveModel(outFile + "-" + i);
        }
    }
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> getEnumMap(Class<K> keyType) {
    return new EnumMap<K, V>(keyType);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Class<K> type, Map.Entry<K, V>... entries) {

    EnumMap<K, V> map = new EnumMap<K, V>(type);

    for (Map.Entry<K, V> entry : entries) {
        map.put(entry.getKey(), entry.getValue());
    }/* www . j  av  a  2 s.c om*/
    return map;
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> createEnumMap(Class<K> keyType) {
    if (keyType == null) {
        return null;
    }//from  ww w  .j  a  v a  2 s  . c o m

    return new EnumMap<K, V>(keyType);
}

From source file:Main.java

@Nonnull
public static <K extends Enum<K>, V> Map<K, V> enumMap(Class<K> enumClass) {
    return new EnumMap<K, V>(enumClass);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> getEnumMap(Map<K, ? extends V> map) {
    return new EnumMap<K, V>(map);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> createEnumMap(Map<K, ? extends V> map) {
    if (map == null) {
        return null;
    }/*from w ww .java 2s  .  com*/

    return new EnumMap<K, V>(map);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(final Class<K> keyType) {
    return new EnumMap<K, V>(keyType);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(final EnumMap<K, ? extends V> m) {
    return new EnumMap<K, V>(m);
}

From source file:Main.java

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(final Map<K, ? extends V> m) {
    return new EnumMap<K, V>(m);
}