/lib/pkp/classes/citation/lookup/crossref/CrossrefNlmCitationSchemaFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs · PHP · 156 lines · 74 code · 26 blank · 56 comment · 7 complexity · 7e6e959903efd0f0bfd8fadb6cf87b37 MD5 · raw file

  1. <?php
  2. /**
  3. * @defgroup citation_lookup_crossref
  4. */
  5. /**
  6. * @file classes/citation/lookup/crossref/CrossrefNlmCitationSchemaFilter.inc.php
  7. *
  8. * Copyright (c) 2000-2012 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class CrossrefNlmCitationSchemaFilter
  12. * @ingroup citation_lookup_crossref
  13. *
  14. * @brief Filter that uses the Crossref web
  15. * service to identify a DOI and corresponding
  16. * meta-data for a given NLM citation.
  17. */
  18. // $Id$
  19. import('citation.NlmCitationSchemaFilter');
  20. define('CROSSREF_WEBSERVICE_URL', 'http://www.crossref.org/openurl/');
  21. class CrossrefNlmCitationSchemaFilter extends NlmCitationSchemaFilter {
  22. /** @var string CrossRef registered access email */
  23. var $_email = '';
  24. /*
  25. * Constructor
  26. * @param $email string
  27. */
  28. function CrossrefNlmCitationSchemaFilter($email) {
  29. assert(!empty($email));
  30. $this->_email = $email;
  31. parent::NlmCitationSchemaFilter(
  32. array(
  33. NLM_PUBLICATION_TYPE_JOURNAL,
  34. NLM_PUBLICATION_TYPE_CONFPROC,
  35. NLM_PUBLICATION_TYPE_BOOK,
  36. NLM_PUBLICATION_TYPE_THESIS
  37. )
  38. );
  39. }
  40. //
  41. // Getters and Setters
  42. //
  43. /**
  44. * Get the access email
  45. * @return string
  46. */
  47. function getEmail() {
  48. return $this->_email;
  49. }
  50. //
  51. // Implement template methods from Filter
  52. //
  53. /**
  54. * @see Filter::process()
  55. * @param $citationDescription MetadataDescription
  56. * @return MetadataDescription
  57. */
  58. function &process(&$citationDescription) {
  59. $nullVar = null;
  60. $searchParams = array(
  61. 'pid' => $this->getEmail(),
  62. 'noredirect' => 'true',
  63. 'format' => 'unixref'
  64. );
  65. $doi = $citationDescription->getStatement('pub-id[@pub-id-type="doi"]');
  66. if (!empty($doi)) {
  67. // Directly look up the DOI with OpenURL 0.1
  68. $searchParams['id'] = 'doi:'.$doi;
  69. } else {
  70. // Use OpenURL meta-data to search for the entry
  71. if (is_null($openUrlMetadata = $this->_prepareOpenUrlSearch($citationDescription))) return $nullVar;
  72. $searchParams += $openUrlMetadata;
  73. }
  74. // Call the CrossRef web service
  75. if (is_null($resultXml =& $this->callWebService(CROSSREF_WEBSERVICE_URL, $searchParams, XSL_TRANSFORMER_DOCTYPE_STRING))) return $nullVar;
  76. // Remove default name spaces from XML as CrossRef doesn't
  77. // set them reliably and element names are unique anyway.
  78. $resultXml = String::regexp_replace('/ xmlns="[^"]+"/', '', $resultXml);
  79. // Transform and process the web service result
  80. if (is_null($metadata =& $this->transformWebServiceResults($resultXml, dirname(__FILE__).DIRECTORY_SEPARATOR.'crossref.xsl'))) return $nullVar;
  81. return $this->addMetadataArrayToNlmCitationDescription($metadata, $citationDescription);
  82. }
  83. //
  84. // Private methods
  85. //
  86. /**
  87. * Prepare a search with the CrossRef OpenURL resolver
  88. * @param $citationDescription MetadataDescription
  89. * @return array an array of search parameters
  90. */
  91. function &_prepareOpenUrlSearch(&$citationDescription) {
  92. $nullVar = null;
  93. // Crosswalk to OpenURL
  94. import('metadata.nlm.NlmCitationSchemaOpenUrlCrosswalkFilter');
  95. $nlmOpenUrlFilter = new NlmCitationSchemaOpenUrlCrosswalkFilter();
  96. if (is_null($openUrlCitation =& $nlmOpenUrlFilter->execute($citationDescription))) return $nullVar;
  97. // Prepare the search
  98. $searchParams = array(
  99. 'url_ver' => 'Z39.88-2004'
  100. );
  101. // Configure the meta-data schema
  102. $openUrlCitationSchema =& $openUrlCitation->getMetadataSchema();
  103. switch(true) {
  104. case is_a($openUrlCitationSchema, 'OpenUrlJournalSchema'):
  105. $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:journal';
  106. break;
  107. case is_a($openUrlCitationSchema, 'OpenUrlBookSchema'):
  108. $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:book';
  109. break;
  110. case is_a($openUrlCitationSchema, 'OpenUrlDissertationSchema'):
  111. $searchParams['rft_val_fmt'] = 'info:ofi/fmt:kev:mtx:dissertation';
  112. break;
  113. default:
  114. assert(false);
  115. }
  116. // Add all OpenURL meta-data to the search parameters
  117. // FIXME: Implement a looping search like for other lookup services.
  118. $searchProperties = array(
  119. 'aufirst', 'aulast', 'btitle', 'jtitle', 'atitle', 'issn',
  120. 'artnum', 'date', 'volume', 'issue', 'spage', 'epage'
  121. );
  122. foreach ($searchProperties as $property) {
  123. if ($openUrlCitation->hasStatement($property)) {
  124. $searchParams['rft.'.$property] = $openUrlCitation->getStatement($property);
  125. }
  126. }
  127. return $searchParams;
  128. }
  129. }
  130. ?>