Source for file stemmer.php

Documentation is available at stemmer.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_finder
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Stemmer base class for the Finder indexer package.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_finder
  17.  * @since       2.5
  18.  */
  19. abstract class FinderIndexerStemmer
  20. {
  21.     /**
  22.      * An internal cache of stemmed tokens.
  23.      *
  24.      * @var    array 
  25.      * @since  2.5
  26.      */
  27.     public $cache = array();
  28.  
  29.     /**
  30.      * Method to get a stemmer, creating it if necessary.
  31.      *
  32.      * @param   string  $adapter  The type of stemmer to load.
  33.      *
  34.      * @return  FinderIndexerStemmer  A FinderIndexerStemmer instance.
  35.      *
  36.      * @since   2.5
  37.      * @throws  Exception on invalid stemmer.
  38.      */
  39.     public static function getInstance($adapter)
  40.     {
  41.         static $instances;
  42.  
  43.         // Only create one stemmer for each adapter.
  44.         if (isset($instances[$adapter]))
  45.         {
  46.             return $instances[$adapter];
  47.         }
  48.  
  49.         // Create an array of instances if necessary.
  50.         if (!is_array($instances))
  51.         {
  52.             $instances array();
  53.         }
  54.  
  55.         // Setup the adapter for the stemmer.
  56.         $adapter JFilterInput::getInstance()->clean($adapter'cmd');
  57.         $path = __DIR__ . '/stemmer/' $adapter '.php';
  58.         $class 'FinderIndexerStemmer' ucfirst($adapter);
  59.  
  60.         // Check if a stemmer exists for the adapter.
  61.         if (file_exists($path))
  62.         {
  63.             // Instantiate the stemmer.
  64.             include_once $path;
  65.             $instances[$adapternew $class;
  66.         }
  67.         else
  68.         {
  69.             // Throw invalid adapter exception.
  70.             throw new Exception(JText::sprintf('COM_FINDER_INDEXER_INVALID_STEMMER'$adapter));
  71.         }
  72.  
  73.         return $instances[$adapter];
  74.     }
  75.  
  76.     /**
  77.      * Method to stem a token and return the root.
  78.      *
  79.      * @param   string  $token  The token to stem.
  80.      * @param   string  $lang   The language of the token.
  81.      *
  82.      * @return  string  The root token.
  83.      *
  84.      * @since   2.5
  85.      */
  86.     abstract public function stem($token$lang);
  87. }

Documentation generated on Tue, 19 Nov 2013 15:14:21 +0100 by phpDocumentor 1.4.3