Source for file snowball.php

Documentation is available at snowball.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. JLoader::register('FinderIndexerStemmer'dirname(__DIR__'/stemmer.php');
  13.  
  14. /**
  15.  * Snowball stemmer class for the Finder indexer package.
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_finder
  19.  * @since       2.5
  20.  */
  21. {
  22.     /**
  23.      * Method to stem a token and return the root.
  24.      *
  25.      * @param   string  $token  The token to stem.
  26.      * @param   string  $lang   The language of the token.
  27.      *
  28.      * @return  string  The root token.
  29.      *
  30.      * @since   2.5
  31.      */
  32.     public function stem($token$lang)
  33.     {
  34.         // Language to use if All is specified.
  35.         static $defaultLang '';
  36.  
  37.         // If language is All then try to get site default language.
  38.         if ($lang == '*' && $defaultLang == '')
  39.         {
  40.             $languages JLanguageHelper::getLanguages();
  41.             $defaultLang = isset($languages[0]->sef$languages[0]->sef '*';
  42.             $lang $defaultLang;
  43.         }
  44.  
  45.         // Stem the token if it is not in the cache.
  46.         if (!isset($this->cache[$lang][$token]))
  47.         {
  48.             // Get the stem function from the language string.
  49.             switch ($lang)
  50.             {
  51.                 // Danish stemmer.
  52.                 case 'da':
  53.                     $function 'stem_danish';
  54.                     break;
  55.  
  56.                 // German stemmer.
  57.                 case 'de':
  58.                     $function 'stem_german';
  59.                     break;
  60.  
  61.                 // English stemmer.
  62.                 default:
  63.                 case 'en':
  64.                     $function 'stem_english';
  65.                     break;
  66.  
  67.                 // Spanish stemmer.
  68.                 case 'es':
  69.                     $function 'stem_spanish';
  70.                     break;
  71.  
  72.                 // Finnish stemmer.
  73.                 case 'fi':
  74.                     $function 'stem_finnish';
  75.                     break;
  76.  
  77.                 // French stemmer.
  78.                 case 'fr':
  79.                     $function 'stem_french';
  80.                     break;
  81.  
  82.                 // Hungarian stemmer.
  83.                 case 'hu':
  84.                     $function 'stem_hungarian';
  85.                     break;
  86.  
  87.                 // Italian stemmer.
  88.                 case 'it':
  89.                     $function 'stem_italian';
  90.                     break;
  91.  
  92.                 // Norwegian stemmer.
  93.                 case 'nb':
  94.                     $function 'stem_norwegian';
  95.                     break;
  96.  
  97.                 // Dutch stemmer.
  98.                 case 'nl':
  99.                     $function 'stem_dutch';
  100.                     break;
  101.  
  102.                 // Portuguese stemmer.
  103.                 case 'pt':
  104.                     $function 'stem_portuguese';
  105.                     break;
  106.  
  107.                 // Romanian stemmer.
  108.                 case 'ro':
  109.                     $function 'stem_romanian';
  110.                     break;
  111.  
  112.                 // Russian stemmer.
  113.                 case 'ru':
  114.                     $function 'stem_russian_unicode';
  115.                     break;
  116.  
  117.                 // Swedish stemmer.
  118.                 case 'sv':
  119.                     $function 'stem_swedish';
  120.                     break;
  121.  
  122.                 // Turkish stemmer.
  123.                 case 'tr':
  124.                     $function 'stem_turkish_unicode';
  125.                     break;
  126.             }
  127.  
  128.             // Stem the word if the stemmer method exists.
  129.             $this->cache[$lang][$tokenfunction_exists($function$function($token$token;
  130.         }
  131.  
  132.         return $this->cache[$lang][$token];
  133.     }
  134. }

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