本文整理汇总了PHP中Entity::addExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::addExtension方法的具体用法?PHP Entity::addExtension怎么用?PHP Entity::addExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::addExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRow
public function processRow($row)
{
$arr = str_getcsv($row);
$ticker = $arr[0];
$name = $arr[1];
$name = str_replace(''', "'", $name);
if ($name == 'Name') {
return false;
}
$cap = $arr[3];
if ($cap < $this->min_market_cap) {
$this->too_small_ct++;
return false;
} else {
$corp = Doctrine::getTable('PublicCompany')->findOneByTicker($ticker);
if ($corp) {
$this->existing_ct++;
return false;
} else {
$corp = new Entity();
$corp->addExtension('Org');
$corp->addExtension('Business');
$corp->addExtension('PublicCompany');
$corp->ticker = $ticker;
$corp->name = $name;
$corp->save();
$this->printDebug("New company added: " . $name);
$this->added_ct++;
}
}
}
示例2: import
public function import($school)
{
if (EntityTable::getByExtensionQuery('Org')->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->instnm) . "%")->fetchOne()) {
$this->printDebug("School exists in database: " . $school->instnm);
} else {
$address = new Address();
$address->street1 = isset($school->addr) ? $school->addr : null;
$address->street2 = isset($school->street2) ? $school->street2 : null;
$address->city = $school->city;
if ($state = AddressStateTable::retrieveByText($school->stabbr)) {
$address->State = $state;
}
$address->postal = $school->zip;
$aliases = explode("|", $school->ialias);
$website = null;
if (!preg_match('/^http\\:\\/\\//i', trim($school->webaddr))) {
$website = "http://" . strtolower($school->webaddr);
}
$this->printDebug($website);
$newschool = new Entity();
$newschool->addExtension('Org');
$newschool->addExtension('School');
$newschool->name = $school->instnm;
$newschool->website = $website;
$newschool->addAddress($address);
$newschool->save();
foreach ($aliases as $alias) {
try {
$newalias = new Alias();
$newalias->Entity = $newschool;
$newalias->name = $alias;
$newalias->save();
} catch (Exception $e) {
$this->printDebug("An alias exception. No biggie. It's most likely that the name already exists. so we ignore it and move on: " . $e);
}
}
$this->printDebug("Adding new school: " . $school->instnm);
}
}
示例3: processRow
//.........这里部分代码省略.........
}
}
if ($matched_bio) {
$person = $s;
break;
} else {
$this->printDebug(' ' . $s->name . ' failed');
}
}
}
$edit['Similar Names'] = array_slice($similar_ids, 0, 5);
$no_match = false;
if (!$person) {
if (isset($row['bio']) && trim($row['bio']) != '') {
$search_person->summary = $row['bio'];
}
$search_person->save();
$this->printDebug(' not found, new person saved: ' . $search_person->name);
$search_person->addReference($this->source_url, null, null, $this->source_name);
$no_match = true;
$edit['New Person'] = $search_person->id;
$person = $search_person;
} else {
if (isset($row['bio']) && trim($row['bio']) != '' && !$person->summary) {
$person->summary = $row['bio'];
$person->save();
}
$this->printDebug(' **person found: ' . $person->name);
$edit['Existing Person'] = $person->id;
}
if ($matched_bio || $no_match) {
$orgs = OrgTable::getOrgsWithSimilarNames($row['affiliation1'], true);
$max = -1;
$affiliated_org = null;
foreach ($orgs as $org) {
$this->printDebug(' found match: ' . $org->name);
$ct = $org->getRelatedEntitiesQuery('Person', RelationshipTable::POSITION_CATEGORY, null, null, null, false, 2)->count();
if ($ct > $max) {
$affiliated_org = $org;
$edit['Existing Org'] = $affiliated_org->id;
$max = $ct;
}
}
if (!$affiliated_org) {
$affiliated_org = new Entity();
$affiliated_org->addExtension('Org');
if (isset($row['affiliation1_extensions']) && $row['affiliation1_extensions'] != '') {
$extensions = explode(',', $row['affiliation1_extensions']);
foreach ($extensions as $ext) {
$ext = trim($ext);
if (in_array($ext, ExtensionDefinitionTable::$extensionNames)) {
$affiliated_org->addExtension($ext);
}
}
} else {
//$affiliated_org->addExtension('Business');
}
$affiliated_org->name = $row['affiliation1'];
$affiliated_org->save();
$affiliated_org->addReference($this->source_url, null, null, $this->source_name);
$edit['New Org'] = $affiliated_org->id;
}
$rel = new Relationship();
$rel->Entity1 = $person;
$rel->Entity2 = $affiliated_org;
$rel->setCategory('Position');
if (isset($row['affiliation1_title']) && $row['affiliation1_title'] != '') {
$description = trim($row['affiliation1_title']);
$rel->description1 = $description;
if ($description == 'Director' || $description == 'Trustee' || preg_match('/^Chair/su', $description)) {
$rel->is_board = 1;
$rel->is_employee = 0;
}
}
$rel->save();
$rel->addReference($this->source_url, null, null, $this->source_name);
$edit['New Relationship'] = $rel->id;
}
if (isset($row['start_date']) && trim($row['start_date']) != '') {
$edit['Relationship']['start_date'] = trim($row['start_date']);
}
if (isset($row['end_date']) && trim($row['end_date']) != '') {
$edit['Relationship']['end_date'] = trim($row['end_date']);
}
if (isset($row['title']) && trim($row['title']) != '') {
$edit['Relationship']['title'] = trim($row['title']);
}
if (isset($row['notes']) && trim($row['notes']) != '') {
$edit['Relationship']['notes'] = trim($row['notes']);
}
if (isset($row['rank']) && $row['rank'] != '') {
$edit['rank'] = $row['rank'];
}
$this->db->commit();
} catch (Exception $e) {
$this->db->rollback();
throw $e;
}
$this->edits[] = $edit;
}
示例4: import
//.........这里部分代码省略.........
} elseif ($this->year > 2004 && preg_match('/<blockquote class="spaced">(.*)<\\/blockquote>/ismU', $text, $match)) {
$summary = str_replace(array(' ', "\n"), array(' ', ' '), html_entity_decode(trim(strip_tags($match[1]))));
}
//get revenue
if ($this->year > 1995 && $this->year < 2000 && preg_match('/<td class="mainlisttxt">\\$([\\S]+) mil<sup>e?<\\/sup><\\/td>/ismU', $text, $match)) {
$this->printDebug($match[1]);
$revenue = str_replace(",", "", $match[1] . ",000,000");
} elseif ($this->year > 1999 && $this->year < 2005 && preg_match('/<td class="mainlisttxt" nowrap>([^<]+)<sup>e?<\\/sup><\\/td>/ismU', $text, $match)) {
$this->printDebug($match[1]);
$revenue = str_replace(",", "", $match[1] . ",000,000");
} elseif ($this->year > 2004 && preg_match('/<td class="highlight" nowrap="nowrap">\\$([\\S]+) bil.*<\\/td> <td class="highlight" nowrap="nowrap">[^<]+<\\/td> <td class="highlight" nowrap="nowrap">([^<]+)<\\/td>/ismU', $text, $match)) {
$revenue = 1000000000 * $match[1];
}
//get employees
if ($this->year > 1995 && $this->year < 2005 && preg_match('/mil<\\/td>.+<td class="mainlisttxt"( nowrap)?>(\\d[^<]+)<\\/td>.+<td class="mainlisttxt">[a-zA-Z]+<\\/td>/ismU', $text, $match)) {
$employees = str_replace(',', '', $match[2]);
} elseif ($this->year > 1999 && $this->year < 2005 && preg_match('/<sup>e?<\\/sup><\\/td> <td class="mainlisttxt"( nowrap)?>(\\d[^<]+)<sup>e?<\\/sup><\\/td> <td class="mainlisttxt">[a-zA-Z]+<\\/td>/ismU', $text, $match)) {
$employees = str_replace(',', '', $match[2]);
} elseif ($this->year > 2004 && preg_match('/<td class="highlight" nowrap="nowrap">([\\d,]+)<\\/td> <td class="highlight" nowrap="nowrap">[A-Z][a-z]{2,}<\\/td>/', $text, $match)) {
$employees = str_replace(',', '', $match[1]);
}
/*$this->printDebug( "URL: ". $url);
$this->printDebug( "Rank: " . $rank );
$this->printDebug( "Name: " . $name );
$this->printDebug( "Industry: " . $industryName );
$this->printDebug( "Street: " . $street1 );
$this->printDebug( "Street2: " . $street2 );
$this->printDebug( "City: " . $city );
$this->printDebug( "State: " . $state );
$this->printDebug( "Postal: " . $postal );
$this->printDebug( "Phone: " . $phone );
$this->printDebug( "Fax: " . $fax );
$this->printDebug( "Website: " . $website );
$this->printDebug( "CEO: " . $ceoName . " " . $ceoBirthYear);
$this->printDebug( "Summary: " . $summary );
$this->printDebug( "Revenue: " . $revenue );
$this->printDebug( "Employees: " . $employees );*/
$search_company_name = trim(implode(' ', array_diff(explode(' ', ucwords(strtolower($name))), array_merge(LsLanguage::$business, LsLanguage::$businessAbbreviations))));
//continue;
$this->printDebug("{$search_company_name} == {$name}");
if ($company = EntityTable::getByExtensionQuery(array('Org', 'PrivateCompany'))->addWhere("LOWER(REPLACE( org.name, '-' , '')) = ?", strtolower($name))->fetchOne()) {
$this->printDebug("Company exists");
$company->revenue = $revenue;
$company->save();
} else {
$this->printDebug("Creating new company {$name}");
Doctrine::getTable('ExtensionDefinition')->clear();
$company = new Entity();
$company->addExtension('Org');
$company->addExtension('Business');
$company->addExtension('PrivateCompany');
$company->name = LsLanguage::titleize($name);
$company->employees = strlen($employees) ? $employees : null;
$company->revenue = strlen($revenue) ? $revenue : null;
$company->website = strlen($website) ? $website : null;
$company->summary = strlen($summary) ? trim($summary) : null;
//add address
if ($phone) {
$company->addPhone($phone);
}
if ($fax) {
//$company->addPhone($fax);
}
if ($city && $state) {
$address = new Address();
$address->street1 = strlen($street1) ? $street1 : null;
$address->street2 = strlen($street2) ? $street2 : null;
$address->city = strlen($city) ? $city : null;
if ($state = AddressStateTable::retrieveByText($state)) {
$address->State = $state;
}
$address->postal = $postal;
$company->addAddress($address);
$address->save();
$address->addReference($source = $url, $excerpt = null, $fields = array('city', 'country_id', 'postal', 'state_id', 'street1'), $name = 'Forbes.com', $detail = null, $date = null);
}
}
/*$this->printDebug( "URL: ". $url);
$this->printDebug( "Rank: " . $rank );
$this->printDebug( "Name: " . $name );
$this->printDebug( "Industry: " . $industryName );
$this->printDebug( "Street: " . $street1 );
$this->printDebug( "Street2: " . $street2 );
$this->printDebug( "City: " . $city );
$this->printDebug( "State: " . $state );
$this->printDebug( "Postal: " . $postal );
$this->printDebug( "Phone: " . $phone );
$this->printDebug( "Fax: " . $fax );
$this->printDebug( "Website: " . $website );
$this->printDebug( "CEO: " . $ceoName . " " . $ceoBirthYear);
$this->printDebug( "Summary: " . $summary );
$this->printDebug( "Revenue: " . $revenue );
$this->printDebug( "Employees: " . $employees );*/
$company->save();
$company->addReference($source = $url, $excerpt = null, $fields = array('website', 'name', 'website', 'summary', 'revenue', 'employees'), $name = 'Forbes.com', $detail = null, $date = null);
$this->saveToList($company, $rank);
} else {
$this->printDebug("Couldn't get company: " . $url);
}
}
示例5: executeAddBulk
//.........这里部分代码省略.........
$extensions_arr[] = $ext->name;
}
$this->matches = array();
if (isset($names) && count($names) > 0) {
for ($i = 0; $i < count($names); $i++) {
if (isset($names[$i]['name']) && trim($names[$i]['name']) != '') {
$name = $names[$i]['name'];
$name_terms = $name;
if ($this->default_type == 'Person') {
$name_parts = preg_split('/\\s+/', $name);
if (count($name_parts) > 1) {
$name_terms = PersonTable::nameSearch($name, true);
}
$terms = $name_terms;
$primary_ext = "Person";
} else {
if ($this->default_type == 'Org') {
$name_terms = OrgTable::nameSearch($name);
$terms = $name_terms;
$primary_ext = "Org";
} else {
$terms = $name_terms;
$primary_ext = null;
}
}
$pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 20, $listIds = null, $aliases = true, $primary_ext);
$match = array('name' => $name);
$match['search_results'] = $pager->execute();
$match['blurb'] = isset($names[$i]['blurb']) ? $names[$i]['blurb'] : null;
$match['rank'] = isset($names[$i]['rank']) ? $names[$i]['rank'] : null;
$match['types'] = array();
if (isset($names[$i]['types'])) {
$types = explode(',', $names[$i]['types']);
$types = array_map('trim', $types);
foreach ($types as $type) {
if (in_array($type, $extensions_arr)) {
$match['types'][] = $type;
}
}
}
$this->matches[] = $match;
}
}
}
}
} else {
if ($request->hasParameter('ref_id')) {
$this->ref_id = $this->getRequestParameter('ref_id');
$entity_ids = array();
$default_type = $this->getRequestParameter('default_type');
for ($i = 0; $i < $this->getRequestParameter('count'); $i++) {
if ($entity_id = $request->getParameter('entity_' . $i)) {
$selected_entity_id = null;
if ($entity_id == 'new') {
$name = $request->getParameter('new_name_' . $i);
if ($default_type == 'Person') {
$new_entity = PersonTable::parseFlatName($name);
} else {
$new_entity = new Entity();
$new_entity->addExtension('Org');
$new_entity->name = trim($name);
}
if ($types = $request->getParameter('new_extensions_' . $i)) {
foreach ($types as $type) {
$new_entity->addExtension($type);
}
}
$new_entity->save();
$new_entity->blurb = $request->getParameter('new_blurb_' . $i);
$ref = Doctrine::getTable('Reference')->find($request->getParameter('ref_id'));
$new_entity->addReference($ref->source, null, null, $ref->name);
$new_entity->save();
$selected_entity_id = $new_entity->id;
} else {
if ($entity_id > 0) {
$selected_entity_id = $entity_id;
}
}
if ($selected_entity_id) {
$q = LsDoctrineQuery::create()->from('LsListEntity le')->where('le.list_id = ? AND le.entity_id = ?', array($this->list['id'], $selected_entity_id));
if (!$q->count()) {
$ls_list_entity = new LsListEntity();
$ls_list_entity->list_id = $this->list->id;
$ls_list_entity->entity_id = $selected_entity_id;
$ls_list_entity->rank = $request->getParameter('entity_' . $i . '_rank');
$ls_list_entity->save();
LsCache::clearEntityCacheById($selected_entity_id);
}
}
}
}
$this->clearCache($this->list);
$this->clearRailsCache($this->list->id);
$this->redirect($this->list->getInternalUrl());
} else {
$request->setError('name', 'The name you entered is invalid');
}
}
}
}
示例6: addGovernmentBodyEntity
private function addGovernmentBodyEntity($name, $fedspending_name, $parent_id = null)
{
$new_gov_body = new Entity();
$new_gov_body->addExtension('Org');
$new_gov_body->addExtension('GovernmentBody');
$new_gov_body->name = $name;
$new_gov_body->is_federal = 1;
if ($parent_id) {
$new_gov_body->parent_id = $parent_id;
}
$new_gov_body->save();
$alias = new Alias();
$alias->context = 'fedspending_government_body';
$alias->name = $fedspending_name;
$alias->entity_id = $new_gov_body->id;
$alias->save();
return $new_gov_body;
}
示例7: import
protected function import($url)
{
$person = null;
$this->printDebug($url);
if (!$this->browser->get($url)->responseIsError()) {
$text = $this->browser->getResponseText();
$bio = null;
$name = null;
$netWorth = null;
$birthYear = null;
$schools = null;
$schools = null;
$imageUrl = null;
$rank = null;
//get name & rank
if ($this->year > 2005 && preg_match('/<b>#(\\d+) ([^<]+)<\\/b>/', $text, $match)) {
$name = trim($match[2]);
$rank = $match[1];
}
if ($this->year == 2005 && preg_match('/<h2>#(\\d+) ([^<]+)<\\/h2>/', $text, $match)) {
$name = trim($match[2]);
$rank = $match[1];
}
//get net worth
if (preg_match('/Net Worth<\\/span> <span class="red">\\$([\\S]+) billion/', $text, $match)) {
$netWorth = $match[1] * 1000000000;
}
//get birth year
if (preg_match('/>Age<\\/span> (\\d+)/', $text, $match)) {
$birthYear = date("Y") - $match[1] . "-00-00";
}
//get schools
if (preg_match('/Education<\\/span>(.*)<\\/td>/isU', $text, $match)) {
$schools = array();
$schoolParts = explode('<br>', $match[1]);
while ($schoolPart = current($schoolParts)) {
if (preg_match('/^([^,]+),\\s+<b>([^<]+)<\\/b>/is', trim($schoolPart), $match)) {
$schoolOrg = trim($match[1]);
if ($schoolOrg == 'High School') {
next($schoolParts);
continue;
}
$schoolDegree = trim($match[2]);
$schools[] = array('org' => $schoolOrg, 'degree' => $schoolDegree);
}
next($schoolParts);
}
}
if (preg_match('#<br>[\\n\\s]<br>(.+?)<br>[\\n\\s]<br>[\\n\\s]<img#isU', $text, $match)) {
$bio = strip_tags(trim($match[1]));
} else {
$wikipedia = new LsWikipedia();
if ($wikipedia->request($name)) {
$bio = $wikipedia->getIntroduction();
}
}
//get image
$regexp = '#([A-Z1-9]{4}).html#';
if (preg_match($regexp, $url, $match)) {
$imageFilename = $match[1] . ".jpg";
$imageUrl = $this->list_urls[$this->year]['img_src'] . $imageFilename;
}
//echo "Rank: " . $rank . "\n";
$this->printDebug("Rank: " . $rank);
$this->printDebug("Name: " . $name);
$this->printDebug("Image: " . $imageUrl);
$this->printDebug("Net worth: " . $netWorth);
$this->printDebug("Birth year: " . $birthYear);
$this->printDebug("Bio: " . $bio);
$person = $this->generatePerson($name, $bio);
$person_exists = $this->getBusinessPersonQuery()->addWhere("person.name_first = ? AND person.name_last = ?", array($person->name_first, $person->name_last))->fetchOne();
if ($person_exists != false) {
$this->printDebug('Person exists');
$person = $person_exists;
} else {
$this->printDebug('Saving new person');
}
//parse name and create person object
$person->addExtension('BusinessPerson');
$person->start_date = $person->start_date == null ? $birthYear : $person->start_date;
$person->summary = $person->summary == null ? $bio : $person->summary;
$person->net_worth = $person->net_worth == null ? $netWorth : $person->net_worth;
//go through schools person attended
foreach ($schools as $school) {
//does the current school exist?
$current_school = EntityTable::getByExtensionQuery('Org')->addWhere("org.name = ?", $school['org'])->fetchOne();
if ($current_school) {
$this->printDebug(" Found School " . $school['org']);
} else {
//clear cache
Doctrine::getTable('ExtensionDefinition')->clear();
$current_school = new Entity();
$current_school->addExtension('Org');
$current_school->addExtension('School');
$current_school->name = LsLanguage::titleize($school['org']);
$current_school->save();
$current_school->addReference($source = $url, $excerpt = null, $fields = array('name'), $name = 'Forbes.com', $detail = null, $date = null);
$this->printDebug(" Adding new school: " . $school['org']);
}
//if there is no relationship between person and school. connect them!
//.........这里部分代码省略.........
示例8: import
function import(Entity $person, $possible_persons)
{
//loop through the people we found. usually just one.
foreach ($possible_persons as $possible_person) {
$this->printDebug('Query returned ' . count($possible_person) . ' person named ' . $possible_person->name);
//this person does not provide education. we skip
if (count($possible_person->education)) {
$this->printDebug('Education found');
} else {
$this->printDebug('No education history found');
continue;
}
//get employement info for this possible match
$possible_person_bio = $possible_person->summary;
if (count($possible_person->employment_history)) {
foreach ($possible_person->employment_history as $employment) {
$possible_person_bio .= ' ' . $employment->company . " ";
}
$this->printDebug('Employment found');
} else {
$this->printDebug('No employment history found');
continue;
}
//get employment info for the person in our database
$relationship_orgs = $person->getRelatedEntitiesQuery('Org', RelationshipTable::POSITION_CATEGORY, null, null, null, false, 1)->execute();
$person_bio = $person->summary;
foreach ($relationship_orgs as $org) {
$person_bio .= ' ' . $org->name;
}
//lets see how many matches we get
$matches = LsLanguage::getCommonPronouns($person_bio, trim($possible_person_bio), LsLanguage::$business);
if (count($matches)) {
foreach ($possible_person->education as $school) {
$school->institution = mb_convert_encoding($school->institution, 'UTF-8');
$school->institution = preg_replace('//isu', ' ', $school->institution);
$this->printDebug('Looking for the school: ' . $school->institution);
$current_school = EntityTable::findByAlias($school->institution, $context = 'bw_school');
//find school
if ($current_school) {
$this->printDebug('Found school');
} else {
$current_school = EntityTable::getByExtensionQuery(array('Org', 'School'))->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->institution) . "%")->fetchOne();
if (!$current_school) {
$new_school = new Entity();
$new_school->addExtension('Org');
$new_school->addExtension('School');
$new_school->name = $school->institution;
$wikipedia = new LsWikipedia();
$wikipedia->request($school->institution);
if ($wikipedia->execute() && !$wikipedia->isDisambiguation()) {
$info_box = $wikipedia->getInfoBox();
if (isset($info_box['students']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['students']['clean'], $match)) {
$new_school->students = LsNumber::clean($match[1]);
} else {
$student_types = array('undergrad', 'postgrad', 'grad', 'doctoral');
$num_students = 0;
foreach ($student_types as $st) {
if (isset($info_box[$st]) && preg_match('/([\\d\\,]{2,})/isu', $info_box[$st]['clean'], $match)) {
$num_students += LsNumber::clean($match[1]);
}
}
if ($num_students > 0) {
$new_school->students = $num_students;
}
}
if (isset($info_box['faculty']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['faculty']['clean'], $match)) {
$new_school->faculty = LsNumber::clean($match[1]);
}
if (isset($info_box['type'])) {
if (stristr($info_box['type']['clean'], 'public')) {
$new_school->is_private = 0;
} else {
if (stristr($info_box['type']['clean'], 'private')) {
$new_school->is_private = 1;
}
}
}
if (isset($info_box['endowment'])) {
if (preg_match('/(\\$[\\d\\,\\.\\s]+)(million|billion)/isu', $info_box['endowment']['clean'], $match)) {
if (strtolower($match[2]) == 'billion') {
$factor = 1000000000;
} else {
$factor = 1000000;
}
$new_school->endowment = LsNumber::formatDollarAmountAsNumber($match[1], $factor);
}
}
if (isset($info_box['established'])) {
$year = null;
if ($date = LsDate::convertDate($info_box['established']['clean'])) {
$new_school->start_date = $date;
} else {
if (preg_match('/\\b(\\d\\d\\d\\d)\\b/isu', $info_box['established']['clean'], $match)) {
$new_school->start_date = $match[1];
}
}
}
$summary = trim($wikipedia->getIntroduction());
$summary = preg_replace('/\\n\\s*\\n/isu', '', $summary);
if (strlen($summary) > 10) {
//.........这里部分代码省略.........
示例9: parseBioguideName
static function parseBioguideName($str)
{
$entity = new Entity();
$entity->addExtension('Person');
//extract nickname
if (preg_match('/\\(([^(]+)\\)/', $str, $nick)) {
$entity->name_nick = $nick[1];
$str = preg_replace('/\\(.*\\)/U', '', $str);
}
$str = preg_replace('/\\s{2,}/', ' ', $str);
$str = str_replace('.', '', $str);
$parts = explode(',', trim($str));
if (count($parts) > 1) {
$entity->name_last = LsLanguage::nameize(mb_strtolower(trim($parts[0]), mb_detect_encoding(trim($parts[0]))));
$other = explode(' ', trim($parts[1]));
$entity->name_first = trim($other[0]);
if (count($other) > 1) {
$middles = array_slice($other, 1);
$middle = trim(implode($middles, ' '));
$entity->name_middle = $middle;
}
if (count($parts) > 2) {
$suffix = trim($parts[2]);
$entity->name_suffix = $suffix;
}
} else {
return null;
}
return $entity;
}
示例10: parseFlatName
//.........这里部分代码省略.........
$prefixes = self::$nameParsePrefixes;
while ($prefix = current($prefixes)) {
if ($str != ($new = preg_replace('/^' . $prefix . ' /i', '', $str))) {
if (!LsArray::inArrayNoCase($prefix, LsLanguage::$commonPrefixes)) {
$namePrefix .= $prefix . ' ';
}
$str = trim($new);
reset($prefixes);
continue;
}
next($prefixes);
}
$namePrefix = $namePrefix ? trim($namePrefix) : null;
//get suffixes
$suffixes = self::$nameParseSuffixes;
while ($suffix = current($suffixes)) {
if ($str != ($new = preg_replace('/ ' . $suffix . '$/i', '', $str))) {
$nameSuffix = $suffix . ' ' . $nameSuffix;
$str = trim($new);
reset($suffixes);
continue;
}
next($suffixes);
}
$nameSuffix = $nameSuffix ? trim($nameSuffix) : null;
//remove commas left over from suffixes
$str = trim(str_replace(',', '', $str));
//find nickname in quotes
if (preg_match('/["\']([\\S]+)[\'"]/', $str, $nickFound)) {
$nameNick = $nickFound[1] ? $nickFound[1] : $nickFound[2];
$str = trim(preg_replace('/["\']([\\S]+)[\'"]/', '', $str));
}
//condense multiple spaces
$str = preg_replace('/\\s{2,}/', ' ', $str);
//split into parts
$parts = explode(' ', $str);
switch (count($parts)) {
case 1:
if ($namePrefix) {
$nameFirst = $namePrefix;
$nameLast = $parts[0];
$namePrefix = null;
} else {
if ($nameSuffix) {
$nameFirst = $parts[0];
$nameLast = $nameSuffix;
$nameSuffix = null;
} else {
if (strtolower($sub) == strtolower($parts[0])) {
$nameLast = $parts[0];
} else {
$nameFirst = $parts[0];
}
}
}
break;
case 2:
$nameFirst = $parts[0];
$nameLast = $parts[1];
break;
case 3:
$nameFirst = $parts[0];
$nameMiddle = $parts[1];
$nameLast = $parts[2];
break;
default:
$nameFirst = $parts[0];
$nameLast = $parts[count($parts) - 1];
for ($n = 1; $n < count($parts) - 1; $n++) {
$nameMiddle .= $parts[$n] . ' ';
}
$nameMiddle = trim($nameMiddle);
break;
}
$nameLast = str_replace('_', ' ', $nameLast);
$name = array('name_first' => $nameFirst, 'name_last' => $nameLast, 'name_middle' => $nameMiddle, 'name_prefix' => $namePrefix, 'name_suffix' => $nameSuffix, 'name_nick' => $nameNick);
foreach ($name as $nk => &$nv) {
if ($nv && $nk != 'name_suffix' && $nk != 'name_prefix') {
$nv = preg_replace('/^(\\P{L})+|(\\P{L})+$/u', '', $nv);
$case = LsString::checkCase($nv);
$nv = $case == 'upper' || $case == 'lower' ? LsLanguage::nameize($nv) : $nv;
if ($nk != 'name_last') {
$nv = LsLanguage::hgCaser($nv, false);
}
}
}
unset($nv);
if ($returnArray) {
return $name;
}
$person = new Entity();
$person->addExtension('Person');
$person->name_first = $name['name_first'];
$person->name_middle = $name['name_middle'];
$person->name_last = $name['name_last'];
$person->name_nick = $name['name_nick'];
$person->name_prefix = $name['name_prefix'];
$person->name_suffix = $name['name_suffix'];
return $person;
}
示例11: mergePeople
private function mergePeople($proxyPerson, $formPerson)
{
$formPerson->name_first;
$formPerson->name_last;
$person = new Entity();
$person->addExtension('Person');
$person->name_first = $formPerson->name_first;
$person->name_middle = $formPerson->name_middle;
$person->name_last = $formPerson->name_last;
$person->name_nick = $formPerson->name_nick;
$person->name_prefix = $formPerson->name_prefix;
$person->name_suffix = $formPerson->name_suffix;
$compatible = false;
if (!$proxyPerson->name_first or $proxyPerson->name_first == '') {
return $person;
}
//check first name compatibility before doing anything
if (stripos($proxyPerson->name_first, $formPerson->name_first) === 0 || stripos($formPerson->name_first, $proxyPerson->name_first) === 0) {
if ($formPerson->name_middle == null || $formPerson->name_middle == '') {
$compatible = true;
$person->name_middle = $proxyPerson->name_middle;
if (strlen($proxyPerson->name_first) > strlen($formPerson->name_first)) {
$person->name_first = $proxyPerson->name_first;
}
} else {
if (!$proxyPerson->name_middle || $proxyPerson->name_middle == '') {
$compatible = true;
if (strlen($proxyPerson->name_first) > strlen($formPerson->name_first)) {
$person->name_first = $proxyPerson->name_first;
}
} else {
if (stripos($proxyPerson->name_middle, $formPerson->name_middle) === 0 || stripos($formPerson->name_middle, $proxyPerson->name_middle) === 0) {
$compatible = true;
if (strlen($proxyPerson->name_middle) > strlen($formPerson->name_middle)) {
$person->name_middle = $proxyPerson->name_middle;
}
if (strlen($proxyPerson->name_first) > strlen($formPerson->name_first)) {
$person->name_first = $proxyPerson->name_first;
}
}
}
}
}
//if names have proven compatible, then check generational suffixes (Jr, Sr etc)
if ($compatible == true) {
$form_suffixes = explode(' ', $formPerson->name_suffix);
$form_generationals = array_intersect($form_suffixes, LsLanguage::$generationalSuffixes);
$proxy_suffixes = explode(' ', $proxyPerson->name_suffix);
$common_generationals = array_intersect($form_generationals, $proxy_suffixes);
//if there are no generationals in the form 4 name, go ahead and grab prefixes, suffixes, etc from proxy name
if (count($form_generationals) == 0 || ($form_generationals = $common_generationals)) {
if (strlen($proxyPerson->name_nick) > strlen($formPerson->name_nick)) {
$person->name_nick = $proxyPerson->name_nick;
}
if (strlen($proxyPerson->name_prefix) > strlen($formPerson->name_prefix)) {
$person->name_prefix = $proxyPerson->name_prefix;
}
if (strlen($proxyPerson->name_suffix) > strlen($formPerson->name_suffix)) {
$person->name_suffix = $proxyPerson->name_suffix;
}
}
}
return $person;
}
示例12: processRow
public function processRow($row)
{
if (isset($row['url']) && $row['url'] != '' && isset($row['url_name']) && $row['url_name'] != '') {
$url = $row['url'];
$url_name = $row['url_name'];
} else {
$url = $this->url;
$url_name = $this->url_name;
}
foreach ($row as &$r) {
trim($r);
}
unset($r);
if ($this->entity) {
$required = array('entity_name', 'primary_type', 'relationship_category');
} else {
$required = array('entity_name', 'primary_type');
}
foreach ($required as $req) {
if (!isset($row[$req]) || $row[$req] == '') {
$this->printDebug('!!! > skipping row, ' . $req . ' not set');
return;
}
}
if ($row['primary_type'] != 'Person' && $row['primary_type'] != 'Org') {
$this->printDebug('!!! > primary type not properly set, skipping row...');
return;
}
if ($this->entity) {
$relationship_category = trim($row['relationship_category']);
$relationship_category_id = array_search($relationship_category, RelationshipCategoryTable::$categoryNames);
if (!$relationship_category_id) {
$this->printDebug('!!! > relationship type not properly set, skipping row...');
return;
}
}
$this->printDebug("processing: " . $row['entity_name'] . '......');
if ($row['primary_type'] == 'Person') {
$entity2 = PersonTable::parseFlatName($row['entity_name']);
$similar_entities = PersonTable::getSimilarQuery2($entity2)->execute();
} else {
$entity2 = new Entity();
$entity2->addExtension('Org');
$entity2->setEntityField('name', $row['entity_name']);
$similar_entities = OrgTable::getOrgsWithSimilarNames($entity2->name);
}
$matched = false;
foreach ($similar_entities as $similar_entity) {
if ($similar_entity['primary_ext'] == 'Person') {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Orgs :: ' . $similar_entity->getRelatedOrgsSummary() . " Bio :: {$similar_entity->summary})");
} else {
$this->printDebug(' POSSIBLE MATCH: ' . $similar_entity->name . ' (Summary :: ' . $similar_entity->summary . ')');
}
$accept = $this->readline(' Is this the same entity? (y or n or b to break)');
if ($accept == 'y') {
$entity2 = $similar_entity;
$matched = true;
$this->printDebug(' [accepted]');
break;
} else {
if ($accept == 'b') {
break;
}
}
}
$created = false;
if (!$matched) {
if ($entity2->getPrimaryExtension() == 'Person') {
$this->printDebug(' New person: ' . $entity2->name_first . ' ' . $entity2->name_last);
} else {
$this->printDebug(' New org: ' . $entity2->name);
}
$accept = $this->readline(' create this new entity? (y or n) ');
if ($accept == 'y') {
try {
$extensions = LsString::split($row['entity_extensions'], '\\s*\\,\\s*');
foreach ($extensions as $extension) {
$entity2->addExtension($extension);
}
$entity2->save();
$entity2->addReference($url, null, null, $url_name);
} catch (Exception $e) {
$this->printDebug(' !!! problems with extensions for this row');
}
$fields = array('summary', 'blurb', 'website');
foreach ($fields as $field) {
if (isset($row[$field])) {
$entity2[$field] = $row[$field];
}
}
$entity2->save();
$entity2->addReference($url, null, null, $url_name);
$created = true;
$this->printDebug(' ' . $entity2->name . ' saved');
//sleep(1);
} else {
$entity2 = null;
}
}
// create relationship
//.........这里部分代码省略.........
示例13: generatePerson
protected function generatePerson($name_str, $summary = null, $orgs = null)
{
$name_arr = LsLanguage::parseFlatName($name_str);
extract($name_arr);
$person = new Entity();
$person->addExtension('Person');
$person->name_prefix = $name_prefix;
$person->name_first = $name_first;
$person->name_middle = $name_middle;
$person->name_last = $name_last;
$person->name_suffix = $name_suffix;
$person->name_nick = $name_nick;
return $person;
}
示例14: createCampaignCommittee
protected function createCampaignCommittee($entityId, $recipientId)
{
$sql = 'SELECT cycle, name, committee_id FROM os_committee WHERE recipient_id = ? AND committee_id <> recipient_id AND name IS NOT NULL';
$stmt = $this->rawDb->execute($sql, array($recipientId));
/*
if (!count($committees = $stmt->fetchAll(PDO::FETCH_ASSOC)))
{
$sql = 'SELECT fec_id FROM os_candidate WHERE candidate_id = ?';
$stmt = $this->rawDb->execute($sql, array($recipientId));
if (count($fecIds = $stmt->fetchAll(PDO::FETCH_COLUMN)))
{
$sql = 'SELECT name, committee_id FROM os_committee WHERE candidate_id IN (\'' . implode('\',\'', $fecIds) . '\')';
$stmt = $this->rawDb->execute($sql);
$committees = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
*/
$committees = array();
//group committees by committee_id, and get most recent name
foreach ($stmt->fetchAll(PDO::FETCH_NUM) as $row) {
list($cycle, $name, $committeeId) = $row;
if (isset($committees[$committeeId])) {
if ($cycle > $committees[$committeeId]['cycle']) {
$committees[$committeeId]['cycle'] = $cycle;
$committees[$committeeId]['name'] = $name;
}
$committees[$committeeId]['aliases'][] = $name;
} else {
$committees[$committeeId] = array('cycle' => $cycle, 'name' => $name, 'aliases' => array());
}
}
foreach ($committees as $committeeId => $ary) {
$name = $ary['name'];
$aliases = array_unique($ary['aliases']);
$sql = 'SELECT e.* FROM entity e LEFT JOIN political_fundraising p ON (p.entity_id = e.id) ' . 'WHERE p.fec_id = ? AND e.is_deleted = 0';
$stmt = $this->db->execute($sql, array($committeeId));
if ($entity = $stmt->fetch(PDO::FETCH_ASSOC)) {
//check for an existing relationship
$sql = 'SELECT COUNT(*) FROM relationship r ' . 'WHERE r.entity1_id = ? AND r.entity2_id = ? AND r.category_id = ? AND r.is_deleted = 0';
$stmt = $this->db->execute($sql, array($entityId, $entity['id'], RelationshipTable::POSITION_CATEGORY));
$createRel = $stmt->fetch(PDO::FETCH_COLUMN) ? false : true;
} else {
Doctrine_Manager::getInstance()->setCurrentConnection('main');
//create new entity and relationship
$entity = new Entity();
$entity->addExtension('Org');
$entity->addExtension('PoliticalFundraising');
$entity->name = $name;
$entity->fec_id = $committeeId;
$entity->save();
if ($this->debugMode) {
print "+ Created new entity for " . $name . " (" . $committeeId . ")\n";
}
$createRel = true;
}
if ($createRel) {
Doctrine_Manager::getInstance()->setCurrentConnection('main');
//create relationship
$rel = new Relationship();
$rel->setCategory('Position');
$rel->entity1_id = $entityId;
$rel->entity2_id = $entity['id'];
$rel->description1 = 'Candidate';
$rel->description2 = 'Political Fundraising Committee';
$rel->is_executive = true;
$rel->save();
//create reference for the relationship
$refName = 'FEC.gov - ' . $name;
$refSource = $this->fecCommitteeBaseUrl . $committeeId;
$sql = 'INSERT INTO reference (object_model, object_id, name, source) VALUES (?, ?, ?, ?)';
$params = array('Relationship', $rel->id, $refName, $refSource);
$stmt = $this->db->execute($sql, $params);
if (!$stmt->rowCount()) {
throw new Exception("Couldn't insert Reference (" . implode(', ', $params) . ")");
}
if ($this->debugMode) {
print "+ Created position relationship between candidate (entity " . $entityId . ") and committee (entity " . $entity['id'] . ")\n";
}
}
//create aliases if necessary
$this->addAliasesToEntityById($entity['id'], $aliases);
}
}
示例15: executeToolbarCreate
public function executeToolbarCreate($request)
{
$this->checkToolbarCredentials();
if (!$request->isMethod('post')) {
$this->forward404();
}
$name = $request->getParameter('name');
$ext = $request->getParameter('ext');
$blurb = $request->getParameter('blurb');
$position = $request->getParameter('position');
$listId = $request->getParameter("list_id");
//save list_id to session for further use
//$this->getUser()->setAttribute('list' . $position . '_id', $listId);
if (!$name || !$ext) {
$this->forward404();
}
if ($ext == 'Person') {
$entity = PersonTable::parseFlatName($name);
$entity->name = $name;
if (!$entity->name_last) {
$this->forward404();
}
} else {
$entity = new Entity();
$entity->addExtension('Org');
$entity->name = $name;
}
$entity->blurb = $blurb;
$entity->save();
if ($listId) {
$db = Doctrine_Manager::connection();
$sql = "SELECT COUNT(*) FROM ls_list WHERE id = ? AND is_network = 0 AND is_deleted = 0";
if (!$this->getUser()->hasCredential('admin')) {
$sql .= " AND is_admin = 0";
}
$stmt = $db->execute($sql, array($listId));
$count = $stmt->fetch(PDO::FETCH_COLUMN);
if ($count == "1") {
$sql = "SELECT COUNT(*) FROM ls_list_entity WHERE list_id = ? AND entity_id = ? AND is_deleted = 0";
$stmt = $db->execute($sql, array($listId, $entity->id));
$count = $stmt->fetch(PDO::FETCH_COLUMN);
if ($count == "0") {
$le = new LsListEntity();
$le->list_id = $listId;
$le->entity_id = $entity->id;
$le->save();
}
} else {
//save list_id to session for further use
//$this->getUser()->setAttribute('list' . $position . '_id', null);
}
}
$this->entity = $entity;
$this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
}