/** * Executes the command with the given parameters. * * @param params the parameters for the command * @throws Exception if command fails */ @Override protected void doExecute(String[] params) throws Exception { try { Object obj = Class.forName(params[0]).newInstance(); if (obj instanceof CapabilitiesHandler) { if (obj instanceof OptionHandler) { List<String> args = new ArrayList<>(); for (int i = 1; i < params.length; i++) { args.add(params[i]); } ((OptionHandler) obj).setOptions(args.toArray(new String[args.size()])); } weka.core.Capabilities caps = ((CapabilitiesHandler) obj).getCapabilities(); System.out.println(caps.toString().replace("[", "\n").replace("]", "\n")); } else { System.out.println("'" + params[0] + "' is not a " + CapabilitiesHandler.class.getName() + "!"); } } catch (Exception e) { System.out.println(e); } } }
/** * Executes the command with the given parameters. * * @param params the parameters for the command * @throws Exception if command fails */ @Override protected void doExecute(String[] params) throws Exception { try { Object obj = Class.forName(params[0]).newInstance(); if (obj instanceof CapabilitiesHandler) { if (obj instanceof OptionHandler) { List<String> args = new ArrayList<>(); for (int i = 1; i < params.length; i++) { args.add(params[i]); } ((OptionHandler) obj).setOptions(args.toArray(new String[args.size()])); } weka.core.Capabilities caps = ((CapabilitiesHandler) obj).getCapabilities(); System.out.println(caps.toString().replace("[", "\n").replace("]", "\n")); } else { System.out.println("'" + params[0] + "' is not a " + CapabilitiesHandler.class.getName() + "!"); } } catch (Exception e) { System.out.println(e); } } }
private void buildAssociations(Instances data) throws Exception { // see if there is an environment variable with // options for the associator if (m_env != null && m_Associator instanceof OptionHandler) { String opts = m_env .getVariableValue("weka.gui.beans.associator.schemeOptions"); if (opts != null && opts.length() > 0) { String[] options = Utils.splitOptions(opts); if (options.length > 0) { try { ((OptionHandler) m_Associator).setOptions(options); } catch (Exception ex) { String warningMessage = "[Associator] WARNING: unable to set options \"" + opts + "\"for " + m_Associator.getClass().getName(); if (m_log != null) { m_log.logMessage(warningMessage); } else { System.err.print(warningMessage); } } } } } m_Associator.buildAssociations(data); }
private void buildAssociations(Instances data) throws Exception { // see if there is an environment variable with // options for the associator if (m_env != null && m_Associator instanceof OptionHandler) { String opts = m_env .getVariableValue("weka.gui.beans.associator.schemeOptions"); if (opts != null && opts.length() > 0) { String[] options = Utils.splitOptions(opts); if (options.length > 0) { try { ((OptionHandler) m_Associator).setOptions(options); } catch (Exception ex) { String warningMessage = "[Associator] WARNING: unable to set options \"" + opts + "\"for " + m_Associator.getClass().getName(); if (m_log != null) { m_log.logMessage(warningMessage); } else { System.err.print(warningMessage); } } } } } m_Associator.buildAssociations(data); }
@Override public void resetLearningImpl() { try { instances = null; String clistring = clustererClasses[wekaAlgorithmOption.getChosenIndex()].getName(); clusterer = (weka.clusterers.AbstractClusterer) ClassOption.cliStringToObject(clistring, weka.clusterers.Clusterer.class, null); String rawOptions = parameterOption.getValue(); String[] options = rawOptions.split(" "); if (clusterer instanceof weka.core.OptionHandler) { ((weka.core.OptionHandler) clusterer).setOptions(options); Utils.checkForRemainingOptions(options); } } catch (Exception e) { e.printStackTrace(); } this.instanceConverter = new SamoaToWekaInstanceConverter(); }
@Override public void setOptions(String[] options) throws Exception { setDontReplaceMissingValues(Utils.getFlag("dont-replace-missing", options)); m_filtersToUse = new ArrayList<Filter>(); while (true) { String filterString = Utils.getOption("filter", options); if (DistributedJobConfig.isEmpty(filterString)) { break; } String[] spec = Utils.splitOptions(filterString); if (spec.length == 0) { throw new IllegalArgumentException( "Invalid filter specification string"); } String filterClass = spec[0]; Filter f = (Filter) Class.forName(filterClass).newInstance(); spec[0] = ""; if (f instanceof OptionHandler) { ((OptionHandler) f).setOptions(spec); } m_filtersToUse.add(f); } }
/** * Set the options for this filter * * @param options the options * @throws Exception if a problem occurs */ public void setOptions(String[] options) throws Exception { String filterSpec = Utils.getOption("filter", options); if (!DistributedJobConfig.isEmpty(filterSpec)) { String[] spec = Utils.splitOptions(filterSpec); String filterClass = spec[0]; spec[0] = ""; Filter base = (Filter) Class.forName(filterClass).newInstance(); if (base instanceof OptionHandler) { ((OptionHandler) base).setOptions(spec); } setBaseFilter(base); } }
/** * Read an {@code OptionHandler} from the current JSON node * * @param optionHNode the {@code JSONNode} to read from * @return an instantiated and configured option handler * @throws WekaException if a problem occurs */ protected static OptionHandler readStepPropertyOptionHandler( JSONNode optionHNode) throws WekaException { String clazz = optionHNode.getChild(CLASS).getValue().toString(); try { OptionHandler oh = (OptionHandler) WekaPackageClassLoaderManager.objectForName(clazz); /* * Beans.instantiate(JSONFlowUtils.class.getClassLoader(), clazz); */ String optionString = optionHNode.getChild(OPTIONS).getValue().toString(); if (optionString != null && optionString.length() > 0) { String[] options = Utils.splitOptions(optionString); oh.setOptions(options); } return oh; } catch (Exception ex) { throw new WekaException(ex); } }
/** * Read an {@code OptionHandler} from the current JSON node * * @param optionHNode the {@code JSONNode} to read from * @return an instantiated and configured option handler * @throws WekaException if a problem occurs */ protected static OptionHandler readStepPropertyOptionHandler( JSONNode optionHNode) throws WekaException { String clazz = optionHNode.getChild(CLASS).getValue().toString(); try { OptionHandler oh = (OptionHandler) WekaPackageClassLoaderManager.objectForName(clazz); /* * Beans.instantiate(JSONFlowUtils.class.getClassLoader(), clazz); */ String optionString = optionHNode.getChild(OPTIONS).getValue().toString(); if (optionString != null && optionString.length() > 0) { String[] options = Utils.splitOptions(optionString); oh.setOptions(options); } return oh; } catch (Exception ex) { throw new WekaException(ex); } }
/** * tests the commandline operation of the saver. */ public void testSaverCommandlineArgs() { String[] options; options = getCommandlineOptions(false); try { ((OptionHandler) m_Saver).setOptions(options); } catch (Exception e) { e.printStackTrace(); fail("Command line test failed ('" + Utils.arrayToString(options) + "'): " + e.toString()); } }
/** * tests the commandline operation of the saver. */ public void testSaverCommandlineArgs() { String[] options; options = getCommandlineOptions(false); try { ((OptionHandler) m_Saver).setOptions(options); } catch (Exception e) { e.printStackTrace(); fail("Command line test failed ('" + Utils.arrayToString(options) + "'): " + e.toString()); } }
((OptionHandler) getClusterer()).setOptions(Utils .partitionOptions(options)); updateOptions();
@Test public void testOptions() throws Exception { if (wrapper instanceof OptionHandler){ OptionHandler optionHandler = ((OptionHandler) wrapper); String[] options = optionHandler.getOptions(); String[] optionsCopy = Arrays.copyOf(options, options.length); optionHandler.setOptions(optionsCopy); String[] optionsAfter = optionHandler.getOptions(); Assert.assertArrayEquals(options, optionsAfter); } }
((OptionHandler) getClusterer()).setOptions(Utils .partitionOptions(options)); updateOptions();
/** * checks whether the user-supplied options can be processed at all * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkSetOptions() { boolean result; print("SetOptions..."); try { getDefaultHandler().setOptions(getUserOptions()); println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }
/** * checks whether the user-supplied options can be processed at all * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkSetOptions() { boolean result; print("SetOptions..."); try { getDefaultHandler().setOptions(getUserOptions()); println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }
/** * checks whether the default options can be processed completely or some * invalid options are returned by the getOptions() method. * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkDefaultOptions() { boolean result; String[] options; print("Default options..."); options = getDefaultOptions(); try { getDefaultHandler().setOptions(options); Utils.checkForRemainingOptions(options); println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }
/** * checks whether the default options can be processed completely or some * invalid options are returned by the getOptions() method. * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkDefaultOptions() { boolean result; String[] options; print("Default options..."); options = getDefaultOptions(); try { getDefaultHandler().setOptions(options); Utils.checkForRemainingOptions(options); println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }
/** * checks whether the user-supplied options can be processed completely or * some "left-over" options remain * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkRemainingOptions() { boolean result; String[] options; print("Remaining options..."); options = getUserOptions(); try { getDefaultHandler().setOptions(options); if (getDebug()) { println("\n remaining: " + printOptions(options)); } println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }
/** * checks whether the user-supplied options can be processed completely or * some "left-over" options remain * * @return index 0 is true if the test was passed, index 1 is always false */ public boolean checkRemainingOptions() { boolean result; String[] options; print("Remaining options..."); options = getUserOptions(); try { getDefaultHandler().setOptions(options); if (getDebug()) { println("\n remaining: " + printOptions(options)); } println("yes"); result = true; } catch (Exception e) { println("no"); result = false; if (getDebug()) { println(e); } } return result; }