<commit_before>/*
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * Licensed under the BSD 3-Clause License.
 */

package vsr.cobalt.service.planner;

import vsr.cobalt.models.Repository;
import vsr.cobalt.planner.DefaultMashupPlanner;
import vsr.cobalt.planner.GraphExtender;
import vsr.cobalt.planner.GraphFactory;
import vsr.cobalt.planner.PlanCollector;
import vsr.cobalt.planner.PlanExtractor;
import vsr.cobalt.planner.PlanningException;
import vsr.cobalt.planner.PlanningProcess;
import vsr.cobalt.planner.collectors.RatingPlanCollector;
import vsr.cobalt.planner.extenders.DefaultGraphExtender;
import vsr.cobalt.planner.extenders.DefaultGraphFactory;
import vsr.cobalt.planner.extenders.PathWalkingCyclicDependencyDetector;
import vsr.cobalt.planner.extenders.providers.BasicPrecursorActionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingExtendedPrecursorActionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingFunctionalityProvisionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingPropertyProvisionProvider;
import vsr.cobalt.planner.extractors.BackwardChainingPlanExtractor;

/**
 * @author <NAME>
 */
public class PlannerJob {

  private final PlannerRequest request;

  private final Repository repository;

  public PlannerJob(final PlannerRequest request, final Repository repository) {
    this.request = request;
    this.repository = repository;
  }

  public PlannerResponse run() {
    final RatingPlanCollector plans = createPlanCollector();
    final PlanningProcess process = createPlanningTask(createPlanner(), plans);

    while (!process.isDone()) {
      try {
        process.advance();
      } catch (final PlanningException ex) {
        return new PlannerFailure(ex);
      }
    }

    return new PlannerSuccess(plans);
  }

  private RatingPlanCollector createPlanCollector() {
    return new RatingPlanCollector(new DefaultPlanRater(repository));
  }

  private PlanningProcess createPlanningTask(final DefaultMashupPlanner planner, final PlanCollector collector) {
    return planner.createPlanningProcess(request.getPlanningProblem(), collector);
  }

  private DefaultMashupPlanner createPlanner() {
    return new DefaultMashupPlanner(createGraphFactory(), createGraphExtender(), createPlanExtractor());
  }

  private GraphFactory createGraphFactory() {
    return new DefaultGraphFactory(new ComposingFunctionalityProvisionProvider(repository));<commit_msg>fix PlannerJob to report any exception as failure<commit_after>/*
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * Licensed under the BSD 3-Clause License.
 */

package vsr.cobalt.service.planner;

import vsr.cobalt.models.Repository;
import vsr.cobalt.planner.DefaultMashupPlanner;
import vsr.cobalt.planner.GraphExtender;
import vsr.cobalt.planner.GraphFactory;
import vsr.cobalt.planner.PlanCollector;
import vsr.cobalt.planner.PlanExtractor;
import vsr.cobalt.planner.PlanningProcess;
import vsr.cobalt.planner.collectors.RatingPlanCollector;
import vsr.cobalt.planner.extenders.DefaultGraphExtender;
import vsr.cobalt.planner.extenders.DefaultGraphFactory;
import vsr.cobalt.planner.extenders.PathWalkingCyclicDependencyDetector;
import vsr.cobalt.planner.extenders.providers.BasicPrecursorActionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingExtendedPrecursorActionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingFunctionalityProvisionProvider;
import vsr.cobalt.planner.extenders.providers.ComposingPropertyProvisionProvider;
import vsr.cobalt.planner.extractors.BackwardChainingPlanExtractor;

/**
 * @author <NAME>
 */
public class PlannerJob {

  private final PlannerRequest request;

  private final Repository repository;

  public PlannerJob(final PlannerRequest request, final Repository repository) {
    this.request = request;
    this.repository = repository;
  }

  public PlannerResponse run() {
    final RatingPlanCollector plans = createPlanCollector();
    final PlanningProcess process = createPlanningTask(createPlanner(), plans);

    while (!process.isDone()) {
      try {
        process.advance();
      } catch (final Exception ex) {
        return new PlannerFailure(ex);
      }
    }

    return new PlannerSuccess(plans);
  }

  private RatingPlanCollector createPlanCollector() {
    return new RatingPlanCollector(new DefaultPlanRater(repository));
  }

  private PlanningProcess createPlanningTask(final DefaultMashupPlanner planner, final PlanCollector collector) {
    return planner.createPlanningProcess(request.getPlanningProblem(), collector);
  }

  private DefaultMashupPlanner createPlanner() {
    return new DefaultMashupPlanner(createGraphFactory(), createGraphExtender(), createPlanExtractor());
  }

  private GraphFactory createGraphFactory() {
    return new DefaultGraphFactory(new ComposingFunctionalityProvisionProvider(repository));
{'fraction_non_alphanumeric': 0.08542816268138156, 'fraction_numerical': 0.0020437359493153486, 'mean_word_length': 5.658503401360544, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5216885', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1438, 'n_words': 270}