• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/template/functions/fabric.php
  • Класс: BitrixIblockTemplateFunctionsFunctionContrast
  • Вызов: FunctionContrast::calculate
public function calculate(array $parameters)
{
	$result = $this->parametersToArray($parameters);
	$limit = array_pop($result);
	$delimiter = array_pop($result);
	$text = strip_tags(implode(" ", $result));

	$words = array();
	$result = preg_split("/([".preg_quote($delimiter, "/")."]+)/", $text);
	if ($result)
	{
		foreach ($result as $word)
		{
			if (mb_strlen($word) > 1)
				$words[$word]++;
		}
		$len = log(max(20, array_sum($words)));
		foreach ($words as $word => $count)
		{
			$words[$word] = log($count + 1) / $len;
		}
		arsort($words);
	}
	return array_keys(array_slice($words, 0, $limit));
}