コード例 #1
0
 public function workerunit_output_cf_factorspan_merged_relex($mappedWorkerunitsWithUnits)
 {
     $tempEntityID = null;
     $status = array();
     try {
         $activity = new Activity();
         $activity->softwareAgent_id = "importer";
         $activity->save();
     } catch (Exception $e) {
         // Something went wrong with creating the Activity
         $activity->forceDelete();
         $status['error']['activity'] = $e->getMessage();
         return $status;
     }
     $relexStructurer = App::make('\\preprocess\\RelexStructurer');
     $test = array();
     foreach ($mappedWorkerunitsWithUnits as $mappedWorkerunitsWithUnitKey => $mappedWorkerunitsWithUnitVal) {
         $parentEntity = $mappedWorkerunitsWithUnitVal['unit'];
         $parentEntity['content']['terms']['first']['text'] = strtolower(str_replace(["[", "]"], ["", ""], $mappedWorkerunitsWithUnitVal['term1']));
         $parentEntity['content']['terms']['second']['text'] = strtolower(str_replace(["[", "]"], ["", ""], $mappedWorkerunitsWithUnitVal['term2']));
         $parentEntity['content']['terms']['first']['formatted'] = $mappedWorkerunitsWithUnitVal['term1'];
         $parentEntity['content']['terms']['first']['startIndex'] = (int) $mappedWorkerunitsWithUnitVal['b1'];
         $parentEntity['content']['terms']['first']['endIndex'] = (int) $mappedWorkerunitsWithUnitVal['e1'];
         $parentEntity['content']['terms']['second']['formatted'] = $mappedWorkerunitsWithUnitVal['term2'];
         $parentEntity['content']['terms']['second']['startIndex'] = (int) $mappedWorkerunitsWithUnitVal['b2'];
         $parentEntity['content']['terms']['second']['endIndex'] = (int) $mappedWorkerunitsWithUnitVal['e2'];
         $parentEntity['content']['sentence']['formatted'] = $mappedWorkerunitsWithUnitVal['sentence'];
         $parentEntity['content']['properties']['overlappingTerms'] = $relexStructurer->overlappingTerms($parentEntity['content']);
         $title = $parentEntity['title'] . "_FS_" . $mappedWorkerunitsWithUnitKey;
         try {
             $entity = new Entity();
             $entity->_id = $tempEntityID;
             $entity->sent_id = $mappedWorkerunitsWithUnitVal['Sent_id'];
             $entity->title = strtolower($title);
             $entity->domain = $parentEntity['domain'];
             $entity->format = $parentEntity['format'];
             $entity->documentType = "relex-structured-sentence";
             $entity->parents = array($parentEntity['_id']);
             $entity->content = $parentEntity['content'];
             unset($parentEntity['properties']);
             $entity->hash = md5(serialize($parentEntity['content']));
             $entity->activity_id = $activity->_id;
             $entity->save();
             array_push($test, $entity->toArray());
             $status['success'][$title] = $title . " was successfully processed into a relex-structured-sentence. (URI: {$entity->_id} {$entity->hash})";
         } catch (Exception $e) {
             // Something went wrong with creating the Entity
             $entity->forceDelete();
             $status['error'][$title] = $e->getMessage() . " " . $entity->hash;
         }
         $tempEntityID = $entity->_id;
     }
     return $test;
     return $status;
 }
コード例 #2
0
ファイル: apiController.php プロジェクト: harixxy/CrowdTruth
 public function postFeatures()
 {
     $return = array('status' => 'ok');
     $input = Input::get();
     $domain = $input[1];
     $type = $input[2];
     // CREATE ACTIVITY FOR BATCH
     $activity = new Activity();
     $activity->label = "Images posted for processing.";
     $activity->softwareAgent_id = 'imagegetter';
     $activity->save();
     // LOOP THROUGH IMAGES CREATE ENTITIES WITH ACTIVITY-ID FOR NEW IMAGES
     $url_ids = "";
     foreach ($input[0] as $img) {
         \Log::debug(json_encode($img));
         try {
             $parse = parse_url($img['url']);
             //$source = $parse['host'];
             // Save images as parent
             $image = new Entity();
             $image->domain = $domain;
             $image->format = "image";
             $content = $image->content;
             $content['url'] = $img['url'];
             $content['title'] = $img['title'];
             $content['height'] = $img['height'];
             $content['width'] = $img['width'];
             $content['description'] = $img['description'];
             $content['author'] = $img['author'];
             $image->content = $content;
             $image->documentType = $type;
             $image->source = "Rijksmuseum";
             $image->tags = ['unit'];
             $image->activity_id = $activity->_id;
             $image->softwareAgent_id = "imagegetter";
             // Take last part of URL as image title
             $temp = explode('/', $img['url']);
             //$image->title = end($temp);
             // CHECK WHETHER URL EXISTS ALREADY
             $hash = md5(serialize($image->content));
             if ($existingid = Entity::where('hash', $hash)->pluck('_id')) {
                 $imageid = $existingid;
             } else {
                 $image->hash = $hash;
                 $image->activity_id = $activity->_id;
                 \Log::debug(json_encode($image->toArray()));
                 $image->save();
                 $existingid = $image->_id;
             }
             $url_ids .= "{$img['url']} {$existingid} ";
         } catch (Exception $e) {
             //delete image
             if (isset($image)) {
                 $image->forceDelete();
             }
             //delete activity
             if (isset($activity)) {
                 $activity->forceDelete();
             }
             //Session::flash('flashError', $e->getMessage());
             $return['error'] = $e->getMessage();
             $return['status'] = 'bad';
             \Log::debug($e->getMessage());
             return $return;
         }
         // RUN PYTHON SCRIPT THAT CALLS APIs TO ADD FEATURES TO IMAGE
     }
     //return $url_ids;
     try {
         //$command = "/usr/bin/python2.7 /var/www/crowd-watson/app/lib/getAPIS/getRijks.py " . $domain . " " . $type . " " . 4 . " " . "vogel";
         $command = "/usr/bin/python2.7 " . base_path() . "/app/lib/getAPIS/getMany.py " . $domain . " " . $type . " " . Auth::user()->email . " " . $url_ids;
         //$command = "/usr/bin/python2.7 /var/www/crowd-watson/app/lib/getAPIS/getMany.py art painting http://lh3.ggpht.com/Q1GZTdmwa8iTLgdbu5uAgzovmLbb7lsYhG-QgVcoN8A-WJtIsNUo4-VyTMd9iKHLp-XNm812WyUaSgQdHdjQjDioJQI=s0 999";
         //return $command;
         \Log::debug("Running {$command}");
         exec($command, $output, $error);
         $return['oo'] = $output;
         $return['ee'] = $error;
         //$return['a'] = $a;
         //throw $e; // for debugging.
         //return $error;
     } catch (Exception $e) {
         //throw $e; // for debugging.
         \Log::debug("ERROR: " . $e->getMessage());
         $return['error'] = $e->getMessage();
         $return['status'] = 'bad';
     }
     return $this->returnJson($return);
 }