PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pkp/classes/citation/parser/parscit/ParscitRawCitationNlmCitationSchemaFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 73 lines | 24 code | 12 blank | 37 comment | 2 complexity | 977611a270f9b5e019334e3af4b2a4c4 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @defgroup citation_parser_parscit
  4. */
  5. /**
  6. * @file classes/citation/parser/parscit/ParscitRawCitationNlmCitationSchemaFilter.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 ParscitRawCitationNlmCitationSchemaFilter
  12. * @ingroup citation_parser_parscit
  13. *
  14. * @brief Parsing filter implementation that uses the Parscit web service.
  15. *
  16. */
  17. // $Id$
  18. import('citation.NlmCitationSchemaFilter');
  19. define('PARSCIT_WEBSERVICE', 'http://aye.comp.nus.edu.sg/parsCit/parsCit.cgi');
  20. class ParscitRawCitationNlmCitationSchemaFilter extends NlmCitationSchemaFilter {
  21. /*
  22. * Constructor
  23. */
  24. function ParscitRawCitationNlmCitationSchemaFilter() {
  25. parent::NlmCitationSchemaFilter();
  26. }
  27. //
  28. // Implement template methods from Filter
  29. //
  30. /**
  31. * @see Filter::supports()
  32. * @param $input mixed
  33. * @param $output mixed
  34. * @return boolean
  35. */
  36. function supports(&$input, &$output) {
  37. return parent::supports($input, $output, true);
  38. }
  39. /**
  40. * @see Filter::process()
  41. * @param $citationString string
  42. * @return MetadataDescription
  43. */
  44. function &process($citationString) {
  45. $nullVar = null;
  46. $queryParams = array(
  47. 'textlines' => $citationString
  48. );
  49. // Parscit web form - the result is (mal-formed) HTML
  50. if (is_null($result = $this->callWebService(PARSCIT_WEBSERVICE, $queryParams, XSL_TRANSFORMER_DOCTYPE_STRING))) return $nullVar;
  51. // Screen-scrape the tagged portion and turn it into XML
  52. $xmlResult = String::regexp_replace('/.*<algorithm[^>]+>(.*)<\/algorithm>.*/s', '\1', html_entity_decode($result));
  53. $xmlResult = String::regexp_replace('/&/', '&amp;', $xmlResult);
  54. // Transform the result into an array of meta-data
  55. if (is_null($metadata = $this->transformWebServiceResults($xmlResult, dirname(__FILE__).DIRECTORY_SEPARATOR.'parscit.xsl'))) return $nullVar;
  56. // Extract a publisher from the place string if possible
  57. $metadata =& $this->fixPublisherNameAndLocation($metadata);
  58. return $this->addMetadataArrayToNlmCitationDescription($metadata);
  59. }
  60. }
  61. ?>