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

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

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

Utils.forName介绍

[英]Creates a new instance of an object given it's class name and (optional) arguments to pass to it's setOptions method. If the object implements OptionHandler and the options parameter is non-null, the object will have it's options set. Example use:

``

String classifierName = Utils.getOption('W', options); 
Classifier c = (Classifier)Utils.forName(Classifier.class, 
classifierName, 
options); 
setClassifier(c);

[中]在给定对象的类名和(可选)参数的情况下,创建对象的新实例,以传递给对象的setOptions方法。如果对象实现OptionHandler,并且options参数为非null,则对象将设置其选项。示例用法:
``

String classifierName = Utils.getOption('W', options); 
Classifier c = (Classifier)Utils.forName(Classifier.class, 
classifierName, 
options); 
setClassifier(c);

代码示例

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

/**
  * Creates a new instance of a kernel given it's class name and (optional)
  * arguments to pass to it's setOptions method.
  * 
  * @param kernelName the fully qualified class name of the classifier
  * @param options an array of options suitable for passing to setOptions. May
  *          be null.
  * @return the newly created classifier, ready for use.
  * @throws Exception if the classifier name is invalid, or the options
  *           supplied are not acceptable to the classifier
  */
 public static Kernel forName(String kernelName, String[] options)
  throws Exception {

  return (Kernel) Utils.forName(Kernel.class, kernelName, options);
 }
}

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

/**
 * Creates a new instance of a clusterer given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the clusterer implements
 * OptionHandler and the options parameter is non-null, the clusterer will
 * have it's options set.
 * 
 * @param clustererName the fully qualified class name of the clusterer
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created search object, ready for use.
 * @exception Exception if the clusterer class name is invalid, or the options
 *              supplied are not acceptable to the clusterer.
 */
public static Clusterer forName(String clustererName, String[] options)
 throws Exception {
 return (Clusterer) Utils.forName(Clusterer.class, clustererName, options);
}

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

/**
  * Creates a new instance of a kernel given it's class name and (optional)
  * arguments to pass to it's setOptions method.
  * 
  * @param kernelName the fully qualified class name of the classifier
  * @param options an array of options suitable for passing to setOptions. May
  *          be null.
  * @return the newly created classifier, ready for use.
  * @throws Exception if the classifier name is invalid, or the options
  *           supplied are not acceptable to the classifier
  */
 public static Kernel forName(String kernelName, String[] options)
  throws Exception {

  return (Kernel) Utils.forName(Kernel.class, kernelName, options);
 }
}

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

/**
 * Creates a new instance of a associator given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the associator implements
 * OptionHandler and the options parameter is non-null, the associator will
 * have it's options set.
 *
 * @param associatorName the fully qualified class name of the associator
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created associator, ready for use.
 * @exception Exception if the associator name is invalid, or the options
 *              supplied are not acceptable to the associator
 */
public static Associator forName(String associatorName, String[] options)
 throws Exception {
 return (Associator) Utils.forName(Associator.class, associatorName,
  options);
}

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

/**
 * Creates a new instance of a estimatorr given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the estimator implements
 * OptionHandler and the options parameter is non-null, the estimator will
 * have it's options set.
 * 
 * @param name the fully qualified class name of the estimatorr
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created estimator, ready for use.
 * @exception Exception if the estimator name is invalid, or the options
 *              supplied are not acceptable to the estimator
 */
public static Estimator forName(String name, String[] options)
 throws Exception {
 return (Estimator) Utils.forName(Estimator.class, name, options);
}

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

/**
 * Creates a new instance of a clusterer given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the clusterer implements
 * OptionHandler and the options parameter is non-null, the clusterer will
 * have it's options set.
 * 
 * @param clustererName the fully qualified class name of the clusterer
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created search object, ready for use.
 * @exception Exception if the clusterer class name is invalid, or the options
 *              supplied are not acceptable to the clusterer.
 */
public static Clusterer forName(String clustererName, String[] options)
 throws Exception {
 return (Clusterer) Utils.forName(Clusterer.class, clustererName, options);
}

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

