<commit_before>package de.fuberlin.wiwiss.silk.workbench.lift.comet

import de.fuberlin.wiwiss.silk.workbench.learning.CurrentLearningTask
import de.fuberlin.wiwiss.silk.util.task.{Finished, Started, Status}
import de.fuberlin.wiwiss.silk.workbench.workspace.CurrentStatusListener
import de.fuberlin.wiwiss.silk.workbench.lift.snippet.StartLearningDialog
import de.fuberlin.wiwiss.silk.workbench.lift.util.{JS, DynamicButton}

/**
 * Button to control the learning process.
 */
class StartLearningButton extends DynamicButton {

  override protected val dontCacheRendering = true

  label = "Start"

  /**
   * Called when the button has been pressed.
   */
  override protected def onPressed() = {
    //TODO check if cache is being loaded

    if (!CurrentLearningTask().status.isRunning)
      StartLearningDialog.openCmd
    else {
      CurrentLearningTask().cancel()
      JS.Empty
    }
  }

  /**
   * Listens to changes of the current learning task.
   */
  private val learningTaskListener = new CurrentStatusListener(CurrentLearningTask) {
    override def onUpdate(status: Status) {
      status match {
        case _: Started => label = "Stop"
        case _: Finished => label = "Start"
        case _ =>
      }
    }
  }
}<commit_msg>Learning: Check if cache is loaded and reference links are present before starting<commit_after>package de.fuberlin.wiwiss.silk.workbench.lift.comet

import de.fuberlin.wiwiss.silk.workbench.learning.CurrentLearningTask
import de.fuberlin.wiwiss.silk.util.task.{Finished, Started, Status}
import de.fuberlin.wiwiss.silk.workbench.lift.snippet.StartLearningDialog
import de.fuberlin.wiwiss.silk.workbench.lift.util.{JS, DynamicButton}
import de.fuberlin.wiwiss.silk.workbench.workspace.{User, CurrentStatusListener}

/**
 * Button to control the learning process.
 */
class StartLearningButton extends DynamicButton {

  override protected val dontCacheRendering = true

  label = "Start"

  /**
   * Called when the button has been pressed.
   */
  override protected def onPressed() = {
    if(User().linkingTask.cache.status.isRunning) {
      JS.Message("Cache not loaded yet.")
    } else if(User().linkingTask.alignment.positive.size < 1 || User().linkingTask.alignment.negative.size < 1) {
      JS.Message("Positive and negative reference links are needed in order to learn a link specification")
    } else if (!CurrentLearningTask().status.isRunning)
      StartLearningDialog.openCmd
    else {
      CurrentLearningTask().cancel()
      JS.Empty
    }
  }

  /**
   * Listens to changes of the current learning task.
   */
  private val learningTaskListener = new CurrentStatusListener(CurrentLearningTask) {
    override def onUpdate(status: Status) {
      status match {
        case _: Started => label = "Stop"
        case _: Finished => label = "Start"
        case _ =>
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.10178384050367262, 'fraction_numerical': 0.0006995452955578874, 'mean_word_length': 3.489795918367347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2685184', 'n_tokens_mistral': 908, 'n_tokens_neox': 847, 'n_words': 199}