Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
stemmer.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Language
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('JPATH_PLATFORM') or die;
11 
12 /**
13  * Stemmer base class.
14  *
15  * @package Joomla.Platform
16  * @subpackage Language
17  * @since 12.1
18  */
19 abstract class JLanguageStemmer
20 {
21  /**
22  * An internal cache of stemmed tokens.
23  *
24  * @var array
25  * @since 12.1
26  */
27  protected $cache = array();
28 
29  /**
30  * @var array JLanguageStemmer instances.
31  * @since 12.1
32  */
33  protected static $instances = array();
34 
35  /**
36  * Method to get a stemmer, creating it if necessary.
37  *
38  * @param string $adapter The type of stemmer to load.
39  *
40  * @return JLanguageStemmer A JLanguageStemmer instance.
41  *
42  * @since 12.1
43  * @throws RuntimeException on invalid stemmer.
44  */
45  public static function getInstance($adapter)
46  {
47  // Only create one stemmer for each adapter.
48  if (isset(self::$instances[$adapter]))
49  {
50  return self::$instances[$adapter];
51  }
52 
53  // Setup the adapter for the stemmer.
54  $class = 'JLanguageStemmer' . ucfirst(trim($adapter));
55 
56  // Check if a stemmer exists for the adapter.
57  if (!class_exists($class))
58  {
59  // Throw invalid adapter exception.
60  throw new RuntimeException(JText::sprintf('JLIB_STEMMER_INVALID_STEMMER', $adapter));
61  }
62 
63  self::$instances[$adapter] = new $class;
64 
65  return self::$instances[$adapter];
66  }
67 
68  /**
69  * Method to stem a token and return the root.
70  *
71  * @param string $token The token to stem.
72  * @param string $lang The language of the token.
73  *
74  * @return string The root token.
75  *
76  * @since 12.1
77  */
78  abstract public function stem($token, $lang);
79 }