コード例 #1
0
ファイル: ToolBelt.java プロジェクト: bitzl/bw-fla
  public ToolBelt(String configFile) throws FitsConfigurationException {
    XMLConfiguration config = null;
    try {
      config = new XMLConfiguration(configFile);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + configFile, e);
    }

    // Collect the tools-used elements
    List<ToolsUsedItem> toolsUsedList = processToolsUsed(config);

    tools = new ArrayList<Tool>();

    // get number of tools
    int size = config.getList("tools.tool[@class]").size();
    // for each tools get the class path and any excluded extensions
    for (int i = 0; i < size; i++) {
      String tClass = config.getString("tools.tool(" + i + ")[@class]");
      @SuppressWarnings("unchecked")
      List<String> excludes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@exclude-exts]");
      @SuppressWarnings("unchecked")
      List<String> includes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@include-exts]");
      Tool t = null;
      try {
        @SuppressWarnings("rawtypes")
        Class c = Class.forName(tClass);
        t = (Tool) c.newInstance();
      } catch (Exception e) {
        // Can't use this tool, but continue anyway.
        // throw new FitsConfigurationException("Error initializing "+tClass,e);
        logger.error(
            "Thread "
                + Thread.currentThread().getId()
                + " error initializing "
                + tClass
                + ": "
                + e.getClass().getName()
                + "  Message: "
                + e.getMessage());
        continue;
      }
      if (t != null) {
        t.setName(bareClassName(tClass));
        for (String ext : excludes) {
          t.addExcludedExtension(ext);
        }
        for (String ext : includes) {
          t.addIncludedExtension(ext);
        }
        // Modify included and excluded extensions by tools-used
        t.applyToolsUsed(toolsUsedList);
        tools.add(t);
      }
    }
  }
