Java Code Examples for weka.core.Utils#forName()

The following examples show how to use weka.core.Utils#forName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentFilesHandlerWithCommandline.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes the setup container using the string.
 *
 * @param s		the string to use
 */
public Setup(String s) {
	String[]	parts;
	String[]	options;
	String		cname;

			parts = s.split("\t");
	if (parts.length != 2)
		return;

	m_File = new File(parts[0]);

	try {
		options    = Utils.splitOptions(parts[1]);
		cname      = options[0];
		options[0] = "";
		m_Handler  = Utils.forName(Object.class, cname, options);
	}
	catch (Exception e) {
		return;
	}
}
 
Example 2
Source File: ExperimentFileChooser.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the actual initialization of the filters.
 */
@Override
protected void doInitializeFilters() {
	List<String> filters = PluginManager.getPluginNamesOfTypeList(ExperimentFileHandler.class.getName());
	m_FileFilters = new ArrayList<>();
	for (String filter: filters) {
		try {
			ExperimentFileHandler handler = (ExperimentFileHandler) Utils.forName(
					ExperimentFileHandler.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();
		}
	}
}
 
Example 3
Source File: AbstractOutput.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a fully configured object from the given commandline.
 * 
 * @param cmdline the commandline to turn into an object
 * @return the object or null in case of an error
 */
public static AbstractOutput fromCommandline(String cmdline) {
  AbstractOutput result;
  String[] options;
  String classname;

  try {
    options = Utils.splitOptions(cmdline);
    classname = options[0];
    options[0] = "";
    result = (AbstractOutput) Utils.forName(AbstractOutput.class, classname,
        options);
  } catch (Exception e) {
    result = null;
  }

  return result;
}
 
Example 4
Source File: MeasurementEvaluationStatisticsExporterFileChooser.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the actual initialization of the filters.
 */
@Override
protected void doInitializeFilters() {
	List<String> filters = PluginManager.getPluginNamesOfTypeList(FileBasedMeasurementEvaluationStatisticsExporter.class.getName());
	m_FileFilters = new ArrayList<>();
	for (String filter: filters) {
		try {
			FileBasedMeasurementEvaluationStatisticsExporter handler = (FileBasedMeasurementEvaluationStatisticsExporter) 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();
		}
	}
}
 
Example 5
Source File: EvaluationStatisticsFileChooser.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the actual initialization of the filters.
 */
@Override
protected void doInitializeFilters() {
	List<String> filters = PluginManager.getPluginNamesOfTypeList(FileBasedEvaluationStatisticsHandler.class.getName());
	m_FileFilters = new ArrayList<>();
	for (String filter: filters) {
		try {
			FileBasedEvaluationStatisticsHandler handler = (FileBasedEvaluationStatisticsHandler) Utils.forName(
					FileBasedEvaluationStatisticsHandler.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();
		}
	}
}
 
Example 6
Source File: EvaluationStatisticsExporterFileChooser.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
		}
	}
}
 
Example 7
Source File: WekaMatchingRule.java    From winter with Apache License 2.0 5 votes vote down vote up
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();
	}
}
 
Example 8
Source File: OptionUtils.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: AbstractMultiSearch.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parses the options for this object.
 *
 * @param options	the options to use
 * @throws Exception	if setting of options fails
 */
@Override
public void setOptions(String[] options) throws Exception {
	String		tmpStr;
	String[]		tmpOptions;
	Vector<String>	search;
	int			i;
	AbstractParameter[]	params;

	tmpStr = Utils.getOption('E', options);
	if (tmpStr.length() != 0)
		setEvaluation(new SelectedTag(tmpStr, m_Metrics.getTags()));
	else
		setEvaluation(new SelectedTag(m_Metrics.getDefaultMetric(), m_Metrics.getTags()));

	search = new Vector<String>();
	do {
		tmpStr = Utils.getOption("search", options);
		if (tmpStr.length() > 0)
			search.add(tmpStr);
	}
	while (tmpStr.length() > 0);
	if (search.size() == 0) {
		for (i = 0; i < m_DefaultParameters.length; i++)
			search.add(getCommandline(m_DefaultParameters[i]));
	}
	params = new AbstractParameter[search.size()];
	for (i = 0; i < search.size(); i++) {
		tmpOptions    = Utils.splitOptions(search.get(i));
		tmpStr        = tmpOptions[0];
		tmpOptions[0] = "";
		params[i]     = (AbstractParameter) Utils.forName(AbstractParameter.class, tmpStr, tmpOptions);
	}
	setSearchParameters(params);

	tmpStr = Utils.getOption("algorithm", options);
	if (!tmpStr.isEmpty()) {
		tmpOptions = Utils.splitOptions(tmpStr);
		tmpStr = tmpOptions[0];
		tmpOptions[0] = "";
		setAlgorithm((AbstractSearch) Utils.forName(AbstractSearch.class, tmpStr, tmpOptions));
	}
	else {
		setAlgorithm(new DefaultSearch());
	}

	tmpStr = Utils.getOption("log-file", options);
	if (tmpStr.length() != 0)
		setLogFile(new File(tmpStr));
	else
		setLogFile(new File(System.getProperty("user.dir")));

	super.setOptions(options);
}
 
Example 10
Source File: AbstractClusterer.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: Classifier.java    From KEEL with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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 (Classifier)Utils.forName(Classifier.class,
		     classifierName,
		     options);
}
 
Example 12
Source File: Estimator.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new instance of a estimatorr 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 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 classifier, ready for use.
 * @exception Exception if the classifier name is invalid, or the options
 * supplied are not acceptable to the classifier
 */
public static Estimator forName(String name,
    String [] options) throws Exception {
  
  return (Estimator)Utils.forName(Estimator.class,
      name,
      options);
}
 
Example 13
Source File: AbstractClassifier.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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));
}
 
Example 14
Source File: ASSearch.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: ASEvaluation.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: AbstractAssociator.java    From tsml with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: Kernel.java    From tsml with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}