Esempio n. 1
0
 /**
  * Handles the particulars of editing a classifier, which includes changing
  * its label and adding training examples.
  *
  * This activity directly handles changing the class label, but not adding
  * training examples. The latter activity is done interactively without
  * reloading the page via XmlHttpRequests, coordinated by the classifier
  * controller dedicated to that task.
  *
  * @param array $data data to be passed on to the view
  * @param array $classifiers map from class labels to their associated
  *    classifiers
  * @param array $machine_urls string urls of machines managed by this
  *    Yioop name server
  */
 function editClassifier(&$data, $classifiers, $machine_urls)
 {
     $parent = $this->parent;
     $data['ELEMENT'] = 'editclassifier';
     $data['INCLUDE_SCRIPTS'] = array('classifiers');
     // We want recrawls, but not archive crawls.
     $crawls = $parent->model("crawl")->getCrawlList(false, true, $machine_urls);
     $data['CRAWLS'] = $crawls;
     $classifier = $classifiers[$data['class_label']];
     if (isset($_REQUEST['update']) && $_REQUEST['update'] == 'update') {
         if (isset($_REQUEST['rename_label'])) {
             $new_label = substr($parent->clean($_REQUEST['rename_label'], 'string'), 0, NAME_LEN);
             $new_label = preg_replace('/[^a-zA-Z0-9_]/', '', $new_label);
             if (!isset($classifiers[$new_label])) {
                 $old_label = $classifier->class_label;
                 $classifier->class_label = $new_label;
                 Classifier::setClassifier($classifier);
                 Classifier::deleteClassifier($old_label);
                 $data['class_label'] = $new_label;
             } else {
                 $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_classifier_exists') . '</h1>\');';
             }
         }
     }
     $data['classifier'] = $classifier;
     // Translations for the classification javascript.
     $data['SCRIPT'] .= "window.tl = {" . 'crawl_component_load_failed:"' . tl('crawl_component_load_failed') . '",' . 'crawl_component_loading:"' . tl('crawl_component_loading') . '",' . 'crawl_component_added_examples:"' . tl('crawl_component_added_examples') . '",' . 'crawl_component_label_update_failed:"' . tl('crawl_component_label_update_failed') . '",' . 'crawl_component_updating:"' . tl('crawl_component_updating') . '",' . 'crawl_component_acc_update_failed:"' . tl('crawl_component_acc_update_failed') . '",' . 'crawl_component_na:"' . tl('crawl_component_na') . '",' . 'crawl_component_no_docs:"' . tl('crawl_component_no_docs') . '",' . 'crawl_component_num_docs:"' . tl('crawl_component_num_docs') . '",' . 'crawl_component_in_class:"' . tl('crawl_component_in_class') . '",' . 'crawl_component_not_in_class:"' . tl('crawl_component_not_in_class') . '",' . 'crawl_component_skip:"' . tl('crawl_component_skip') . '",' . 'crawl_component_prediction:"' . tl('crawl_component_prediction') . '",' . 'crawl_component_scores:"' . tl('crawl_component_scores') . '"' . '};';
     /*
       We pass along authentication information to the client, so that it
       can authenticate any XmlHttpRequests that it makes in order to label
       documents.
     */
     $time = strval(time());
     $session = md5($time . AUTH_KEY);
     $data['SCRIPT'] .= "Classifier.initialize(" . "'{$data['class_label']}'," . "'{$session}'," . "'{$time}');";
 }
Esempio n. 2
0
 /**
  * Deletes an existing classifier, specified by its label.
  *
  * @param string $label class label of the existing classifier
  */
 function deleteClassifier($label)
 {
     Classifier::deleteClassifier($label);
     $mix_name = Classifier::getCrawlMixName($label);
     $mix_time = $this->crawlModel->getCrawlMixTimestamp($mix_name);
     if ($mix_time) {
         $this->crawlModel->deleteCrawlMixIteratorState($mix_time);
         $this->crawlModel->deleteCrawlMix($mix_time);
     }
 }