コード例 #1
0
 public static function fromJSON($filename)
 {
     $jc = new JobConfiguration();
     try {
         if (!file_exists($filename) || !is_readable($filename)) {
             throw new Exception('JSON template file does not exist or is not readable.');
         }
         $json = file_get_contents($filename);
         if (!($arr = json_decode($json, true))) {
             throw new Exception('JSON incorrectly formatted');
         }
         $jc->content = $arr;
         return $jc;
     } catch (Exception $e) {
         Log::debug("{$e} - using empty JobConf");
         return $jc;
     }
 }
コード例 #2
0
ファイル: Workerunit.php プロジェクト: crowdtruth/crowdtruth
 public function createAnnotationVectorRelEx()
 {
     try {
         // AMT
         if (isset($this->content['Q1text'])) {
             $ans = str_replace(" ", "_", rtrim($this->content['Q1text']));
             $ans = str_replace("[DIAGNOSED_BY_TEST_OR_DRUG]", "[DIAGNOSE_BY_TEST_OR_DRUG]", $ans);
             if ($ans == '') {
                 return null;
             }
             // throw new Exception('Answer is empty.');
             $ans = str_replace("]_[", "]*[", $ans);
             $ans = explode('*', $ans);
             // CF
         } elseif (isset($this->content['step_1_select_the_valid_relations'])) {
             if (is_array($this->content['step_1_select_the_valid_relations'])) {
                 $ans = $this->content['step_1_select_the_valid_relations'];
             } else {
                 $ans = str_replace("\n", "_", rtrim($this->content['step_1_select_the_valid_relations']));
                 $ans = str_replace("\r", "_", $ans);
                 $ans = str_replace("]_[", "]*[", $ans);
                 $ans = explode('*', $ans);
             }
         } else {
             throw new Exception('Can\'t determine if it\'s CF or AMT.');
         }
         /*            if(in_array("[NONE]", $ans)){
                         if(count($ans)>1)
                             throw new Exception('Worker selected none but also other relations.');
         
                         if(empty($this->content['Q2b']))
                             throw new Exception('Worker selected [NONE] but gave no explanation.');
         
                     } elseif(empty($this->content['Q2a'])){
                         throw new Exception('Worker selected a relation but didn\'t hightlight words');
                     }*/
         $dic = array("[TREATS]" => in_array("[TREATS]", $ans) ? 1 : 0, "[CAUSES]" => in_array("[CAUSES]", $ans) ? 1 : 0, "[PREVENTS]" => in_array("[PREVENTS]", $ans) ? 1 : 0, "[IS_A]" => in_array("[IS_A]", $ans) ? 1 : 0, "[OTHER]" => in_array("[OTHER]", $ans) ? 1 : 0, "[NONE]" => in_array("[NONE]", $ans) ? 1 : 0, "[PART_OF]" => in_array("[PART_OF]", $ans) ? 1 : 0, "[DIAGNOSE_BY_TEST_OR_DRUG]" => in_array("[DIAGNOSE_BY_TEST_OR_DRUG]", $ans) ? 1 : 0, "[ASSOCIATED_WITH]" => in_array("[ASSOCIATED_WITH]", $ans) ? 1 : 0, "[SIDE_EFFECT]" => in_array("[SIDE_EFFECT]", $ans) ? 1 : 0, "[SYMPTOM]" => in_array("[SYMPTOM]", $ans) ? 1 : 0, "[LOCATION]" => in_array("[LOCATION]", $ans) ? 1 : 0, "[MANIFESTATION]" => in_array("[MANIFESTATION]", $ans) ? 1 : 0, "[CONTRAINDICATES]" => in_array("[CONTRAINDICATES]", $ans) ? 1 : 0);
         // We decided to give the spammers just empty vectors.
         /*            foreach($ans as $a){
                         if(!in_array($a, array_keys($dic)))
                            throw new Exception("Answer $a not in annotationVector.");
                     }
         
                     if(!in_array(1, $dic)){
                         throw new Exception('AnnotationVector EMPTY');
                     }*/
         return array('extraction' => $dic);
     } catch (Exception $e) {
         echo $e->getMessage();
         Log::debug($e->getMessage());
         return null;
     }
 }
コード例 #3
0
ファイル: Job.php プロジェクト: crowdtruth/crowdtruth
 /** 
  * In case of exception: undo everything.
  * @throws Exception if even the undo isn't working. 
  */
 private function undoCreation($ids, $error = null)
 {
     // TODO use platformjobid.
     Log::debug("Attempting to delete jobs from crowdsourcing platform.");
     try {
         $this->getPlatform()->undoCreation($ids);
     } catch (Exception $e) {
         // This is bad.
         if ($error) {
             $orige = $error->getMessage();
         } else {
             $orige = 'None.';
         }
         $newe = $e->getMessage();
         throw new Exception("WARNING. There was an error in uploading the jobs. We could not undo all the steps. \n\t\t\t\tPlease check the platforms manually and delete any uploaded jobs.\n\t\t\t\t<br>Initial exception: {$orige}\n\t\t\t\t<br>Deletion error: {$newe}\n\t\t\t\t<br>Please contact an administrator.");
         Log::warning("Couldn't delete jobs. Please manually check the platforms and database.\r\nInitial exception: {$orige}\n\t\t\t\t\r\nDeletion error: {$newe}\r\nActivity: {$this->activityURI}\r\nJob ID's: " . json_encode($ids));
     }
 }