public static void printPerformanceStatistics(List<PerformanceStatistic> performanceStatistics) {
    if (null == performanceStatistics) return;
    System.out.flush();
    StringBuilder sb = new StringBuilder();
    if (performanceStatistics.size() == 0) {
      sb.append(getPerformanceStatistics_noResults());
    } else {
      Collections.sort(performanceStatistics);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PrintStream writer = new PrintStream(baos);

      for (PerformanceStatistic rp : performanceStatistics) {
        writer.append(LINE_SEPARATOR);
        writer.printf(
            "| %10d | %10d | %11.3f sec | %11.3f sec | %11.3f sec | %11.3f sec | %11.3f sec | %11.3f sec | %8.2f MB | %s", //
            rp.getNoOfRules(),
            rp.getNoOfLiterals(), //
            .001 * rp.getLoadTheoryTimeUsed(), //
            .001 * rp.getNormalFormTransformationTimeUsed(), //
            .001 * rp.getDefeaterRemovalTimeUsed(), //
            .001 * rp.getSuperiorityRemovalTimeUsed(), //
            .001 * rp.getReasoningTimeUsed(), //
            .001 * rp.getTotalTimeUsed(), //
            1.0 * rp.getMaxMemoryUsed() / 1024 / 1024, //
            rp.getUrl().toString());
      }
      writer.flush();

      Object[] args = {
        Converter.long2TimeString(IOManager.getConfigurationTimeUsed()),
        performanceStatistics.size(),
        baos.toString()
      };

      try {
        sb.append(
            TextUtilities.formatArguments(getPerformanceStatisticsTemplate(), args.length, args));
      } catch (InvalidArgumentException e) {
        e.printStackTrace();
      }
    }
    System.out.println(sb.toString());
    System.out.flush();
  }
Beispiel #2
0
  private static void runReasoner(URL url) throws ReasonerException {
    PerformanceStatistic ps = new PerformanceStatistic(url);
    performanceStatistics.add(ps);

    Reasoner reasoner = new Reasoner();
    reasoner.addReasonerMessageListener(messageListener);

    try {
      memoryMonitor.reset();
      memoryMonitor.startMonitor();

      ps.setStartLoadTheory();
      reasoner.loadTheory(url);
      Theory theory = reasoner.getTheory();
      ps.setEndLoadTheory();

      ps.setNoOfRules(reasoner.getTheory().getFactsAndAllRules().size());
      ps.setNoOfLiterals(reasoner.getTheory().getAllLiteralsInRules().size());

      ps.setStartNormalFormTransformation();
      reasoner.transformTheoryToRegularForm();
      ps.setEndNormalFormTransformation();

      if (theory.getDefeatersCount() > 0) {
        ps.setStartDefeaterRemoval();
        reasoner.removeDefeater();
        ps.setEndTimeDefeaterRemoval();
      }

      switch (Conf.getReasonerVersion()) {
        case 1:
          if (theory.getSuperiorityCount() > 0) {
            ps.setStartSuperiorityRemoval();
            reasoner.removeSuperiority();
            ps.setEndTimeSuperiorityRemoval();
          }
          break;
        default:
      }

      ps.setStartReasoning();
      reasoner.getConclusions();
      ps.setEndReasoning();

      ps.setMaxMemoryUsed(memoryMonitor.getMemoryUsed());
      if (Conf.isShowStatistics()) System.out.println(ps.toString());

      if (Conf.isSaveResult()) {
        File fd = null;
        File urlFile = new File(url.getFile());
        if ("".equals(url.getHost())) {
          // create the conclusions folder if it does not exists
          fd = new File(urlFile.getParentFile(), Conf.getResultFolder());
          fd.mkdirs();
        } else {
          fd = new File(Conf.getResultFolder(), url.getFile());
          fd = fd.getParentFile();

          if (null != fd.getParentFile()) fd.getParentFile().mkdirs();
        }

        // create the conclusions file name
        File outFilename =
            FileManager.changeFileExtension(
                FileManager.addFilenamePostfix(urlFile, "_conclusions"), Conf.getConclusionExt());
        File outFile = new File(fd, outFilename.getName());

        // save conclusions
        reasoner.saveConclusions(outFile);
      }
      if (Conf.isLogInferenceProcess()) {
        InferenceLogger inferenceLogger = reasoner.getInferenceLogger();
        if (null != inferenceLogger) {
          System.out.println(
              "=== Inference Logger - start ===\n"
                  + inferenceLogger
                  + "\n=== Inference Logger -  end  ===");
        }
      }
    } catch (Exception e) {
      throw new ReasonerException("exception throw while reasoning", e);
    } finally {
      reasoner.clear();
      reasoner.removeReasonerMessageListener(messageListener);
      reasoner = null;
    }
  }