示例#1
0
 public static function getTextEntityNames($text, $entity_types)
 {
     //$ls_names = LsLanguage::getHtmlPersonNames($text);
     //var_dump($ls_names);
     $oc = new LsOpencalais();
     $oc->setParameter(array('contentType' => 'text/txt'));
     $oc->setContent($text);
     $oc->execute();
     $response = $oc->getParsedResponse(array("Person", "Company", "Organization"));
     $names = array();
     if ($entity_types == 'all') {
         $names = array_merge((array) $response['Person'], (array) $response['Company'], (array) $response['Organization']);
     } else {
         if ($entity_types == 'people') {
             $names = array_merge((array) $response['Person']);
         } else {
             if ($entity_types == 'orgs') {
                 $names = array_merge((array) $response['Company'], (array) $response['Organization']);
             }
         }
     }
     return $names;
 }
示例#2
0
 public function executeAddBoard($request)
 {
     $this->checkEntity($request, false, false);
     //FIND NAMES AT REF URL PROVIDED
     $this->reference_form = new ReferenceForm();
     $this->reference_form->setSelectObject($this->entity);
     if ($request->isMethod('post')) {
         $commit = $request->getParameter('commit');
         if ($commit == 'Cancel') {
             $this->redirect(EntityTable::getInternalUrl($this->entity));
         }
         $this->lim = 5;
         // REFERENCE INFO HAS BEEN SUBMITTED, SO GO TO URL AND SCRAPE
         if (!$request->hasParameter('ref_id') && $request->hasParameter('reference')) {
             $this->getUser()->setAttribute('board_names', null);
             $refParams = $request->getParameter('reference');
             $this->reference_form->bind($refParams);
             if ($this->reference_form->isValid()) {
                 if ($this->ref_id = $refParams['existing_source']) {
                     $ref = Doctrine::getTable('Reference')->find($this->ref_id);
                     $url = $ref->source;
                 } else {
                     $ref = new Reference();
                     $ref->object_model = 'Entity';
                     $ref->object_id = $this->entity->id;
                     $ref->source = $refParams['source'];
                     $ref->name = $refParams['name'];
                     $ref->source_detail = $refParams['source_detail'];
                     $ref->publication_date = $refParams['publication_date'];
                     $ref->save();
                     $this->ref_id = $ref->id;
                     $url = $ref->source;
                 }
                 $browser = new sfWebBrowser();
                 //FIND NAMES AT URL USING COMBO OF OPENCALAIS & LS CUSTOM HTML PARSING
                 if (!$browser->get($url)->responseIsError()) {
                     $text = $browser->getResponseText();
                     $ls_names = LsLanguage::getHtmlPersonNames($text);
                     $oc = new LsOpencalais();
                     $oc->setParameter(array('contentType' => 'text/html'));
                     $oc->setContent($text);
                     $oc->execute();
                     $response = $oc->getParsedResponse(array("Person"));
                     $oc_names = (array) $response['Person'];
                     $names = array_merge($oc_names, $ls_names);
                     $names = array_unique($names);
                     sort($names);
                     $this->getUser()->setAttribute('board_names', $names);
                 }
             }
         } else {
             if ($request->hasParameter('ref_id')) {
                 $this->ref_id = $this->getRequestParameter('ref_id');
                 $entity_ids = array();
                 for ($i = 0; $i < $this->lim; $i++) {
                     if ($entity_id = $request->getParameter('entity_' . $i)) {
                         if ($entity_id == 'new') {
                             $name = $request->getParameter('new_name_' . $i);
                             $new_entity = PersonTable::parseFlatName($name);
                             $new_entity->blurb = $request->getParameter('new_blurb_' . $i);
                             if ($name && !$new_entity->name_last) {
                                 $request->setError('name', 'The name you entered is invalid');
                             } else {
                                 $new_entity->save();
                                 $entity_ids[] = $new_entity->id;
                             }
                         } else {
                             if ($entity_id > 0) {
                                 $entity_ids[] = $entity_id;
                             }
                         }
                     }
                 }
                 $this->existing_rels = array();
                 $this->new_rels = array();
                 //CHECK FOR EXISTING RELATIONSHIPS, CREATE NEW IF NONE FOUND
                 foreach ($entity_ids as $entity_id) {
                     $existing_rel = LsDoctrineQuery::create()->from('Relationship r')->leftJoin('r.Position p')->where('r.entity1_id = ? and r.entity2_id = ? and p.is_board = ?', array($entity_id, $this->entity->id, '1'))->fetchOne();
                     if ($existing_rel) {
                         $this->existing_rels[] = $existing_rel;
                     } else {
                         $rel = new Relationship();
                         $rel->entity1_id = $entity_id;
                         $rel->entity2_id = $this->entity->id;
                         $rel->setCategory('Position');
                         $rel->description1 = 'Board Member';
                         $rel->description2 = 'Board Member';
                         $rel->is_board = 1;
                         $rel->is_employee = 0;
                         $rel->saveWithRequiredReference(array('existing_source' => $this->ref_id, 'excerpt' => null, 'source_detail' => null, 'publication_date' => null));
                         $this->new_rels[] = $rel;
                     }
                 }
             }
         }
     } else {
         $this->getUser()->setAttribute('board_names', null);
     }
     // IF BOARD NAMES SESSION VARIABLE NOT NULL, PAGE THROUGH TO CORRECT START
     if ($board_names = $this->getUser()->getAttribute('board_names')) {
         $this->start = $this->getRequestParameter('start');
         $this->matches = array();
         if (count($board_names) > $this->start) {
             for ($i = $this->start; $i < $this->start + $this->lim; $i++) {
                 if (!isset($board_names[$i])) {
                     break;
                 }
                 $name = $board_names[$i];
                 $pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 10, $listIds = null, $aliases = true, $primary_ext = "Person");
                 $this->matches[$name] = $pager->execute();
                 $this->total = $pager->getNumResults();
             }
         }
         $this->total = count($board_names);
         $this->end = count($this->matches) < $this->lim ? $this->start + count($this->matches) : $this->start + $this->lim;
     }
     if ($this->hasRequestParameter('finished')) {
         $this->finished = 1;
     }
 }