pubmed.inc 25 KB

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