weka.core.Utils.getOptionPos()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(15.1k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中weka.core.Utils.getOptionPos()方法的一些代码示例,展示了Utils.getOptionPos()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getOptionPos()方法的具体详情如下:
包路径:weka.core.Utils
类名称:Utils
方法名:getOptionPos

Utils.getOptionPos介绍

[英]Gets the index of an option or flag indicated by a flag "-Char" from the given array of strings. Stops searching at the first marker "--".
[中]获取由给定字符串数组中的标志“-Char”指示的选项或标志的索引。停止搜索第一个标记“-”。

代码示例

代码示例来源:origin: Waikato/weka-trunk

/**
 * Gets the index of an option or flag indicated by a flag "-Char" from the
 * given array of strings. Stops searching at the first marker "--".
 * 
 * @param flag the character indicating the option.
 * @param options the array of strings containing all the options.
 * @return the position if found, or -1 otherwise
 */
public static int getOptionPos(char flag, String[] options) {
 return getOptionPos("" + flag, options);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Gets the index of an option or flag indicated by a flag "-Char" from the
 * given array of strings. Stops searching at the first marker "--".
 * 
 * @param flag the character indicating the option.
 * @param options the array of strings containing all the options.
 * @return the position if found, or -1 otherwise
 */
public static int getOptionPos(char flag, String[] options) {
 return getOptionPos("" + flag, options);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Checks if the given array contains the flag "-String". Stops searching at
 * the first marker "--". If the flag is found, it is replaced with the empty
 * string.
 * 
 * @param flag the String indicating the flag.
 * @param options the array of strings containing all the options.
 * @return true if the flag was found
 * @exception Exception if an illegal option was found
 */
public static boolean getFlag(String flag, String[] options) throws Exception {
 int pos = getOptionPos(flag, options);
 if (pos > -1) {
  options[pos] = "";
 }
 return (pos > -1);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Checks if the given array contains the flag "-String". Stops searching at
 * the first marker "--". If the flag is found, it is replaced with the empty
 * string.
 * 
 * @param flag the String indicating the flag.
 * @param options the array of strings containing all the options.
 * @return true if the flag was found
 * @exception Exception if an illegal option was found
 */
public static boolean getFlag(String flag, String[] options) throws Exception {
 int pos = getOptionPos(flag, options);
 if (pos > -1) {
  options[pos] = "";
 }
 return (pos > -1);
}

代码示例来源:origin: Waikato/meka

/**
 * Parses an array option, returns all the occurrences of the option as a string array.
 *
 * @param options       the option array to use
 * @param option        the option to look for in the options array (no leading dash)
 * @return              the parsed value (or default value if option not present)
 * @throws Exception    if parsing of value fails
 */
public static String[] parse(String[] options, String option) throws Exception {
  List<String> result = new ArrayList<>();
  while (Utils.getOptionPos(option, options) > -1)
    result.add(Utils.getOption(option, options));
  return result.toArray(new String[result.size()]);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses an array option, returns all the occurrences of the option as a string array.
 *
 * @param options       the option array to use
 * @param option        the option to look for in the options array (no leading dash)
 * @return              the parsed value (or default value if option not present)
 * @throws Exception    if parsing of value fails
 */
public static String[] parse(String[] options, String option) throws Exception {
  List<String> result = new ArrayList<>();
  while (Utils.getOptionPos(option, options) > -1)
    result.add(Utils.getOption(option, options));
  return result.toArray(new String[result.size()]);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/meka

@Override
public void setOptions(String[] options) throws Exception {
  m_Is = (Utils.getOptionPos("Is",options) >= 0) ? Integer.parseInt(Utils.getOption("Is", options)) : m_Is;
  m_Iy = (Utils.getOptionPos("Iy",options) >= 0) ? Integer.parseInt(Utils.getOption("Iy", options)) : m_Iy;
  m_Payoff = (Utils.getOptionPos('P',options) >= 0) ? Integer.parseInt(Utils.getOption('P', options)) : m_Payoff;
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/meka

@Override
public void setOptions(String[] options) throws Exception {
  m_I = (Utils.getOptionPos('I',options) >= 0) ? Integer.parseInt(Utils.getOption('I',options)) : m_I; 
  super.setOptions(options);
}

代码示例来源:origin: Waikato/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: Waikato/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: net.sf.meka/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: Waikato/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  super.setOptions(options);
}

代码示例来源:origin: Waikato/meka

/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -K <br>
 * Use kernel estimation for modelling numeric attributes rather than
 * a single normal distribution.<p>
 *
 * -D <br>
 * Use supervised discretization to process numeric attributes.
 *
 * @param options the list of options as an array of strings
 * @exception Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
 //These are just examples, modify to suit your algorithm
 //    boolean k = Utils.getFlag('K', options);
 //    boolean d = Utils.getFlag('D', options);
 //    if (k && d) {
 //      throw new IllegalArgumentException(
 //    		  "Can't use both kernel density estimation and discretization!");
 //    }
 //    setUseSupervisedDiscretization(d);
 //    setUseKernelEstimator(k);
  roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa;
  m_userankstoclass= (Utils.getOptionPos("K",options) >= 0);
  activity_report = (Utils.getOptionPos("Rt",options) >= 0) ? Utils.getOption("Rt", options) : "";
  
  super.setOptions(options);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/meka

/**
 * SetClassesFromOptions.
 * @note: there is a similar function in Exlorer.prepareData(D) but that function can only take -C from the dataset options.
 */
public static void setClassesFromOptions(Instances D, String options[]) throws Exception {
  try {
    // get L
    int L = (Utils.getOptionPos('C', options) >= 0) ? Integer.parseInt(Utils.getOption('C',options)) : Integer.parseInt(Utils.getOption('c',options));
    // if negative, then invert first
    if ( L < 0) {
      L = -L;
      D = MLUtils.switchAttributes(D,L);
    }
    // set L
    D.setClassIndex(L);
  } catch(Exception e) {
    e.printStackTrace();
    //System.err.println("[Error] Failed to Set Options from Command Line -- Check\n\t the spelling of the base classifier;\n \t that options are specified in the correct order (respective to  the '--' divider); and\n\t that the class index is set properly.");
    //System.exit(1);
    throw new Exception ("Error] Failed to Set Classes from options.");
  }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/meka

/**
 * Prepares the class index of the data.
 * 
 * @param data the data to prepare
 * @throws Exception if preparation fails
 */
public static void prepareData(Instances data) throws Exception {
 String doptions[] = null;
 try {
  doptions = MLUtils.getDatasetOptions(data);
 } 
 catch(Exception e) {
  throw new Exception("[Error] Failed to Get Options from @Relation Name", e);
 }
 int c = (Utils.getOptionPos('C', doptions) >= 0) ? Integer.parseInt(Utils.getOption('C',doptions)) : Integer.parseInt(Utils.getOption('c',doptions));
 // if negative, then invert
 if ( c < 0) {
  c = -c;
  data = MLUtils.switchAttributes(data,c);
 }
 // set c
 data.setClassIndex(c);
}

相关文章