/**
 * Creates a new instance of a classifier given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the classifier implements
 * OptionHandler and the options parameter is non-null, the classifier will
 * have it's options set.
 *
 * @param classifierName the fully qualified class name of the classifier
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created classifier, ready for use.
 * @exception Exception if the classifier name is invalid, or the options
 *              supplied are not acceptable to the classifier
 */
public static Classifier forName(String classifierName, String[] options)
 throws Exception {
 return ((AbstractClassifier) Utils.forName(Classifier.class, classifierName,
  options));
}

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

/**
 * Creates a new instance of an attribute/subset evaluator given it's class
 * name and (optional) arguments to pass to it's setOptions method. If the
 * evaluator implements OptionHandler and the options parameter is non-null,
 * the evaluator will have it's options set.
 * 
 * @param evaluatorName the fully qualified class name of the evaluator
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created evaluator, ready for use.
 * @exception Exception if the evaluator name is invalid, or the options
 *              supplied are not acceptable to the evaluator
 */
public static ASEvaluation forName(String evaluatorName, String[] options)
 throws Exception {
 return (ASEvaluation) Utils.forName(ASEvaluation.class, evaluatorName,
  options);
}

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

/**
 * Creates a new instance of an attribute/subset evaluator given it's class
 * name and (optional) arguments to pass to it's setOptions method. If the
 * evaluator implements OptionHandler and the options parameter is non-null,
 * the evaluator will have it's options set.
 * 
 * @param evaluatorName the fully qualified class name of the evaluator
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created evaluator, ready for use.
 * @exception Exception if the evaluator name is invalid, or the options
 *              supplied are not acceptable to the evaluator
 */
public static ASEvaluation forName(String evaluatorName, String[] options)
 throws Exception {
 return (ASEvaluation) Utils.forName(ASEvaluation.class, evaluatorName,
  options);
}

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

/**
 * Creates a new instance of a classifier given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the classifier implements
 * OptionHandler and the options parameter is non-null, the classifier will
 * have it's options set.
 *
 * @param classifierName the fully qualified class name of the classifier
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created classifier, ready for use.
 * @exception Exception if the classifier name is invalid, or the options
 *              supplied are not acceptable to the classifier
 */
public static Classifier forName(String classifierName, String[] options)
 throws Exception {
 return ((AbstractClassifier) Utils.forName(Classifier.class, classifierName,
  options));
}

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

/**
 * Creates a new instance of a estimatorr given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the estimator implements
 * OptionHandler and the options parameter is non-null, the estimator will
 * have it's options set.
 * 
 * @param name the fully qualified class name of the estimatorr
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created estimator, ready for use.
 * @exception Exception if the estimator name is invalid, or the options
 *              supplied are not acceptable to the estimator
 */
public static Estimator forName(String name, String[] options)
 throws Exception {
 return (Estimator) Utils.forName(Estimator.class, name, options);
}

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

/**
 * Creates a new instance of a associator given it's class name and (optional)
 * arguments to pass to it's setOptions method. If the associator implements
 * OptionHandler and the options parameter is non-null, the associator will
 * have it's options set.
 *
 * @param associatorName the fully qualified class name of the associator
 * @param options an array of options suitable for passing to setOptions. May
 *          be null.
 * @return the newly created associator, ready for use.
 * @exception Exception if the associator name is invalid, or the options
 *              supplied are not acceptable to the associator
 */
public static Associator forName(String associatorName, String[] options)
 throws Exception {
 return (Associator) Utils.forName(Associator.class, associatorName,
  options);
}

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

/**
 * Creates a new instance of a search class given it's class name and
 * (optional) arguments to pass to it's setOptions method. If the
 * search method implements OptionHandler and the options parameter is
 * non-null, the search method will have it's options set.
 *
 * @param searchName the fully qualified class name of the search class
 * @param options an array of options suitable for passing to setOptions. May
 * be null.
 * @return the newly created search object, ready for use.
 * @throws Exception if the search class name is invalid, or the options
 * supplied are not acceptable to the search class.
 */
public static ASSearch forName(String searchName,
        String [] options) throws Exception {
 return (ASSearch)Utils.forName(ASSearch.class,
         searchName,
         options);
}

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