コード例 #2
0
ファイル: ToolBelt.java プロジェクト: bitzl/bw-fla
 /* Process the tools-used elements and return a list of
  * ... something */
 private List<ToolsUsedItem> processToolsUsed(XMLConfiguration config) {
   int size = config.getList("tools-used[@exts]").size();
   List<ToolsUsedItem> results = new ArrayList<ToolsUsedItem>(size);
   for (int i = 0; i < size; i++) {
     @SuppressWarnings("unchecked")
     List<String> exts = (List<String>) (List<?>) config.getList("tools-used(" + i + ")[@exts]");
     @SuppressWarnings("unchecked")
     List<String> tools = (List<String>) (List<?>) config.getList("tools-used(" + i + ")[@tools]");
     results.add(new ToolsUsedItem(exts, tools));
   }
   return results; // TODO stub
 }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public void test() {
    try {
      confMonoTests.setFileName("confMonoTests.xml");
      confDbs.setFileName("confDbs.xml");
      confDatasources.setFileName("confDatasources.xml");

      confMonoTests.load();
      confDbs.load();
      confDatasources.load();

      List<String> runs = confMonoTests.getList("run");
      log.info("Start of testing");
      // runs = new TestRun[confRuns.getInt("threads")];
      int numRuns = confMonoTests.getInt("threads");
      String resultsFile = "";
      semRuns = new Semaphore(numRuns);
      // Iterate through runs
      for (String run : runs) {
        int dbId = 0;
        run = "runs." + run;
        // Iterate through dbs
        while (confMonoTests.getProperty(run + ".dbs.db(" + dbId + ").name") != null) {
          String dbName = confMonoTests.getString(run + ".dbs.db(" + dbId + ").name");
          List<String> datasources =
              confMonoTests.getList(run + ".dbs.db(" + dbId + ").datasources");
          int datasourceId = 0;
          // Iterate through datasources
          for (String datasourceName : datasources) {
            int methodId = 0;
            // Load possible normalizers
            List<String> numericalNorms =
                confMonoTests.getList(run + ".normalizers.numericalNormalizer");
            List<String> nominalNormalizers =
                confMonoTests.getList(run + ".normalizers.nominalNormalizer");
            List<String> listNormalizer =
                confMonoTests.getList(run + ".normalizers.listNormalizer");
            // Iterate through tests
            if (confMonoTests.getProperty(run + ".test.path") != null) {
              synchronized (semRuns) {
                // Waiting for a free slot;
                semRuns.acquire();

                System.gc();
                BasicDataSource trainDataSource = getDataSource(datasourceName, dbName);
                trainDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                trainDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");
                BasicDataSource testDataSource = getDataSource(datasourceName, dbName);
                testDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                testDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");

                MonotonicityTest mt = new MonotonicityTest();
                mt.configTest(confMonoTests, run + ".test");
                log.info("Testing datasource " + trainDataSource.getName());
                // Making new thread for a new test.
                new TestRun(
                        this,
                        mt,
                        trainDataSource,
                        testDataSource,
                        getNorms(nominalNormalizers),
                        getNorms(numericalNorms),
                        getNorms(listNormalizer))
                    .start();
                // Wait 1 second for avoid of the colision
                // in writing of results.
                Thread.sleep(1000);
              }
            }
            datasourceId++;
          }
          dbId++;
        }
      }

      // Waiting for all other threads to finish.
      for (int i = 0; i < numRuns; i++) semRuns.acquire();

      log.info("End of testing");

      Process p = Runtime.getRuntime().exec("cmd ", null, null);
      p.getOutputStream().write(("loadResults.bat " + resultsFile + "\n").getBytes());
      p.getOutputStream().flush();
      p.getOutputStream().write("exit\n".getBytes());
      p.getOutputStream().flush();
      BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while (true) {
        try {
          p.exitValue();
          break;
        } catch (Exception e) {
          while (stdOut.ready() || stdErr.ready()) {
            if (stdOut.ready()) stdOut.readLine();
            else stdErr.readLine();
          }
        }
      }
      p.waitFor();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
  @SuppressWarnings("unchecked")
  public void test() {
    try {
      confRuns.setFileName("confRuns.xml");
      confDbs.setFileName("confDbs.xml");
      confDatasources.setFileName("confDatasources.xml");
      confMethods.setFileName("confMethods.xml");

      confRuns.load();
      confDbs.load();
      confDatasources.load();
      confMethods.load();

      List<String> runs = confRuns.getList("run");
      log.info("Start of testing");
      // runs = new TestRun[confRuns.getInt("threads")];
      int numRuns = confRuns.getInt("threads");
      String resultsFile = "";
      semRuns = new Semaphore(numRuns);
      // Iterate through runs
      for (String run : runs) {
        int dbId = 0;
        run = "runs." + run;
        // Iterate through dbs
        while (confRuns.getProperty(run + ".dbs.db(" + dbId + ").name") != null) {
          String dbName = confRuns.getString(run + ".dbs.db(" + dbId + ").name");
          List<String> datasources = confRuns.getList(run + ".dbs.db(" + dbId + ").datasources");
          int datasourceId = 0;
          // Iterate through datasources
          for (String datasourceName : datasources) {
            int methodId = 0;
            // Iterate through methods
            while (confRuns.getProperty(run + ".methods.method(" + methodId + ").name") != null) {
              String methodName =
                  confRuns.getString(run + ".methods.method(" + methodId + ").name");
              int testId = 0;
              // Iterate through tests
              while (confRuns.getProperty(run + ".tests.test(" + testId + ").class") != null) {
                synchronized (semRuns) {
                  // Waiting for a free slot;
                  semRuns.acquire();

                  String testClass = confRuns.getString(run + ".tests.test(" + testId + ").class");
                  Constructor[] a = Class.forName(testClass).getConstructors();
                  log.info("Datasource " + datasourceName + ", method " + methodName);
                  System.gc();
                  BasicDataSource trainDataSource = getDataSource(datasourceName, dbName);
                  trainDataSource.configDriver(confRuns, run + ".dbs.db(" + dbId + ")");
                  trainDataSource.configDataSource(
                      confRuns, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");
                  BasicDataSource testDataSource = getDataSource(datasourceName, dbName);
                  testDataSource.configDriver(confRuns, run + ".dbs.db(" + dbId + ")");
                  testDataSource.configDataSource(
                      confRuns, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");

                  // ExportAsTHSource.exportAsTHSource(trainDataSource, "C:\\data\\",
                  // trainDataSource.getName());
                  // writeRecords(trainDataSource);
                  // writeRecords(testDataSource);
                  // DataSourceStatistics b = new DataSourceStatistics(trainDataSource.getName());
                  // b.getStatistics(trainDataSource);
                  // semRuns.release();
                  InductiveMethod method = getMethod(methodName);
                  method.configClassifier(confRuns, run + ".methods.method(" + methodId + ")");

                  Test test = (Test) a[0].newInstance();
                  test.configTest(confRuns, run + ".tests.test(" + testId + ")");
                  resultsFile = test.getResultsInterpreter().getFilePrefix() + ".csv";

                  log.info("Testing datasource " + trainDataSource.getName());
                  // Making new thread for a new test.
                  new TestRun(this, trainDataSource, testDataSource, method, test).start();
                  // Wait 1 second for avoid of the colision
                  // in writing of results.
                  Thread.sleep(1000);
                }
                testId++;
              }
              methodId++;
            }
            datasourceId++;
          }
          dbId++;
        }
      }
      // Waiting for all other threads to finish.
      for (int i = 0; i < numRuns; i++) semRuns.acquire();

      log.info("End of testing");

      Process p = Runtime.getRuntime().exec("cmd ", null, null);
      p.getOutputStream().write(("loadResults.bat " + resultsFile + "\n").getBytes());
      p.getOutputStream().flush();
      p.getOutputStream().write("exit\n".getBytes());
      p.getOutputStream().flush();
      BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while (true) {
        try {
          p.exitValue();
          break;
        } catch (Exception e) {
          while (stdOut.ready() || stdErr.ready()) {
            if (stdOut.ready()) stdOut.readLine();
            else stdErr.readLine();
          }
        }
      }
      p.waitFor();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }