diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index 29ec32cf92d6b4e59e931bc2921a7f39319225e3..caa2c43310d8a14959e8252cb4ee5ffd0793d473 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -341,11 +341,6 @@ CallNumber = callnumber-sort ; WorldCatIdentities ; Use the WorldCat Identities API to find names and related subjects based ; on the current search. -; WorldCatTerms:[vocabulary] -; Use the WorldCat Terminologies API to find Library of Congress Subject -; Headings related to the current search. [vocabulary] is the vocabulary to -; use for recommendations; default is "lcsh" but other options include "fast", -; "mesh", etc. See http://tspilot.oclc.org/resources/ for details. ; ; Available modules recommended for use in the "no results" area: ; @@ -385,7 +380,6 @@ Author[] = AuthorFacets Author[] = SpellingSuggestions ;Author[] = WorldCatIdentities CallNumber[] = "TopFacets:ResultsTop" ; disable spelling in this context -;Subject[] = WorldCatTerms [NoResultsRecommendations] CallNumber[] = SwitchQuery::wildcard:truncatechar diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 7ec0151d5db4b738e00c0fd0cb1c8bddc4b099d4..247c4dfbfe8877f84d915da6e79e4bcefcff717a 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -427,7 +427,6 @@ $config = [ 'visualfacets' => 'VuFind\Recommend\Factory::getVisualFacets', 'webresults' => 'VuFind\Recommend\Factory::getWebResults', 'worldcatidentities' => 'VuFind\Recommend\Factory::getWorldCatIdentities', - 'worldcatterms' => 'VuFind\Recommend\Factory::getWorldCatTerms', ], 'invokables' => [ 'alphabrowselink' => 'VuFind\Recommend\AlphaBrowseLink', @@ -443,6 +442,7 @@ $config = [ 'summondatabasesdeferred' => 'VuFind\Recommend\SummonDatabasesDeferred', 'summonresultsdeferred' => 'VuFind\Recommend\SummonResultsDeferred', 'switchtype' => 'VuFind\Recommend\SwitchType', + 'worldcatterms' => 'VuFind\Recommend\Deprecated', ], ], 'recorddriver' => [ diff --git a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php index cc31e0f886f2ca44b304f0da85df48602e0ea8d1..dfec2f27ca57e318d5b6672f2a9a840f995756ca 100644 --- a/module/VuFind/src/VuFind/Connection/WorldCatUtils.php +++ b/module/VuFind/src/VuFind/Connection/WorldCatUtils.php @@ -442,138 +442,4 @@ class WorldCatUtils implements \Zend\Log\LoggerAwareInterface return $output; } - - /** - * Given a subject term, get related (broader/narrower/alternate) terms. - * Loosely adapted from Eric Lease Morgan's Term Finder demo (see - * http://zoia.library.nd.edu/sandbox/term-finder/). Note that this is - * intended as a fairly fuzzy search -- $term need not be an exact subject - * heading; this function will return best guess matches in the 'exact' - * key, possible broader terms in the 'broader' key and possible narrower - * terms in the 'narrower' key of the return array. - * - * @param string $term Term to get related terms for. - * @param string $vocabulary Vocabulary to search (default = LCSH; see OCLC docs - * for other options). - * @param int $maxRecords Max # of records to read from API (more = slower). - * - * @return mixed False on error, otherwise array of related terms, - * keyed by category. - */ - public function getRelatedTerms($term, $vocabulary = 'lcsh', $maxRecords = 10) - { - // Strip quotes from incoming term: - $term = str_replace('"', '', $term); - - // Build the request URL: - $url = "http://tspilot.oclc.org/" . urlencode($vocabulary) . "/?" . - // Search for the user-supplied term in both preferred and alternative - // fields! - "query=oclcts.preferredTerm+%3D+%22" . urlencode($term) . - "%22+OR+oclcts.alternativeTerms+%3D+%22" . urlencode($term) . "%22" . - "&version=1.1" . - "&operation=searchRetrieve" . - "&recordSchema=info%3Asrw%2Fschema%2F1%2Fmarcxml-v1.1" . - "&maximumRecords=" . intval($maxRecords) . - "&startRecord=1" . - "&resultSetTTL=300" . - "&recordPacking=xml" . - "&recordXPath=" . - "&sortKeys=recordcount"; - - // Get the API response: - $data = $this->retrieve($url); - - // Extract plain MARCXML from the WorldCat response: - $marcxml = XSLTProcessor::process('wcterms-marcxml.xsl', $data); - - // Try to parse the MARCXML into a File_MARC object; if this fails, - // we probably have bad MARCXML, which may indicate an API failure - // or an empty record set. Just give up if this happens! - try { - $marc = new \File_MARCXML($marcxml, File_MARCXML::SOURCE_STRING); - } catch (\File_MARC_Exception $e) { - return false; - } - - // Initialize arrays: - $exact = []; - $broader = []; - $narrower = []; - - while ($record = $marc->next()) { - // Get exact terms; only save it if it is not a subset of the requested - // term. - $main = $this->getExactTerm($record); - if ($main && !stristr($term, $main)) { - $exact[] = $main; - } - - // Get broader/narrower terms: - $related = $record->getFields('550'); - foreach ($related as $current) { - $type = $current->getSubfield('w'); - $value = $current->getSubfield('a'); - if ($type && $value) { - $type = (string)$type->getData(); - $value = (string)$value->getData(); - if ($type == 'g') { - // Don't save exact matches to the user-entered term: - if (strcasecmp($term, $value) != 0) { - $broader[] = $value; - } - } else if ($type == 'h') { - // Don't save exact matches to the user-entered term: - if (strcasecmp($term, $value) != 0) { - $narrower[] = $value; - } - } - } - } - } - - // Send back everything we found, sorted and filtered for uniqueness; note - // that we do NOT sort FAST results since they support relevance ranking. - // As of this writing, other vocabularies do not support relevance. - if ($vocabulary !== 'fast') { - natcasesort($exact); - natcasesort($broader); - natcasesort($narrower); - } - return [ - 'exact' => array_unique($exact), - 'broader' => array_unique($broader), - 'narrower' => array_unique($narrower) - ]; - } - - /** - * Extract an exact term from a MARC record. - * - * @param \File_MARC_Record $record MARC record - * - * @return string - */ - protected function getExactTerm($record) - { - // Get exact terms: - $actual = $record->getField('150'); - if (!$actual || !($main = $actual->getSubfield('a'))) { - return false; - } - - // Some versions of File_MARCXML seem to have trouble returning - // strings properly (giving back XML objects instead); let's - // cast to string to be sure we get what we expect! - $main = (string)$main->getData(); - - // Add subdivisions: - $subdivisions = $actual->getSubfields('x'); - if ($subdivisions) { - foreach ($subdivisions as $current) { - $main .= ', ' . (string)$current->getData(); - } - } - return $main; - } } diff --git a/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php b/module/VuFind/src/VuFind/Recommend/Deprecated.php similarity index 53% rename from module/VuFind/src/VuFind/Recommend/WorldCatTerms.php rename to module/VuFind/src/VuFind/Recommend/Deprecated.php index 556adda3a1fa67d6920830a9dcc23505d7d7ef48..6118aa9ae44c911546ef8bacb0c53c89b3be8566 100644 --- a/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php +++ b/module/VuFind/src/VuFind/Recommend/Deprecated.php @@ -1,10 +1,11 @@ <?php /** - * WorldCatTerms Recommendations Module + * Deprecated Recommendations Module - used to replace legacy modules that no + * longer function due to, for example, external APIs that have been shut down. * * PHP version 5 * - * Copyright (C) Villanova University 2010. + * Copyright (C) Villanova University 2015. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -26,13 +27,10 @@ * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki */ namespace VuFind\Recommend; -use VuFind\Connection\WorldCatUtils; -use VuFindSearch\Query\Query; /** - * WorldCatTerms Recommendations Module - * - * This class provides recommendations by using the WorldCat Terminologies API. + * Deprecated Recommendations Module - used to replace legacy modules that no + * longer function due to, for example, external APIs that have been shut down. * * @category VuFind2 * @package Recommendations @@ -40,39 +38,8 @@ use VuFindSearch\Query\Query; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki */ -class WorldCatTerms implements RecommendInterface +class Deprecated implements RecommendInterface { - /** - * Search results object - * - * @var \VuFind\Search\Base\Results - */ - protected $searchObject; - - /** - * Vocabulary to use. - * - * @var string - */ - protected $vocab = 'lcsh'; - - /** - * WorldCat utilities wrapper object. - * - * @var WorldCatUtils - */ - protected $worldCatUtils; - - /** - * Constructor - * - * @param WorldCatUtils $wcu WorldCat utilities object - */ - public function __construct(WorldCatUtils $wcu) - { - $this->worldCatUtils = $wcu; - } - /** * Store the configuration of the recommendation module. * @@ -82,9 +49,6 @@ class WorldCatTerms implements RecommendInterface */ public function setConfig($settings) { - // Pick a vocabulary (either user-specified, or LCSH by default): - $params = trim($settings); - $this->vocab = empty($params) ? 'lcsh' : $params; } /** @@ -101,7 +65,6 @@ class WorldCatTerms implements RecommendInterface */ public function init($params, $request) { - // No action needed. } /** @@ -115,34 +78,5 @@ class WorldCatTerms implements RecommendInterface */ public function process($results) { - $this->searchObject = $results; - } - - /** - * Get terms related to the query. - * - * @return array - */ - public function getTerms() - { - // Extract the first search term from the search object: - $search = $this->searchObject->getParams()->getQuery(); - $lookfor = ($search instanceof Query) ? $search->getString() : ''; - - // Get terminology information: - $terms = $this->worldCatUtils->getRelatedTerms($lookfor, $this->vocab); - - // Wipe out any empty or unexpected sections of the related terms array; - // this will make it easier to only display content in the template if - // we have something worth displaying. - if (is_array($terms)) { - $desiredKeys = ['exact', 'broader', 'narrower']; - foreach ($terms as $key => $value) { - if (empty($value) || !in_array($key, $desiredKeys)) { - unset($terms[$key]); - } - } - } - return $terms; } -} \ No newline at end of file +} diff --git a/module/VuFind/src/VuFind/Recommend/Factory.php b/module/VuFind/src/VuFind/Recommend/Factory.php index 6f3d9bb934e2070e248af09da0cf5333c140b709..f3ec771b4e352453179ecb572da5e30b0b52aff1 100644 --- a/module/VuFind/src/VuFind/Recommend/Factory.php +++ b/module/VuFind/src/VuFind/Recommend/Factory.php @@ -335,18 +335,4 @@ class Factory $sm->getServiceLocator()->get('VuFind\WorldCatUtils') ); } - - /** - * Factory for WorldCatTerms module. - * - * @param ServiceManager $sm Service manager. - * - * @return WorldCatTerms - */ - public static function getWorldCatTerms(ServiceManager $sm) - { - return new WorldCatTerms( - $sm->getServiceLocator()->get('VuFind\WorldCatUtils') - ); - } } \ No newline at end of file diff --git a/module/VuFind/tests/fixtures/worldcat/terms b/module/VuFind/tests/fixtures/worldcat/terms deleted file mode 100644 index 252638e28d89501f5e213fc5e231d588e2fabf50..0000000000000000000000000000000000000000 Binary files a/module/VuFind/tests/fixtures/worldcat/terms and /dev/null differ diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Connection/WorldCatUtilsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Connection/WorldCatUtilsTest.php index c078496d75fd14115fe6da6a5a7f285fc90fd9d1..429795338877c29fcd4a4bd1d5e0ad760cc9f214 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Connection/WorldCatUtilsTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Connection/WorldCatUtilsTest.php @@ -111,21 +111,6 @@ class WorldCatUtilsTest extends \PHPUnit_Framework_TestCase $this->assertFalse($client->getRelatedIdentities('')); } - /** - * Test related terminology - * - * @return void - */ - public function testGetRelatedTerms() - { - $client = $this->getClient('terms'); - $terms = $client->getRelatedTerms('hogs'); - $this->assertEquals(4, count($terms['exact'])); - $this->assertEquals(7, count($terms['broader'])); - $this->assertEquals(4, count($terms['narrower'])); - $this->assertTrue(in_array('Construction workers', $terms['broader'])); - } - /** * Load WorldCatUtils client w/ fixture * diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/WorldCatTermsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/WorldCatTermsTest.php deleted file mode 100644 index f59ef4829fb60e8983c30e353b74bce344bd041a..0000000000000000000000000000000000000000 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/WorldCatTermsTest.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -/** - * WorldCatTerms recommendation module Test Class - * - * PHP version 5 - * - * Copyright (C) Villanova University 2010. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @category VuFind2 - * @package Tests - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link http://vufind.org/wiki/vufind2:unit_tests Wiki - */ -namespace VuFindTest\Recommend; -use VuFind\Recommend\WorldCatTerms; - -/** - * WorldCatTerms recommendation module Test Class - * - * @category VuFind2 - * @package Tests - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link http://vufind.org/wiki/vufind2:unit_tests Wiki - */ -class WorldCatTermsTest extends \VuFindTest\Unit\TestCase -{ - /** - * Test normal operation of the module. - * - * @return void - */ - public function testNormalOperation() - { - $terms = [ - 'exact' => 'exact', 'junk' => 'junk' - ]; - $wcu = $this->getMockWorldCatUtils(); - $wcu->expects($this->once())->method('getRelatedTerms') - ->with($this->equalTo('foo'), $this->equalTo('lcsh')) - ->will($this->returnValue($terms)); - $results = $this->getMockResults(); - $request = new \Zend\StdLib\Parameters([]); - $module = new WorldCatTerms($wcu); - $module->setConfig(''); - $module->init($results->getParams(), $request); - $module->process($results); - $this->assertEquals(['exact' => 'exact'], $module->getTerms()); - } - - /** - * Get a mock WorldCatUtils object. - * - * @return \VuFind\Connection\WorldCatUtils - */ - protected function getMockWorldCatUtils() - { - return $this->getMockBuilder('VuFind\Connection\WorldCatUtils') - ->disableOriginalConstructor()->getMock(); - } - - /** - * Get a mock results object. - * - * @return \VuFind\Search\Solr\Results - */ - protected function getMockResults() - { - $query = new \VuFindSearch\Query\Query('foo', 'bar'); - $params = $this->getMockBuilder('VuFind\Search\Solr\Params') - ->disableOriginalConstructor()->getMock(); - $params->expects($this->any())->method('getQuery') - ->will($this->returnValue($query)); - $results = $this->getMockBuilder('VuFind\Search\Solr\Results') - ->disableOriginalConstructor()->getMock(); - $results->expects($this->any())->method('getParams') - ->will($this->returnValue($params)); - return $results; - } -} \ No newline at end of file diff --git a/themes/bootstrap3/templates/Recommend/Deprecated.phtml b/themes/bootstrap3/templates/Recommend/Deprecated.phtml new file mode 100644 index 0000000000000000000000000000000000000000..63445d34f9c1ebc4c55c092c9dcf8965c9fd3c66 --- /dev/null +++ b/themes/bootstrap3/templates/Recommend/Deprecated.phtml @@ -0,0 +1,2 @@ +<? /* do nothing -- this module is a placeholder for old deprecated features + to prevent legacy configurations from causing fatal errors. */ ?> \ No newline at end of file diff --git a/themes/bootstrap3/templates/Recommend/WorldCatTerms.phtml b/themes/bootstrap3/templates/Recommend/WorldCatTerms.phtml deleted file mode 100644 index ed9c6bbfc0f9e81e0116a70b2f3c317247d11541..0000000000000000000000000000000000000000 --- a/themes/bootstrap3/templates/Recommend/WorldCatTerms.phtml +++ /dev/null @@ -1,21 +0,0 @@ -<? $worldCatTerms = $this->recommend->getTerms(); if (!empty($worldCatTerms)): ?> -<h4><?=$this->transEsc('Subject Recommendations')?></h4> -<div class="row"> - <? $i = 0; foreach ($worldCatTerms as $type => $section): ?> - <? $moreClass = 'WCTerms'.$this->escapeHtml($type).' hidden'; ?> - <div class="col-sm-<?=floor(12/count($worldCatTerms)) ?>"> - <dl> - <dt><?=$this->transEsc('wcterms_' . $type)?></dt> - <? $j = 0; foreach ($section as $subj): ?> - <? if (++$j == 4): ?> - <dd id="moreWCTerms<?=$this->escapeHtml($type)?>"><a href="#" onclick="moreFacets('WCTerms<?=$this->escapeHtml($type)?>'); return false;"><?=$this->transEsc('more')?> ...</a></dd> - <? endif; ?> - <dd<? if($j >= 4): ?> class="<?=$moreClass ?>"<? endif ?>>• <a href="<?=$this->url('search-results')?>?lookfor=%22<?=urlencode($subj)?>%22&type=Subject"><?=$this->escapeHtml($subj)?></a></dd> - <? endforeach; ?> - <? if ($j > 3): ?><dd class="<?=$moreClass ?>"><a href="#" onclick="lessFacets('WCTerms<?=$this->escapeHtml($type)?>'); return false;"><?=$this->transEsc('less')?> ...</a></dd><? endif; ?> - </dl> - </div> - <? endforeach; ?> - <div class="clearfix"></div> -</div> -<? endif; ?> diff --git a/themes/jquerymobile/templates/Recommend/Deprecated.phtml b/themes/jquerymobile/templates/Recommend/Deprecated.phtml new file mode 100644 index 0000000000000000000000000000000000000000..63445d34f9c1ebc4c55c092c9dcf8965c9fd3c66 --- /dev/null +++ b/themes/jquerymobile/templates/Recommend/Deprecated.phtml @@ -0,0 +1,2 @@ +<? /* do nothing -- this module is a placeholder for old deprecated features + to prevent legacy configurations from causing fatal errors. */ ?> \ No newline at end of file diff --git a/themes/jquerymobile/templates/Recommend/WorldCatTerms.phtml b/themes/jquerymobile/templates/Recommend/WorldCatTerms.phtml deleted file mode 100644 index 0df1e74df188b2630299fe4da6e7178c92ad5afc..0000000000000000000000000000000000000000 --- a/themes/jquerymobile/templates/Recommend/WorldCatTerms.phtml +++ /dev/null @@ -1 +0,0 @@ -<? /* Not supported in mobile theme. */ ?> \ No newline at end of file