PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

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