Example usage for weka.core Version VERSION

List of usage examples for weka.core Version VERSION

Introduction

In this page you can find the example usage for weka.core Version VERSION.

Prototype

String VERSION

To view the source code for weka.core Version VERSION.

Click Source Link

Document

the complete version

Usage

From source file:adams.core.management.WekaHomeEnvironmentModifier.java

License:Open Source License

/**
 * Updates the environment variables that the {@link Launcher} uses for
 * launching the ADAMS process.//from  w  w  w  . ja  v  a  2  s .co m
 *
 * @param env      the current key=value pairs
 * @return      if the environment got updated
 */
@Override
public boolean updateEnvironment(List<String> env) {
    String path;
    File dir;

    for (String var : env) {
        if (var.startsWith(ENV_VAR + "=")) {
            getLogger().warning("Environment variable " + ENV_VAR + " already present, not overriding.");
            return false;
        }
    }

    path = Environment.getInstance().getHome() + File.separator + "wekafiles" + File.separator
            + FileUtils.createFilename(Version.VERSION, "_");

    // try to create directory
    dir = new File(path);
    if (!dir.exists()) {
        if (isLoggingEnabled())
            getLogger().info("Creating directory: " + path);
        if (!dir.mkdirs()) {
            getLogger().warning("Failed to create directory: " + path);
            return false;
        }
    }

    env.add(ENV_VAR + "=" + path);
    if (isLoggingEnabled())
        getLogger().info(ENV_VAR + ": " + path);

    return true;
}

From source file:bme.mace.logicdomain.Evaluation.java

License:Open Source License

/**
 * Wraps a static classifier in enough source to test using the weka class
 * libraries./*from w  w w .ja va  2 s. c om*/
 * 
 * @param classifier a Sourcable Classifier
 * @param className the name to give to the source code class
 * @return the source for a static classifier that can be tested with weka
 *         libraries.
 * @throws Exception if code-generation fails
 */
