public ClassifierTrainer<MaxEnt> createTrainer(String... args) { MaxEntTrainer trainer = new MaxEntTrainer(); if (args != null) { if (args.length % 2 != 0) { throw new IllegalArgumentException("each argument must be supplied with a value: " + getUsageMessage()); } for (int i = 0; i < args.length; i += 2) { String optionName = args[i]; String optionValue = args[i + 1]; if (optionName.equals("--numIterations")) { int numIterations = Integer.parseInt(optionValue); if (numIterations > 0) trainer.setNumIterations(numIterations); else throw new IllegalArgumentException("numIterations must be positive. " + getUsageMessage()); } else if (optionName.equals("--gaussianPriorVariance")) trainer.setGaussianPriorVariance(Double.parseDouble(optionValue)); else throw new IllegalArgumentException(String.format( "the argument %1$s is invalid. ", optionName) + getUsageMessage()); } } return trainer; }
public ClassifierTrainer<MaxEnt> createTrainer(String... args) { MaxEntTrainer trainer = new MaxEntTrainer(); if (args != null) { if (args.length % 2 != 0) { throw new IllegalArgumentException("each argument must be supplied with a value: " + getUsageMessage()); } for (int i = 0; i < args.length; i += 2) { String optionName = args[i]; String optionValue = args[i + 1]; if (optionName.equals("--numIterations")) { int numIterations = Integer.parseInt(optionValue); if (numIterations > 0) trainer.setNumIterations(numIterations); else throw new IllegalArgumentException("numIterations must be positive. " + getUsageMessage()); } else if (optionName.equals("--gaussianPriorVariance")) trainer.setGaussianPriorVariance(Double.parseDouble(optionValue)); else throw new IllegalArgumentException(String.format( "the argument %1$s is invalid. ", optionName) + getUsageMessage()); } } return trainer; }