예제 #1
0
  @Test
  public void testAllRecommenderSystemsFilePersistence()
      throws CannotLoadRatingsDataset, CannotLoadContentDataset {
    final List<RecommenderSystem> recommenderSystems =
        RecommenderSystemsFactory.getInstance().getAllClasses(RecommenderSystem.class);

    for (RecommenderSystem recommenderSystem : recommenderSystems) {
      if (recommenderSystem instanceof Recommender_DatasetProperties) {
        continue;
      }

      String configFile = TEST_DIRECTORY + recommenderSystem.getName() + "_config.xml";

      RecommenderSystemConfigurationFileParser.saveConfigFile(
          configFile,
          recommenderSystem,
          datasetLoader,
          new FilePersistence(recommenderSystem.getName(), "dat", new File(TEST_DIRECTORY)),
          new OnlyNewItems(),
          getRecommendationOutputFileXML(recommenderSystem));

      Chronometer chronometer = new Chronometer();
      SingleUserRecommendation.buildRecommendationModel(configFile);
      Global.showln(
          "Built model of '" + recommenderSystem + "' in " + chronometer.printTotalElapsed());

      RatingsDataset<? extends Rating> ratingsDataset = datasetLoader.getRatingsDataset();
      chronometer.reset();
      ratingsDataset
          .allUsers()
          .stream()
          .forEach(
              (idUser) -> {
                SingleUserRecommendation.recommendToUser(configFile, idUser);
              });
      Global.showln(
          "Recommended with '"
              + recommenderSystem
              + "' to "
              + datasetLoader.getRatingsDataset().allUsers().size()
              + " users in "
              + chronometer.printTotalElapsed());
    }
  }
  @Override
  public void progressChanged(ExperimentProgress algorithmExperiment) {

    String executionTask = algorithmExperiment.getExecutionProgressTask();
    int executionPercent = algorithmExperiment.getExecutionProgressPercent();

    boolean begin = executionPercent == 0;
    boolean finish = executionPercent == 100;
    boolean repeated =
        executionPercent == executionLastPercent && executionTask.equals(executionLastTask);
    boolean timeTrigger = chronometer.getTotalElapsed() >= verbosePeriod;
    if (((begin || finish) && !repeated) || timeTrigger) {
      printProgress(algorithmExperiment);

      executionLastPercent = executionPercent;
      executionLastTask = executionTask;
      chronometer.reset();
    }
  }