Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
 /**
  * Handles admin requests for creating, editing, and deleting classifiers.
  *
  * This activity implements the logic for the page that lists existing
  * classifiers, including the actions that can be performed on them.
  */
 function manageClassifiers()
 {
     $parent = $this->parent;
     $crawl_model = $parent->model("crawl");
     $possible_arguments = array('createclassifier', 'editclassifier', 'finalizeclassifier', 'deleteclassifier', 'search');
     $data['ELEMENT'] = 'manageclassifiers';
     $data['SCRIPT'] = '';
     $data['FORM_TYPE'] = '';
     $search_array = array();
     $machine_urls = $parent->model("machine")->getQueueServerUrls();
     $num_machines = count($machine_urls);
     if ($num_machines < 1 || $num_machines == 1 && UrlParser::isLocalhostUrl($machine_urls[0])) {
         $machine_urls = NULL;
     }
     $data['leftorright'] = getLocaleDirection() == 'ltr' ? 'right' : 'left';
     $classifiers = Classifier::getClassifierList();
     $start_finalizing = false;
     if (isset($_REQUEST['arg']) && in_array($_REQUEST['arg'], $possible_arguments)) {
         if (isset($_REQUEST['name'])) {
             $name = substr($parent->clean($_REQUEST['name'], 'string'), 0, NAME_LEN);
             $name = Classifier::cleanLabel($name);
         } else {
             if (isset($_REQUEST['class_label'])) {
                 $name = substr($parent->clean($_REQUEST['class_label'], 'string'), 0, NAME_LEN);
                 $name = Classifier::cleanLabel($name);
             } else {
                 $name = "";
             }
         }
         switch ($_REQUEST['arg']) {
             case 'createclassifier':
                 if (!isset($classifiers[$name])) {
                     $classifier = new Classifier($name);
                     Classifier::setClassifier($classifier);
                     $classifiers[$name] = $classifier;
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_new_classifier') . '</h1>\');';
                 } else {
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_classifier_exists') . '</h1>\');';
                 }
                 break;
             case 'deleteclassifier':
                 /*
                   In addition to deleting the classifier, we also want to
                   delete the associated crawl mix (if one exists) used to
                   iterate over existing indexes in search of new training
                   examples.
                 */
                 if (isset($classifiers[$name])) {
                     unset($classifiers[$name]);
                     Classifier::deleteClassifier($name);
                     $mix_name = Classifier::getCrawlMixName($name);
                     $mix_time = $crawl_model->getCrawlMixTimestamp($mix_name);
                     if ($mix_time) {
                         $crawl_model->deleteCrawlMixIteratorState($mix_time);
                         $crawl_model->deleteCrawlMix($mix_time);
                     }
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_classifier_deleted') . '</h1>\');';
                 } else {
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_no_classifier') . '</h1>\');';
                 }
                 break;
             case 'editclassifier':
                 if (isset($classifiers[$name])) {
                     $data['class_label'] = $name;
                     $this->editClassifier($data, $classifiers, $machine_urls);
                 } else {
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_no_classifier') . '</h1>\');';
                 }
                 break;
             case 'finalizeclassifier':
                 /*
                   Finalizing is too expensive to be done directly in the
                   controller that responds to the web request. Instead, a
                   daemon is launched to finalize the classifier
                   asynchronously and save it back to disk when it's done.
                   In the meantime, a flag is set to indicate the current
                   finalizing state.
                 */
                 CrawlDaemon::start("classifier_trainer", $name, '', -1);
                 $classifier = $classifiers[$name];
                 $classifier->finalized = Classifier::FINALIZING;
                 $start_finalizing = true;
                 $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_finalizing_classifier') . '</h1>\');';
                 break;
             case 'search':
                 $search_array = $parent->tableSearchRequestHandler($data, array('name'));
                 break;
         }
     }
     $data['classifiers'] = $classifiers;
     if ($search_array == array()) {
         $search_array[] = array("name", "", "", "ASC");
     }
     $parent->pagingLogic($data, 'classifiers', 'classifiers', DEFAULT_ADMIN_PAGING_NUM, $search_array, "", array('name' => 'class_label'));
     $data['reload'] = false;
     foreach ($classifiers as $label => $classifier) {
         if ($classifier->finalized == Classifier::FINALIZING) {
             $data['reload'] = true;
             break;
         }
     }
     if ($data['reload'] && !$start_finalizing) {
         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\">" . tl('crawl_component_finalizing_classifier') . '</h1>\');';
     }
     return $data;
 }
Exemplo n.º 3
0
 /**
  * Retrieves an iterator for an existing crawl mix. The crawl mix remembers
  * its previous offset, so that the new iterator picks up where the
  * previous one left off.
  *
  * @param string $label class label of the classifier this crawl mix is
  * associated with
  * @return object new MixArchiveBundleIterator instance that picks up where
  * the previous one left off
  */
 function retrieveClassifierCrawlMix($label)
 {
     $mix_name = Classifier::getCrawlMixName($label);
     $mix_time = $this->model("crawl")->getCrawlMixTimestamp($mix_name);
     return new MixArchiveBundleIterator($mix_time, $mix_time);
 }