Пример #1
0
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($entity) {
         if (!Schema::hasCollection('entities')) {
             static::createSchema();
         }
         if (!empty($entity->hash)) {
             if (Entity::withTrashed()->where('hash', $entity->hash)->first()) {
                 throw new Exception("Hash already exists for: " . $entity->title);
             }
         }
         if (empty($entity->_id)) {
             $entity->_id = static::generateIncrementedBaseURI($entity);
         }
         if (Auth::check()) {
             $entity->user_id = Auth::user()->_id;
         } else {
             $entity->user_id = "crowdwatson";
         }
     });
     static::saving(function ($entity) {
         if (Auth::check()) {
             $entity->user_id = Auth::user()->_id;
         } else {
             $entity->user_id = "crowdwatson";
         }
         static::validateEntity($entity);
     });
     static::saved(function ($entity) {
         \MongoDB\Temp::truncate();
         Cache::flush();
     });
     static::deleted(function ($entity) {
         Cache::flush();
     });
 }
 /**
  * Store to the database the given entities as entities decendent from the given
  * document.
  * 
  * @param $document Parent document -- Must be a document entity on the database.
  * @param $entities List of entities to be created as decendents from the given document. 
  * 
  * @return multitype:string A status array containing the result status information.
  */
 public function store($document, $entities)
 {
     $nEnts = count($entities);
     if ($nEnts <= 0 && $nEnts >= 10000) {
         // We will have problems processing empty files or more than 10,000 entities
         return ['error' => 'Unable to process files with more than 10,000 lines: ' . $nEnts . 'found'];
     }
     $activity = new Activity();
     $activity->softwareAgent_id = $this->softwareComponent->_id;
     $activity->save();
     $format = $document['format'];
     $domain = $document['domain'];
     $docType = $document['documentType'] . '-sentence';
     $title = $document['title'];
     $parentId = $document['_id'];
     $project = $document['project'];
     $activityId = $activity->_id;
     if (Auth::check()) {
         $userId = Auth::user()->_id;
     } else {
         $userId = "crowdwatson";
     }
     $idBase = 'entity/' . $format . '/' . $domain . '/' . $docType . '/';
     $inc = $this->getLastDocumentInc($format, $domain, $docType);
     $fullEntities = [];
     foreach ($entities as $entitiy) {
         $fullEntity = ["_id" => $idBase . $inc, "documentType" => 'unit', "activity_id" => $activityId, "softwareAgent_id" => $this->softwareComponent->_id, "project" => $project, "user_id" => $userId, "type" => $docType, "unitParents" => [$parentId], "jobParents" => [], "children" => [], "judgements" => [], "metrics" => [], "source" => '', "format" => $format, "title" => strtolower($title), "domain" => $domain, "tags" => ['unit'], "content" => $entitiy, "hash" => md5(serialize($entitiy)), "updated_at" => new MongoDate(time()), "created_at" => new MongoDate(time())];
         $inc++;
         array_push($fullEntities, $fullEntity);
     }
     \DB::collection('entities')->insert($fullEntities);
     \MongoDB\Temp::truncate();
     return ['success' => 'Sentences created successfully'];
 }
Пример #3
0
 public function getDeletepl($id)
 {
     $platform = App::make('cf2');
     //dd($id);
     $platform->deleteJobPL($id);
     \MongoDB\Temp::truncate();
     return Redirect::to("jobs");
 }
Пример #4
0
 public function store(&$parentEntity, $relexStructuredSentences, $inc)
 {
     // dd('test');
     $allEntities = array();
     foreach ($relexStructuredSentences as $tKey => &$relexStructuredSentence) {
         $title = $parentEntity['title'] . "_index_" . $inc;
         $hash = md5(serialize(array_except($relexStructuredSentence, ['properties'])));
         if ($dup = Entity::where('hash', $hash)->first()) {
             array_push($this->status['store']['error']['skipped_duplicates'], $tKey . " ---> " . $dup->_id);
             continue;
         }
         if (Auth::check()) {
             $user_id = Auth::user()->_id;
         } else {
             $user_id = "crowdwatson";
         }
         $entity = ["_id" => 'entity/text/medical/relex-structured-sentence/' . $inc, "title" => strtolower($title), "domain" => $parentEntity['domain'], "format" => $parentEntity['format'], "tags" => ['unit'], "documentType" => "relex-structured-sentence", "parents" => [$parentEntity['_id']], "content" => $relexStructuredSentence, "hash" => $hash, "activity_id" => $this->activity->_id, "user_id" => $user_id, "updated_at" => new MongoDate(time()), "created_at" => new MongoDate(time())];
         array_push($allEntities, $entity);
         $inc++;
         array_push($this->status['store']['success'], $tKey . " ---> URI: {$entity['_id']}");
     }
     if (count($allEntities) > 1) {
         \DB::collection('entities')->insert($allEntities);
         \MongoDB\Temp::truncate();
     }
     return $inc;
 }