コード例 #1
0
ファイル: token.php プロジェクト: adjaika/J3Base
 /**
  * Method to construct the token object.
  *
  * @param   mixed   $term    The term as a string for words or an array for phrases.
  * @param   string  $lang    The simple language identifier.
  * @param   string  $spacer  The space separator for phrases. [optional]
  *
  * @since   2.5
  */
 public function __construct($term, $lang, $spacer = ' ')
 {
     $this->language = $lang;
     // Tokens can be a single word or an array of words representing a phrase.
     if (is_array($term)) {
         // Populate the token instance.
         $this->term = implode($spacer, $term);
         $this->stem = implode($spacer, array_map(array('FinderIndexerHelper', 'stem'), $term, array($lang)));
         $this->numeric = false;
         $this->common = false;
         $this->phrase = true;
         $this->length = JString::strlen($this->term);
         /*
          * Calculate the weight of the token.
          *
          * 1. Length of the token up to 30 and divide by 30, add 1.
          * 2. Round weight to 4 decimal points.
          */
         $this->weight = ($this->length >= 30 ? 30 : $this->length) / 30 + 1;
         $this->weight = round($this->weight, 4);
     } else {
         // Populate the token instance.
         $this->term = $term;
         $this->stem = FinderIndexerHelper::stem($this->term, $lang);
         $this->numeric = is_numeric($this->term) || (bool) preg_match('#^[0-9,.\\-\\+]+$#', $this->term);
         $this->common = $this->numeric ? false : FinderIndexerHelper::isCommon($this->term, $lang);
         $this->phrase = false;
         $this->length = JString::strlen($this->term);
         /*
          * Calculate the weight of the token.
          *
          * 1. Length of the token up to 15 and divide by 15.
          * 2. If common term, divide weight by 8.
          * 3. If numeric, multiply weight by 1.5.
          * 4. Round weight to 4 decimal points.
          */
         $this->weight = ($this->length >= 15 ? 15 : $this->length) / 15;
         $this->weight = $this->common == true ? $this->weight / 8 : $this->weight;
         $this->weight = $this->numeric == true ? $this->weight * 1.5 : $this->weight;
         $this->weight = round($this->weight, 4);
     }
 }
コード例 #2
0
 /**
  * @todo   Implement testStem().
  */
 public function testStem()
 {
     $this->assertEquals(FinderIndexerHelper::stem('token', 'en'), 'token');
 }