function searchFromPeopleFinder($nameString, $mysqli_object) { //global $context; //$returnVal = []; //$baseURL = "https://webservices.doit.missouri.edu"; //if(empty($people_list)){ //return $returnVal; //} $qry = "SELECT LastName, FirstName, Department, Title, Email from MOSpacePeople where LastName = ? AND FirstName = ? "; $parser = new HumanNameParser_Parser($nameString); if (!($stmt = $mysqli_object->prepare($qry))) { exit("statement prepared failed: (" . $mysqli_object->errno . ") " . $mysqli_object->error); } $bind_param_last_name = $parser->getLast(); $bind_param_first_name = $parser->getFirst(); if (!$stmt->bind_param("ss", $bind_param_last_name, $bind_param_first_name)) { exit("bind parameter failed: (" . $stmt->errno . ")" . $stmt->error); } if (!$stmt->execute()) { exit("Execute failed: (" . $stmt->errno . ")" . $stmt->error); } $stmt->store_result(); //echo $stmt->num_rows."\n"; if ($stmt->num_rows == 0) { return false; } if ($stmt->num_rows > 0) { $stmt->bind_result($last, $first, $dep, $title, $email); $stmt->fetch(); return array("LastName" => $last, "FirstName" => $first, "Department" => $dep, "Title" => $title, "Email" => $email); } }
public function testSingleName() { $parser = new HumanNameParser_Parser("Björn"); $this->assertEquals("Björn", $parser->getName()->getStr()); $this->assertEquals(null, $parser->getFirst()); $this->assertEquals(null, $parser->getLast()); }
function addMOProperty($unifiedName, $client) { $mysqli = new mysqli(HOSTNAME, USERNAME, PASSWD, DATABASE); if ($mysqli->connect_errno) { die("error: " . $mysqli->connect_error); } $localTable = "MOSpacePeople"; $parser = new HumanNameParser_Parser($unifiedName); $last = $parser->getLast(); $first = $parser->getFirst(); //@Debug //echo "Checking ".$last.", ".$first."....."; $q = "SELECT * from " . $localTable . " where firstname='" . $mysqli->real_escape_string($first) . "' and lastname='" . $mysqli->real_escape_string($last) . "'"; $fromMU = 0; $isProfessor = 0; if ($result = $mysqli->query($q)) { if ($result->num_rows == 1) { //@Debug //echo "found in local database....."; $fromMU = 1; if ($resAssocArray = $result->fetch_assoc()) { if (isset($resAssocArray['Title'])) { $isProfessor = findIfProfessor($resAssocArray['Title']) == 1 ? 1 : 0; //@Debug //if($isProfessor == 1) echo "is a prof\n"; else echo "NOT a prof\n"; } else { $isProfessor = 0; //@Debu //echo "NOT a prof\n"; } } else { die("fetch result from MOSpacePeople failed"); } } else { $peopleFinderURL = "https://webservices.doit.missouri.edu/peoplefinderWS/peoplefinderws.asmx/PeopleFinderXml?firstName=" . urlencode($first) . "&lastname=" . urlencode($last) . "&department=&phoneno=&email="; $url_parser = new URLParser($peopleFinderURL); $retArr = $url_parser->XMLToArray(); if (intval($retArr['@attributes']['found']) == 1) { //@Debug //echo "found in Peoplefinder..."; $fromMU = 1; $title = array_key_exists("Title", $retArr['Person']) && !empty($retArr['Person']['Title']) ? $retArr['Person']['Title'] : ""; $isProfessor = findIfProfessor($title) == 1 ? 1 : 0; //@Debug //if($isProfessor == 1) echo "is a prof\n"; else echo "NOT a prof\n"; } else { $isProfessor = 0; //@Debug //echo "NOT a prof\n"; } } } else { die("query: " . $q . "\nFailed"); } $q_str = "match (u:Person {name: \"" . $unifiedName . "\"}) set u.fromMU = " . $fromMU . ", u.isProfessor = " . $isProfessor; $query = new Query($client, $q_str); $client->executeCypherQuery($query); }
function prepare_doc_for_citeproc(&$doc) { $authors = array(); foreach ($doc['authors'] as $author) { $name = new HumanNameParser_Name($author); $parser = new HumanNameParser_Parser($name); $authors[] = array('given' => $parser->getFirst(), 'family' => $parser->getLast(), 'static-ordering' => false); } foreach (array('year', 'month', 'day') as $item) { if (!$doc[$item]) { $doc[$item] = '01'; } } $doc = array_filter(array('id' => $doc['id'], 'title' => $doc['title'], 'author' => $authors, 'publisher' => $doc['publisher'], 'volume' => $doc['volume'], 'issue' => $doc['issue'], 'page-range' => $doc['pages'], 'issued' => array('date-parts' => array(array($doc['year'], $doc['month'], $doc['day']))), 'type' => 'article')); }
public function setFullname($fullname) { $name = new \HumanNameParser_Parser($fullname); $this->customer->setName(new Name($name->getFirst(), $name->getLast(), $name->getMiddle())); return $this; }
} $client = new Everyman\Neo4j\Client('localhost', 7474); $client->getTransport()->setAuth('neo4j', 'muresearch'); $q = "match (u:Person) return u.name as name"; $query = new Query($client, $q); $result = $query->getResultSet(); $mysqli = new mysqli(HOSTNAME, USERNAME, PASSWD, DATABASE); if ($mysqli->connect_errno) { die("error: " . $mysqli->connect_error); } $localTable = "MOSpacePeople"; $transaction = $client->beginTransaction(); foreach ($result as $r) { $parser = new HumanNameParser_Parser($r['name']); $last = $parser->getLast(); $first = $parser->getFirst(); //@Debug echo "Checking " . $last . ", " . $first . "....."; $q = "SELECT * from " . $localTable . " where firstname='" . $mysqli->real_escape_string($first) . "' and lastname='" . $mysqli->real_escape_string($last) . "'"; $fromMU = 0; $isProfessor = 0; if ($result = $mysqli->query($q)) { if ($result->num_rows == 1) { //@Debug echo "found in local database....."; $fromMU = 1; if ($resAssocArray = $result->fetch_assoc()) { if (isset($resAssocArray['Title'])) { $isProfessor = findIfProfessor($resAssocArray['Title']) == 1 ? 1 : 0; //@Debug if ($isProfessor == 1) {
foreach ($people_array as $p) { if (str_word_count($p) == 1) { continue; } if (strpos("{$p}", ", ") !== false) { $tmp = explode(",", $p); if (in_array(trim($tmp[1]), array("Jr.")) && isset($tmp[2])) { $p = $tmp[0] . ", " . $tmp[2]; } else { $p = implode(",", array_slice($tmp, 0, 2)); } } //$p = implode(",", array_slice(explode(",", $p), 0, 2)); //echo $p."\n"; $parser = new HumanNameParser_Parser($p); $searchURL = "/peoplefinderWS/peoplefinderws.asmx/PeopleFinderXml?firstName=" . urlencode($parser->getFirst()) . "&lastname=" . urlencode($parser->getLast()) . "&department=&phoneno=&email="; $peopleInfoXML = file_get_contents($baseURL . $searchURL, false, $context) or die("The mospace server might failed\n"); //echo $baseURL.$searchURL; $peopleInfoXMLObject = simplexml_load_string($peopleInfoXML, null, LIBXML_NOCDATA); if ($peopleInfoXMLObject['found'] == 0 || $peopleInfoXMLObject['found'] >= 49) { continue; } //echo "<pre>"; ///print_r($peopleInfoXMLObject->Person); //echo "</pre>"; $personObject = new Person(); $personObject->setLastName($parser->getLast()); $personObject->setFirstName($parser->getFirst()); //For test purpose only //echo $personObject->getLastName().", ".$personObject->getFirstName()."; "; $personObject->setDepartment($peopleInfoXMLObject->Person->Department);
public function crawlPubmed() { $search_url = $this->pubmed_search_url . "&term=" . urlencode($this->firstName . " " . $this->lastName . "[Author]" . " AND " . $this->affiliation . "[Affiliation]"); $search_url_parser = new URLParser($search_url); $pubmedSearch_item_array = $search_url_parser->XMLToArray(); $returnVal = array(); if (array_key_exists('Count', $pubmedSearch_item_array) && $pubmedSearch_item_array['Count'] > 0) { if ($pubmedSearch_item_array['Count'] == 1 || $pubmedSearch_item_array['RetMax'] == 1) { $pubmedSearch_item_array['IdList']['Id'] = array($pubmedSearch_item_array['IdList']['Id']); } $pid_url = ""; foreach ($pubmedSearch_item_array['IdList']['Id'] as $ind => $pubid) { $pid_url .= $pubid . ","; } $pid_url = rtrim($pid_url, ","); $fetch_url = $this->pubmed_fetch_url . $pid_url; $fetch_url_parser = new URLParser($fetch_url); $pubmedFetchResultArray = $fetch_url_parser->XMLToArray(); if (!array_key_exists('PubmedArticle', $pubmedFetchResultArray)) { trigger_error("PubmedArticle not set in pubmedFetchResultArray", E_USER_ERROR); return null; } $pubmedFetchResultArray['PubmedArticle'] = isset($pubmedFetchResultArray['PubmedArticle'][0]) ? $pubmedFetchResultArray['PubmedArticle'] : array($pubmedFetchResultArray['PubmedArticle']); foreach ($pubmedFetchResultArray['PubmedArticle'] as $record) { if (!array_key_exists('MedlineCitation', $record)) { trigger_error("MedlineCitation not set in one pubmed record", E_USER_ERROR); continue; } $coauthorList = array(); $title = $record['MedlineCitation']['Article']['ArticleTitle']; $url = 'http://www.ncbi.nlm.nih.gov/pubmed/' . $record['MedlineCitation']['PMID']; if (array_key_exists('AuthorList', $record['MedlineCitation']['Article']) && array_key_exists('Author', $record['MedlineCitation']['Article']['AuthorList']) && !empty($record['MedlineCitation']['Article']['AuthorList'])) { $authorList = $record['MedlineCitation']['Article']['AuthorList']['Author']; } else { trigger_error("authorlist/author not set or author is empty", E_USER_ERROR); continue; } if (!isset($authorList[0])) { continue; } if (count($authorList) > 20) { continue; } foreach ($authorList as $a) { //converting pubmed name to neo4j compatible format $parser = new HumanNameParser_Parser($a['LastName'] . ", " . $a['ForeName']); $first = $parser->getFirst(); $last = $parser->getLast(); if (array_key_exists('AffiliationInfo', $a)) { if (array_key_exists('Affiliation', $a['AffiliationInfo'])) { $affi = $a['AffiliationInfo']['Affiliation']; } else { if (array_key_exists(0, $a['AffiliationInfo']) && array_key_exists('Affiliation', $a['AffiliationInfo'][0])) { $affi = $a['AffiliationInfo'][0]['Affiliation']; } } } else { $affi = ""; } $coauthorList[] = array("firstName" => $first, "lastName" => $last, "affiliation" => $affi); } $returnVal[] = array("title" => $title, "url" => $url, "people" => $coauthorList); } } return $returnVal; }
exit("Binding parameters failed: (" . $stmt->errno . ")" . $stmt->error); } if (!$stmt->execute()) { exit("Execute failed: (" . $stmt->errno . ") " . $stmt->error); } $stmt->store_result(); if ($stmt->num_rows == 0 || $stmt->num_rows >= 2) { exit("Error: id not found or multiple result found"); } $stmt->bind_result($userid, $lastname, $firstname, $middlename, $suffix, $title, $department, $phone, $email, $photoImageURL, $keywordImageURL, $socialKeywordURL, $description); $stmt->fetch(); $registered = 1; } else { if (isset($name)) { $bind_param_last_name = $parser->getLast(); $bind_param_first_name = $parser->getFirst(); $bind_param_middle_name = $parser->getMiddle(); $bind_param_suffix = $parser->getSuffix(); if (!$stmt->bind_param("ssss", $bind_param_last_name, $bind_param_first_name, $bind_param_middle_name, $bind_param_suffix)) { exit("Binding parameters failed: (" . $stmt->errno . ")" . $stmt->error); } if (!$stmt->execute()) { exit("Execute failed: (" . $stmt->errno . ") " . $stmt->error); } $stmt->store_result(); if ($stmt->num_rows == 1) { $stmt->bind_result($theid, $lastname, $firstname, $middlename, $suffix, $title, $department, $phone, $email, $photoImageURL, $keywordImageURL, $socialKeywordURL, $description); $stmt->fetch(); $registered = 1; } else { if ($stmt->num_rows > 1) {
if ($expected === '') { $expected = "[empty]"; } if ($actual === '') { $actual = "[empty]"; } if ($actual === $expected) { $ret = "<span class='win'>{$expected} = {$actual}</span>"; } else { $ret = "<span class='fail'>{$expected} ≠ {$actual}</span>"; } return $ret; } $handle = fopen('./Tests/testNames.txt', 'r'); while ($nameArr = fgetcsv($handle, 1000, "|")) { $parser = new HumanNameParser_Parser($nameArr[0]); // check to see if the parser got each name-part correct $ret = testEqual($nameArr[1], $parser->getleadingInit()); $ret .= testEqual($nameArr[2], $parser->getFirst()); $ret .= testEqual($nameArr[3], $parser->getNicknames()); $ret .= testEqual($nameArr[4], $parser->getMiddle()); $ret .= testEqual($nameArr[5], $parser->getLast()); $ret .= testEqual($nameArr[6], $parser->getSuffix()); $divClass = strpos($ret, "class='fail'") ? "fail" : "win"; // a hacky way to do this echo "<div class='name {$divClass}'><h2 class='test-name'>{$nameArr[0]}</h2>{$ret}</div>"; } ?> </body> </html>