public static String wekaStaticWrapper(Sourcable classifier, String className) throws Exception {

    StringBuffer result = new StringBuffer();
    String staticClassifier = classifier.toSource(className);

    result.append("// Generated with Weka " + Version.VERSION + "\n");
    result.append("//\n");
    result.append("// This code is public domain and comes with no warranty.\n");
    result.append("//\n");
    result.append("// Timestamp: " + new Date() + "\n");
    result.append("\n");
    result.append("package weka.classifiers;\n");
    result.append("\n");
    result.append("import weka.core.Attribute;\n");
    result.append("import weka.core.Capabilities;\n");
    result.append("import weka.core.Capabilities.Capability;\n");
    result.append("import weka.core.Instance;\n");
    result.append("import weka.core.Instances;\n");
    result.append("import weka.core.RevisionUtils;\n");
    result.append("import weka.classifiers.Classifier;\n");
    result.append("\n");
    result.append("public class WekaWrapper\n");
    result.append("  extends Classifier {\n");

    // globalInfo
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Returns only the toString() method.\n");
    result.append("   *\n");
    result.append("   * @return a string describing the classifier\n");
    result.append("   */\n");
    result.append("  public String globalInfo() {\n");
    result.append("    return toString();\n");
    result.append("  }\n");

    // getCapabilities
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Returns the capabilities of this classifier.\n");
    result.append("   *\n");
    result.append("   * @return the capabilities\n");
    result.append("   */\n");
    result.append("  public Capabilities getCapabilities() {\n");
    result.append(((Classifier) classifier).getCapabilities().toSource("result", 4));
    result.append("    return result;\n");
    result.append("  }\n");

    // buildClassifier
    result.append("\n");
    result.append("  /**\n");
    result.append("   * only checks the data against its capabilities.\n");
    result.append("   *\n");
    result.append("   * @param i the training data\n");
    result.append("   */\n");
    result.append("  public void buildClassifier(Instances i) throws Exception {\n");
    result.append("    // can classifier handle the data?\n");
    result.append("    getCapabilities().testWithFail(i);\n");
    result.append("  }\n");

    // classifyInstance
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Classifies the given instance.\n");
    result.append("   *\n");
    result.append("   * @param i the instance to classify\n");
    result.append("   * @return the classification result\n");
    result.append("   */\n");
    result.append("  public double classifyInstance(Instance i) throws Exception {\n");
    result.append("    Object[] s = new Object[i.numAttributes()];\n");
    result.append("    \n");
    result.append("    for (int j = 0; j < s.length; j++) {\n");
    result.append("      if (!i.isMissing(j)) {\n");
    result.append("        if (i.attribute(j).isNominal())\n");
    result.append("          s[j] = new String(i.stringValue(j));\n");
    result.append("        else if (i.attribute(j).isNumeric())\n");
    result.append("          s[j] = new Double(i.value(j));\n");
    result.append("      }\n");
    result.append("    }\n");
    result.append("    \n");
    result.append("    // set class value to missing\n");
    result.append("    s[i.classIndex()] = null;\n");
    result.append("    \n");
    result.append("    return " + className + ".classify(s);\n");
    result.append("  }\n");

    // getRevision
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Returns the revision string.\n");
    result.append("   * \n");
    result.append("   * @return        the revision\n");
    result.append("   */\n");
    result.append("  public String getRevision() {\n");
    result.append("    return RevisionUtils.extract(\"1.0\");\n");
    result.append("  }\n");

    // toString
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Returns only the classnames and what classifier it is based on.\n");
    result.append("   *\n");
    result.append("   * @return a short description\n");
    result.append("   */\n");
    result.append("  public String toString() {\n");
    result.append("    return \"Auto-generated classifier wrapper, based on " + classifier.getClass().getName()
            + " (generated with Weka " + Version.VERSION + ").\\n" + "\" + this.getClass().getName() + \"/"
            + className + "\";\n");
    result.append("  }\n");

    // main
    result.append("\n");
    result.append("  /**\n");
    result.append("   * Runs the classfier from commandline.\n");
    result.append("   *\n");
    result.append("   * @param args the commandline arguments\n");
    result.append("   */\n");
    result.append("  public static void main(String args[]) {\n");
    result.append("    runClassifier(new WekaWrapper(), args);\n");
    result.append("  }\n");
    result.append("}\n");

    // actual classifier code
    result.append("\n");
    result.append(staticClassifier);

    return result.toString();
}

From source file:gui_pt.stream.DoTaskFromGui.java

License:Open Source License

/**
 * Checks if the Weka version is recent enough to run MOA.
 * For example, if the Weka version is not recent, there may be problems
 * due to the fact that <code>Instance</code> was a class before 3.7.1 and
 * now is an interface.//from w ww . j a v a 2s.  c o  m
 *
 * @return true if the Weka version is recent.
 */
public static boolean isWekaVersionOK() {
    Version version = new Version();
    if (version.isOlder("3.7.1")) {
        System.err.println();
        System.err.println(Globals.getWorkbenchInfoString());
        System.err.println();
        System.err.print("Weka 3.7.1 or higher is required to run MOA. ");
        System.err.println("Weka version " + Version.VERSION + " found");
        return false;
    } else {
        return true;
    }
}

From source file:moa.core.WekaUtils.java

License:Open Source License

/**
    * Checks if the Weka version is recent enough to run MOA.
    * For example, if the Weka version is not recent, there may be problems
    * due to the fact that <code>Instance</code> was a class before 3.7.1 and
    * now is an interface./* w w w  .  j a v a 2  s.  c  o  m*/
    *
    * @return true if the Weka version is recent.
    */
public static boolean isWekaVersionOK() {
    try {
        Class.forName("weka.core.Version");
        Version version = new Version();
        if (version.isOlder("3.7.1")) {
            System.err.println();
            System.err.println(Globals.getWorkbenchInfoString());
            System.err.println();
            System.err.print("Weka 3.7.1 or higher is required to run MOA. ");
            System.err.println("Weka version " + Version.VERSION + " found");
            return false;
        } else {
            return true;
        }
    } catch (ClassNotFoundException exception) {
        // It is not available
        return true;
    }
}