/**
 * Creates a new instance of a search class given it's class name and
 * (optional) arguments to pass to it's setOptions method. If the
 * search method implements OptionHandler and the options parameter is
 * non-null, the search method will have it's options set.
 *
 * @param searchName the fully qualified class name of the search class
 * @param options an array of options suitable for passing to setOptions. May
 * be null.
 * @return the newly created search object, ready for use.
 * @throws Exception if the search class name is invalid, or the options
 * supplied are not acceptable to the search class.
 */
public static ASSearch forName(String searchName,
        String [] options) throws Exception {
 return (ASSearch)Utils.forName(ASSearch.class,
         searchName,
         options);
}

代码示例来源:origin: olehmberg/winter

public void initialiseClassifier(String classifierName, String parameters[]) {
  this.parameters = parameters;
  // create classifier
  try {
    this.classifier = (Classifier) Utils.forName(Classifier.class, classifierName, parameters);
  } catch (Exception e) {
    e.printStackTrace();
  }
}

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

/**
 * Turns a commandline into an object.
 *
 * @param cls           the class that the commandline is expected to be
 * @param cmdline       the commandline to parse
 * @return              the object, null if failed to instantiate
 * @throws Exception    if parsing fails
 */
public static <T> T fromCommandLine(Class<T> cls, String cmdline) throws Exception {
  String[]    options;
  String      classname;
  options    = Utils.splitOptions(cmdline);
  classname  = options[0];
  options[0] = "";
  return (T) Utils.forName(cls, classname, options);
}

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

/**
 * Turns a commandline into an object.
 *
 * @param cls           the class that the commandline is expected to be
 * @param cmdline       the commandline to parse
 * @return              the object, null if failed to instantiate
 * @throws Exception    if parsing fails
 */
public static <T> T fromCommandLine(Class<T> cls, String cmdline) throws Exception {
  String[]    options;
  String      classname;
  options    = Utils.splitOptions(cmdline);
  classname  = options[0];
  options[0] = "";
  return (T) Utils.forName(cls, classname, options);
}

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

/**
 * Construct an instance of an option handler from a String specifying its
 * class name and option values
 *
 * @param optionValue a String containing the class of the option handler
 *          followed by its options
 * @return an instantiated option handling object
 * @throws Exception if a problem occurs
 */
protected static Object constructOptionHandlerValue(String optionValue)
 throws Exception {
 String[] optHandlerSpec = Utils.splitOptions(optionValue);
 if (optHandlerSpec.length == 0) {
  throw new Exception("Invalid option handler specification " + "string '"
   + optionValue);
 }
 String optionHandler = optHandlerSpec[0];
 optHandlerSpec[0] = "";
 Object handler = Utils.forName(null, optionHandler, optHandlerSpec);
 return handler;
}

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

/**
 * generates the options string.
 * 
 * @return the options string
 * @throws Exception in case the generation fails
 */
public String generate() throws Exception {
 StringBuffer result;
 OptionHandler handler;
 Enumeration<Option> enm;
 Option option;
 result = new StringBuffer();
 
 handler = (OptionHandler) Utils.forName(null, getClassname(), new String[0]);
 enm = handler.listOptions();
 while (enm.hasMoreElements()) {
  option = enm.nextElement();
  result.append(option.synopsis() + '\n');
  result.append(option.description() + "\n");
 }
 return result.toString();
}

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

/**
 * Performs the actual initialization of the filters.
 */
@Override
protected void doInitializeFilters() {
  List<String> filters = PluginManager.getPluginNamesOfTypeList(FileBasedEvaluationStatisticsExporter.class .getName());
  m_FileFilters = new ArrayList<>();
  for (String filter: filters) {
    try {
      FileBasedEvaluationStatisticsExporter handler = (FileBasedEvaluationStatisticsExporter) Utils.forName(
          FileBasedEvaluationStatisticsExporter.class, filter, new String[0]);
      m_FileFilters.add(new ExtensionFileFilterWithClass(
          handler.getFormatExtensions(),
          handler.getFormatDescription() + " (" + ObjectUtils.flatten(handler.getFormatExtensions(), ", ") + ")",
          filter));
    }
    catch (Exception e) {
      System.err.println("Failed to instantiate file filter: " + filter);
      e.printStackTrace();
    }
  }
}

相关文章

微信公众号

最新文章

更多