Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ParscitRawCitationNlm30CitationSchemaFilter.inc.php
1 <?php
21 import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30CitationSchemaFilter');
22 
23 define('PARSCIT_WEBSERVICE', 'http://aye.comp.nus.edu.sg/parsCit/parsCit.cgi');
24 
26  /*
27  * Constructor
28  * @param $filterGroup FilterGroup
29  */
30  function ParscitRawCitationNlm30CitationSchemaFilter($filterGroup) {
31  $this->setDisplayName('ParsCit');
32 
33  parent::Nlm30CitationSchemaFilter($filterGroup);
34  }
35 
36  //
37  // Implement template methods from PersistableFilter
38  //
42  function getClassName() {
43  return 'lib.pkp.plugins.citationParser.parscit.filter.ParscitRawCitationNlm30CitationSchemaFilter';
44  }
45 
46 
47  //
48  // Implement template methods from Filter
49  //
55  function &process(&$input) {
56  $nullVar = null;
57  $queryParams = array(
58  'demo' => '3',
59  'textlines' => $input
60  );
61 
62  // Parscit web form - the result is (mal-formed) HTML
63  if (is_null($result = $this->callWebService(PARSCIT_WEBSERVICE, $queryParams, XSL_TRANSFORMER_DOCTYPE_STRING, 'POST'))) return $nullVar;
64  $result = html_entity_decode($result);
65 
66  // Detect errors.
67  if (!String::regexp_match('/.*<algorithm[^>]+>.*<\/algorithm>.*/s', $result)) {
68  $translationParams = array('filterName' => $this->getDisplayName());
69  $this->addError(__('submission.citations.filter.webserviceResultTransformationError', $translationParams));
70  return $nullVar;
71  }
72 
73  // Screen-scrape the tagged portion and turn it into XML.
74  $xmlResult = String::regexp_replace('/.*<algorithm[^>]+>(.*)<\/algorithm>.*/s', '\1', $result);
75  $xmlResult = String::regexp_replace('/&/', '&amp;', $xmlResult);
76 
77  // Transform the result into an array of meta-data.
78  if (is_null($metadata = $this->transformWebServiceResults($xmlResult, dirname(__FILE__).DIRECTORY_SEPARATOR.'parscit.xsl'))) return $nullVar;
79 
80  // Extract a publisher from the place string if possible.
81  $metadata =& $this->fixPublisherNameAndLocation($metadata);
82 
83  return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
84  }
85 }
86 ?>
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: String.inc.php:377
setDisplayName($displayName)
Definition: Filter.inc.php:140
static regexp_match($pattern, $subject)
Definition: String.inc.php:339
& transformWebServiceResults(&$xmlResult, $xslFileName)
Parsing filter implementation that uses the Parscit web service.
addError($message)
Definition: Filter.inc.php:265
Abstract base class for all filters that transform NLM citation metadata descriptions.
getDisplayName()
Definition: Filter.inc.php:155
& getNlm30CitationDescriptionFromMetadataArray(&$metadataArray)
& callWebService($url, &$params, $returnType=XSL_TRANSFORMER_DOCTYPE_DOM, $method= 'GET')