pubmed.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. <?php
  2. /**
  3. * @file
  4. * Tripal Pub PubMed Interface
  5. *
  6. * @defgroup tripal_pub_pubmed PubMed Interface
  7. * @ingroup tripal_pub
  8. */
  9. /**
  10. *
  11. */
  12. function tripal_pub_remote_search_pubmed($search_array, $num_to_retrieve, $pager_id) {
  13. // convert the terms list provicded by the caller into a string with words
  14. // separated by a '+' symbol.
  15. $terms = '';
  16. if ($search_array['search_terms']) {
  17. $terms = '(' . implode("+", preg_split('/\s+/', trim($search_array['search_terms']))) . '[Title/Abstract]) AND ';
  18. }
  19. if ($search_array['author']) {
  20. $terms = "(" . $search_array . "[Author]) AND ";
  21. }
  22. $terms = substr($terms, 0, -4);
  23. $search_array['limit'] = $num_to_retrieve;
  24. // we want to get the list of pubs using the search terms but using a Drupal style pager
  25. $pubs = tripal_pager_callback('tripal_pub_remote_search_pubmed_range',
  26. $num_to_retrieve, $pager_id, 'tripal_pub_remote_search_pubmed_count', $search_array);
  27. return $pubs;
  28. }
  29. /*
  30. * This function is used as the callback function when used with the
  31. * tripal_pager_callback function. This function returns a count of
  32. * the dataset to be paged.
  33. */
  34. function tripal_pub_remote_search_pubmed_count($search_array) {
  35. $terms = $search_array['search_terms'];
  36. $days = $search_array['days'];
  37. $limit = $search_array['limit'];
  38. $results = tripal_pub_remote_search_pubmed_search_init($terms, $limit, $days);
  39. $_SESSION['tripal_pub_pubmed_query'][$terms]['Count'] = $results['Count'];
  40. $_SESSION['tripal_pub_pubmed_query'][$terms]['WebEnv'] = $results['WebEnv'];
  41. $_SESSION['tripal_pub_pubmed_query'][$terms]['QueryKey'] = $results['QueryKey'];
  42. return $results['Count'];
  43. }
  44. /*
  45. * This function is used as the callback function when used with the
  46. * tripal_pager_callback function. This function returns the results
  47. * within the specified range
  48. */
  49. function tripal_pub_remote_search_pubmed_range($search_array, $start = 0, $limit = 10) {
  50. $terms = $search_array['search_terms'];
  51. $days = $search_array['days'];
  52. $limit = $search_array['limit'];
  53. // get the query_key and the web_env from the previous count query.
  54. $query_key = $_SESSION['tripal_pub_pubmed_query'][$terms]['QueryKey'];
  55. $web_env = $_SESSION['tripal_pub_pubmed_query'][$terms]['WebEnv'];
  56. // if this function has been called without calling the count function
  57. // then we need to do the query.
  58. if (!$query_key) {
  59. $results = tripal_pub_remote_search_pubmed_search_init($terms, $limit, $days);
  60. $_SESSION['tripal_pub_pubmed_query']['WebEnv'] = $results['WebEnv'];
  61. $_SESSION['tripal_pub_pubmed_query']['QueryKey'] = $results['QueryKey'];
  62. $query_key = $results['QueryKey'];
  63. $web_env = $results['WebEnv'];
  64. }
  65. // now get the list of PMIDs from the previous search
  66. $pmids_txt = tripal_pub_remote_search_pubmed_fetch($query_key, $web_env, 'uilist', 'text', $start, $limit);
  67. // iterate through each PMID and get the publication record. This requires a new search and new fetch
  68. $pmids = explode("\n", trim($pmids_txt));
  69. $pubs = array();
  70. foreach ($pmids as $pmid) {
  71. // now retrieve the individual record
  72. $pub_xml = tripal_pub_remote_search_pubmed_fetch($query_key, $web_env, 'null', 'xml', 0, 1, array('id' => $pmid));
  73. $pub = tripal_pub_remote_search_pubmed_parse_pubxml($pub_xml);
  74. $pubs[] = $pub;
  75. }
  76. return $pubs;
  77. }
  78. /*
  79. *
  80. */
  81. function tripal_pub_remote_search_pubmed_search_init($terms, $retmax, $days = 0){
  82. // do a search for a single result so that we can establish a history, and get
  83. // the number of records. Once we have the number of records we can retrieve
  84. // those requested in the range.
  85. $query_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=Pubmed&retmax=$retmax&usehistory=y&term=$terms";
  86. if($days) {
  87. $query_url .= "&reldate=$days&datetype=edat";
  88. }
  89. //dpm($query_url);
  90. $rfh = fopen($query_url, "r");
  91. if (!$rfh) {
  92. drupal_set_message('Could not perform Pubmed query. Cannot connect to Entrez.', 'error');
  93. return 0;
  94. }
  95. // retrieve the XML results
  96. $query_xml = '';
  97. while (!feof($rfh)) {
  98. $query_xml .= fread($rfh, 255);
  99. }
  100. fclose($rfh);
  101. //dpm("<pre>$query_xml</pre>");
  102. $xml = new XMLReader();
  103. $xml->xml($query_xml);
  104. // iterate though the child nodes of the <eSearchResult> tag and get the count, history and query_id
  105. $result = array();
  106. while ($xml->read()) {
  107. $element = $xml->name;
  108. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'WebEnv') {
  109. // we've read as much as we need. If we go too much further our counts
  110. // will get messed up by other 'Count' elements. so we're done.
  111. break;
  112. }
  113. if ($xml->nodeType == XMLReader::ELEMENT) {
  114. switch ($element) {
  115. case 'Count':
  116. $xml->read();
  117. $result['Count'] = $xml->value;
  118. break;
  119. case 'WebEnv':
  120. $xml->read();
  121. $result['WebEnv'] = $xml->value;
  122. break;
  123. case 'QueryKey':
  124. $xml->read();
  125. $result['QueryKey'] = $xml->value;
  126. break;
  127. }
  128. }
  129. }
  130. return $result;
  131. }
  132. /*
  133. *
  134. */
  135. function tripal_pub_remote_search_pubmed_fetch($query_key, $web_env, $rettype = 'null',
  136. $retmod = 'null', $start = 0, $limit = 10, $args = array()){
  137. // repeat the search performed previously (using WebEnv & QueryKey) to retrieve
  138. // the PMID's within the range specied. The PMIDs will be returned as a text list
  139. $fetch_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?rettype=$rettype&retmode=$retmod&retstart=$start&retmax=$limit&db=Pubmed&query_key=$query_key&WebEnv=$web_env";
  140. //dpm($fetch_url);
  141. foreach ($args as $key => $value) {
  142. if(is_array($value)) {
  143. $fetch_url .= "&$key=";
  144. foreach ($value as $item) {
  145. $fetch_url .= "$item,";
  146. }
  147. $fetch_url = substr($fetch_url, 0, -1); // remove trailing comma
  148. }
  149. else {
  150. $fetch_url .= "&$key=$value";
  151. }
  152. }
  153. $rfh = fopen($fetch_url, "r");
  154. if (!$rfh) {
  155. drupal_set_message('Could not perform Pubmed query. Cannot connect to Entrez.', 'error');
  156. return '';
  157. }
  158. $results = '';
  159. if($rfh) {
  160. while (!feof($rfh)) {
  161. $results .= fread($rfh, 255);
  162. }
  163. fclose($rfh);
  164. }
  165. return $results;
  166. }
  167. /*
  168. * This function parses the XML containing details of a publication and
  169. * converts it into an associative array of where keys are Tripal Pub
  170. * ontology terms and the values are extracted from the XML. The
  171. * XML should contain only a single publication record.
  172. *
  173. * Information about the valid elements in the PubMed XML can be found here:
  174. * http://www.nlm.nih.gov/bsd/licensee/elements_descriptions.html
  175. *
  176. * Information about PubMed's citation format can be found here
  177. * http://www.nlm.nih.gov/bsd/policy/cit_format.html
  178. */
  179. function tripal_pub_remote_search_pubmed_parse_pubxml($pub_xml) {
  180. $pub = array();
  181. if (!$pub_xml) {
  182. return $pub;
  183. }
  184. // read the XML and iterate through it.
  185. $xml = new XMLReader();
  186. $xml->xml($pub_xml);
  187. while ($xml->read()) {
  188. $element = $xml->name;
  189. if ($xml->nodeType == XMLReader::ELEMENT) {
  190. switch ($element) {
  191. case 'PMID':
  192. $xml->read(); // get the value for this element
  193. $pub['pub_accession'] = $xml->value;
  194. $pub['pub_database'] = 'PMID';
  195. break;
  196. case 'Article':
  197. $pub_model = $xml->getAttribute('PubModel');
  198. $pub['publication_model'] = $pub_model;
  199. tripal_pub_remote_search_pubmed_parse_article($xml, $pub);
  200. break;
  201. case 'MedlineJournalInfo':
  202. tripal_pub_remote_search_pubmed_parse_medline_journal_info($xml, $pub);
  203. break;
  204. case 'ChemicalList':
  205. // TODO: handle this
  206. break;
  207. case 'SupplMeshList':
  208. // TODO: meant for protocol list
  209. break;
  210. case 'CitationSubset':
  211. // TODO: not sure this is needed.
  212. break;
  213. case 'CommentsCorrections':
  214. // TODO: handle this
  215. break;
  216. case 'GeneSymbolList':
  217. // TODO: handle this
  218. break;
  219. case 'MeshHeadingList':
  220. // TODO: Medical subject headings
  221. break;
  222. case 'NumberOfReferences':
  223. // TODO: not sure we should keep this as it changes frequently.
  224. break;
  225. case 'PersonalNameSubjectList':
  226. // TODO: for works about an individual or with biographical note/obituary.
  227. break;
  228. case 'OtherID':
  229. // TODO: ID's from another NLM partner.
  230. break;
  231. case 'OtherAbstract':
  232. // TODO: when the journal does not contain an abstract for the publication.
  233. break;
  234. case 'KeywordList':
  235. // TODO: handle this
  236. break;
  237. case 'InvestigatorList':
  238. // TODO: personal names of individuals who are not authors (can be used with collection)
  239. break;
  240. case 'GeneralNote':
  241. // TODO: handle this
  242. break;
  243. case 'DeleteCitation':
  244. // TODO: need to know how to handle this
  245. break;
  246. default:
  247. break;
  248. }
  249. }
  250. }
  251. $pub['citation'] = $pub['author_list'] .
  252. '. <a href="http://www.ncbi.nlm.nih.gov/pubmed/' . $pub['pub_accession'] . '" target="_blank">' . $pub['title'] . '</a> ' .
  253. $pub['journal_iso_abbreviation']. '. ' . $pub['publication_date'];
  254. if ($pub['volume'] or $pub['issue']) {
  255. $pub['citation'] .= '; ';
  256. }
  257. if ($pub['volume']) {
  258. $pub['citation'] .= $pub['volume'];
  259. }
  260. if ($pub['issue']) {
  261. $pub['citation'] .= '(' . $pub['issue'] . ')';
  262. }
  263. if ($pub['pages']) {
  264. $pub['citation'] .= ':' . $pub['pages'];
  265. }
  266. $pub['citation'] .= '. PubMed PMID: ' . $pub['pub_accession'];
  267. $pub['xml'] = $pub_xml;
  268. return $pub;
  269. }
  270. /*
  271. *
  272. */
  273. function tripal_pub_remote_search_pubmed_parse_medline_journal_info($xml, &$pub) {
  274. while ($xml->read()) {
  275. // get this element name
  276. $element = $xml->name;
  277. // if we're at the </Article> element then we're done with the article...
  278. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'MedlineJournalInfo') {
  279. return;
  280. }
  281. if ($xml->nodeType == XMLReader::ELEMENT) {
  282. switch ($element) {
  283. case 'Country':
  284. // the place of publication of the journal
  285. $xml->read();
  286. $pub['journal_country'] = $xml->value;
  287. break;
  288. case 'MedlineTA':
  289. // TODO: not sure how this is different from ISOAbbreviation
  290. break;
  291. case 'NlmUniqueID':
  292. // TODO: the journal's unique ID in medline
  293. break;
  294. case 'ISSNLinking':
  295. // TODO: not sure how this is different from ISSN
  296. break;
  297. default:
  298. break;
  299. }
  300. }
  301. }
  302. }
  303. /*
  304. *
  305. */
  306. function tripal_pub_remote_search_pubmed_parse_article($xml, &$pub) {
  307. while ($xml->read()) {
  308. // get this element name
  309. $element = $xml->name;
  310. // if we're at the </Article> element then we're done with the article...
  311. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Article') {
  312. return;
  313. }
  314. if ($xml->nodeType == XMLReader::ELEMENT) {
  315. switch ($element) {
  316. case 'Journal':
  317. tripal_pub_remote_search_pubmed_parse_journal($xml, $pub);
  318. break;
  319. case 'ArticleTitle':
  320. $xml->read();
  321. $pub['title'] = $xml->value;
  322. break;
  323. case 'Abstract':
  324. tripal_pub_remote_search_pubmed_parse_abstract($xml, $pub);
  325. break;
  326. case 'Pagination':
  327. tripal_pub_remote_search_pubmed_parse_pagination($xml, $pub);
  328. break;
  329. case 'ELocationID':
  330. $type = $xml->getAttribute('EIdType');
  331. $valid = $xml->getAttribute('ValidYN');
  332. $xml->read();
  333. $elocation = $xml->value;
  334. if ($type == 'doi' and $valid == 'Y') {
  335. $pub['DOI'] = $elocation;
  336. }
  337. if ($type == 'pii' and $valid == 'Y') {
  338. $pub['PII'] = $elocation;
  339. }
  340. $pub['elocation'] = $elocation;
  341. break;
  342. case 'Affiliation':
  343. // the affiliation tag at this level is meant solely for the first author
  344. $xml->read();
  345. $pub['authors'][0]['affiliation'] = $xml->value;
  346. break;
  347. case 'AuthorList':
  348. $complete = $xml->getAttribute('CompleteYN');
  349. tripal_pub_remote_search_pubmed_parse_authorlist($xml, $pub);
  350. break;
  351. case 'InvestigatorList':
  352. // TODO: perhaps handle this one day. The investigator list is to list the names of people who
  353. // are members of a collective or corporate group that is an author in the paper.
  354. break;
  355. case 'Language':
  356. $xml->read();
  357. $lang_abbr = $xml->value;
  358. // there may be multiple languages so we store these in an array
  359. $pub['language'][] = tripal_pub_remote_search_get_language($lang_abbr);
  360. $pub['language_abbr'][] = $lang_abbr;
  361. break;
  362. case 'DataBankList':
  363. // TODO: handle this case
  364. break;
  365. case 'GrantList':
  366. // TODO: handle this case
  367. break;
  368. case 'PublicationTypeList':
  369. tripal_pub_remote_search_pubmed_parse_publication_type($xml, $pub);
  370. break;
  371. case 'VernacularTitle':
  372. $xml->read();
  373. $pub['vernacular_title'][] = $xml->value;;
  374. break;
  375. case 'ArticleDate':
  376. // TODO: figure out what to do with this element. We already have the
  377. // published date in the <PubDate> field, but this date should be in numeric
  378. // form and may have more information.
  379. break;
  380. default:
  381. break;
  382. }
  383. }
  384. }
  385. }
  386. /*
  387. * A full list of publication types can be found here:
  388. * http://www.nlm.nih.gov/mesh/pubtypes.html.
  389. *
  390. * The Tripal Pub ontology doesn't yet have terms for all of the
  391. * publication types so we store the value in the 'publication_type' term.
  392. */
  393. function tripal_pub_remote_search_pubmed_parse_publication_type($xml, &$pub) {
  394. while ($xml->read()) {
  395. $element = $xml->name;
  396. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'PublicationTypeList') {
  397. // we've reached the </PublicationTypeList> element so we're done.
  398. return;
  399. }
  400. if ($xml->nodeType == XMLReader::ELEMENT) {
  401. switch ($element) {
  402. case 'PublicationType':
  403. $xml->read();
  404. $pub['publication_type'][] = $xml->value;
  405. break;
  406. default:
  407. break;
  408. }
  409. }
  410. }
  411. }
  412. /*
  413. *
  414. */
  415. function tripal_pub_remote_search_pubmed_parse_abstract($xml, &$pub) {
  416. $abstract = '';
  417. while ($xml->read()) {
  418. $element = $xml->name;
  419. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Abstract') {
  420. // we've reached the </Abstract> element so return
  421. $pub['abstract'] = $abstract;
  422. return;
  423. }
  424. // the abstract text can be just a singe paragraph or be broken into multiple
  425. // abstract texts for structured abstracts. Here we will just combine then
  426. // into a single element in the order that they arrive in HTML format
  427. if ($xml->nodeType == XMLReader::ELEMENT) {
  428. switch ($element) {
  429. case 'AbstractText':
  430. $label = $xml->getAttribute('Label');
  431. $xml->read();
  432. if ($label) {
  433. $pub['structured_abstract_part'][][$label] = $xml->value;
  434. $abstract .= "<p><b>$label</b></br>" . $xml->value . '</p>';
  435. }
  436. else {
  437. $abstract .= '<p>' . $xml->value . '</p>';
  438. }
  439. break;
  440. case 'CopyrightInformation':
  441. $xml->read();
  442. $pub['copyright'] = $xml->value;
  443. break;
  444. default:
  445. break;
  446. }
  447. }
  448. }
  449. }
  450. /*
  451. *
  452. */
  453. function tripal_pub_remote_search_pubmed_parse_pagination($xml, &$pub) {
  454. while ($xml->read()) {
  455. $element = $xml->name;
  456. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Pagination') {
  457. // we've reached the </Pagination> element so we're done.
  458. return;
  459. }
  460. if ($xml->nodeType == XMLReader::ELEMENT) {
  461. switch ($element) {
  462. case 'MedlinePgn':
  463. $xml->read();
  464. if(trim($xml->value)) {
  465. $pub['pages'] = $xml->value;
  466. }
  467. break;
  468. default:
  469. break;
  470. }
  471. }
  472. }
  473. }
  474. /*
  475. *
  476. */
  477. function tripal_pub_remote_search_pubmed_parse_journal($xml, &$pub) {
  478. while ($xml->read()) {
  479. $element = $xml->name;
  480. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'Journal') {
  481. return;
  482. }
  483. if ($xml->nodeType == XMLReader::ELEMENT) {
  484. switch ($element) {
  485. case 'ISSN':
  486. $issn_type = $xml->getAttribute('IssnType');
  487. $xml->read();
  488. $issn = $xml->value;
  489. $pub['ISSN'] = $issn;
  490. if ($issn_type == 'Electronic') {
  491. $pub['eISSN'] = $issn;
  492. }
  493. if ($issn_type == 'Print') {
  494. $pub['pISSN'] = $issn;
  495. }
  496. break;
  497. case 'JournalIssue':
  498. // valid values of cited_medium are 'Internet' and 'Print'
  499. $cited_medium = $xml->getAttribute('CitedMedium');
  500. tripal_pub_remote_search_pubmed_parse_journal_issue($xml, $pub);
  501. break;
  502. case 'Title':
  503. $xml->read();
  504. $pub['journal_name'] = $xml->value;
  505. break;
  506. case 'ISOAbbreviation':
  507. $xml->read();
  508. $pub['journal_iso_abbreviation'] = $xml->value;
  509. break;
  510. default:
  511. break;
  512. }
  513. }
  514. }
  515. }
  516. /*
  517. *
  518. */
  519. function tripal_pub_remote_search_pubmed_parse_journal_issue($xml, &$pub) {
  520. while ($xml->read()) {
  521. $element = $xml->name;
  522. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'JournalIssue'){
  523. // if we're at the </JournalIssue> element then we're done
  524. return;
  525. }
  526. if ($xml->nodeType == XMLReader::ELEMENT) {
  527. switch ($element) {
  528. case 'Volume':
  529. $xml->read();
  530. $pub['volume'] = $xml->value;
  531. break;
  532. case 'Issue':
  533. $xml->read();
  534. $pub['issue'] = $xml->value;
  535. break;
  536. case 'PubDate':
  537. $date = tripal_pub_remote_search_pubmed_parse_date($xml, 'PubDate');
  538. $year = $date['year'];
  539. $month = $date['month'];
  540. $day = $date['day'];
  541. $medline = $date['medline'];
  542. $pub['year'] = $year;
  543. if ($month and $day and $year) {
  544. $pub['publication_date'] = "$year $month $day";
  545. }
  546. elseif ($month and !$day and $year) {
  547. $pub['publication_date'] = "$year $month";
  548. }
  549. elseif (!$month and !$day and $year) {
  550. $pub['publication_date'] = $year;
  551. }
  552. elseif ($medline) {
  553. $pub['publication_date'] = $medline;
  554. }
  555. else {
  556. $pub['publication_date'] = "Date Unknown";
  557. }
  558. break;
  559. default:
  560. break;
  561. }
  562. }
  563. }
  564. }
  565. /*
  566. *
  567. */
  568. function tripal_pub_remote_search_pubmed_parse_date ($xml, $element_name) {
  569. $date = array();
  570. while ($xml->read()) {
  571. $element = $xml->name;
  572. if ($xml->nodeType == XMLReader::END_ELEMENT and $element == $element_name){
  573. // if we're at the </$element_name> then we're done
  574. return $date;
  575. }
  576. if ($xml->nodeType == XMLReader::ELEMENT) {
  577. switch ($element) {
  578. case 'Year':
  579. $xml->read();
  580. $date['year'] = $xml->value;
  581. break;
  582. case 'Month':
  583. $xml->read();
  584. $month =
  585. $date['month'] = $xml->value;
  586. break;
  587. case 'Day':
  588. $xml->read();
  589. $date['day'] = $xml->value;
  590. break;
  591. case 'MedlineDate':
  592. // the medline date is when the date cannot be broken into distinct month day year.
  593. $xml->read();
  594. $date['medline'] = $xml->value;
  595. break;
  596. default:
  597. break;
  598. }
  599. }
  600. }
  601. }
  602. /*
  603. *
  604. */
  605. function tripal_pub_remote_search_pubmed_parse_authorlist($xml, &$pub) {
  606. $num_authors = 0;
  607. while ($xml->read()) {
  608. $element = $xml->name;
  609. if ($xml->nodeType == XMLReader::END_ELEMENT){
  610. // if we're at the </AuthorList> element then we're done with the article...
  611. if($element == 'AuthorList') {
  612. // build the author list before returning
  613. $author_list = '';
  614. foreach ($pub['authors'] as $author) {
  615. if ($author['valid'] == 'N') {
  616. // skip non-valid entries. A non-valid entry should have
  617. // a corresponding corrected entry so we can saftely skip it.
  618. continue;
  619. }
  620. if ($author['collective']) {
  621. $author_list .= $author['collective'] . ', ';
  622. }
  623. else {
  624. $author_list .= $author['surname'] . ' ' . $author['first_initials'] . ', ';
  625. }
  626. }
  627. $author_list = substr($author_list, 0, -2);
  628. $pub['author_list'] = $author_list;
  629. return;
  630. }
  631. // if we're at the end </Author> element then we're done with the author and we can
  632. // start a new one.
  633. if($element == 'Author') {
  634. $num_authors++;
  635. }
  636. }
  637. if ($xml->nodeType == XMLReader::ELEMENT) {
  638. switch ($element) {
  639. case 'Author':
  640. $valid = $xml->getAttribute('ValidYN');
  641. $pub['authors'][$num_authors]['valid'] = $valid;
  642. break;
  643. case 'LastName':
  644. $xml->read();
  645. $pub['authors'][$num_authors]['surname'] = $xml->value;
  646. break;
  647. case 'ForeName':
  648. $xml->read();
  649. $pub['authors'][$num_authors]['given_name'] = $xml->value;
  650. break;
  651. case 'Initials':
  652. $xml->read();
  653. $pub['authors'][$num_authors]['first_initials'] = $xml->value;
  654. break;
  655. case 'Suffix':
  656. $xml->read();
  657. $pub['authors'][$num_authors]['suffix'] = $xml->value;
  658. break;
  659. case 'CollectiveName':
  660. $xml->read();
  661. $pub['authors'][$num_authors]['collective'] = $xml->value;
  662. break;
  663. case 'Identifier':
  664. // according to the specification, this element is not yet used.
  665. break;
  666. default:
  667. break;
  668. }
  669. }
  670. }
  671. }
  672. /*
  673. * Language abbreviations were obtained here:
  674. * http://www.nlm.nih.gov/bsd/language_table.html
  675. */
  676. function tripal_pub_remote_search_get_language($lang_abbr) {
  677. $languages = array(
  678. 'afr' => 'Afrikaans',
  679. 'alb' => 'Albanian',
  680. 'amh' => 'Amharic',
  681. 'ara' => 'Arabic',
  682. 'arm' => 'Armenian',
  683. 'aze' => 'Azerbaijani',
  684. 'ben' => 'Bengali',
  685. 'bos' => 'Bosnian',
  686. 'bul' => 'Bulgarian',
  687. 'cat' => 'Catalan',
  688. 'chi' => 'Chinese',
  689. 'cze' => 'Czech',
  690. 'dan' => 'Danish',
  691. 'dut' => 'Dutch',
  692. 'eng' => 'English',
  693. 'epo' => 'Esperanto',
  694. 'est' => 'Estonian',
  695. 'fin' => 'Finnish',
  696. 'fre' => 'French',
  697. 'geo' => 'Georgian',
  698. 'ger' => 'German',
  699. 'gla' => 'Scottish Gaelic',
  700. 'gre' => 'Greek, Modern',
  701. 'heb' => 'Hebrew',
  702. 'hin' => 'Hindi',
  703. 'hrv' => 'Croatian',
  704. 'hun' => 'Hungarian',
  705. 'ice' => 'Icelandic',
  706. 'ind' => 'Indonesian',
  707. 'ita' => 'Italian',
  708. 'jpn' => 'Japanese',
  709. 'kin' => 'Kinyarwanda',
  710. 'kor' => 'Korean',
  711. 'lat' => 'Latin',
  712. 'lav' => 'Latvian',
  713. 'lit' => 'Lithuanian',
  714. 'mac' => 'Macedonian',
  715. 'mal' => 'Malayalam',
  716. 'mao' => 'Maori',
  717. 'may' => 'Malay',
  718. 'mul' => 'Multiple languages',
  719. 'nor' => 'Norwegian',
  720. 'per' => 'Persian',
  721. 'pol' => 'Polish',
  722. 'por' => 'Portuguese',
  723. 'pus' => 'Pushto',
  724. 'rum' => 'Romanian, Rumanian, Moldovan',
  725. 'rus' => 'Russian',
  726. 'san' => 'Sanskrit',
  727. 'slo' => 'Slovak',
  728. 'slv' => 'Slovenian',
  729. 'spa' => 'Spanish',
  730. 'srp' => 'Serbian',
  731. 'swe' => 'Swedish',
  732. 'tha' => 'Thai',
  733. 'tur' => 'Turkish',
  734. 'ukr' => 'Ukrainian',
  735. 'und' => 'Undetermined',
  736. 'urd' => 'Urdu',
  737. 'vie' => 'Vietnamese',
  738. 'wel' => 'Welsh',
  739. );
  740. return $languages[$lang_abbr];
  741. }