php-extended/php-score-object

实现 php-score-interface 包的库

7.0.6 2024-07-31 13:33 UTC

README

实现 php-score-interface 包的库

coverage build status

安装

此库的安装是通过 composer 完成的,并且所有类的自动加载都通过它们的自动加载器来完成。

  • 他们的网站下载 composer.phar
  • 然后运行以下命令将此库作为依赖项安装
  • php composer.phar require php-extended/php-score-object ^7

基本用法

您可以使用以下方式使用此库


use PhpExtended\Score\StringLevenshteinScore;
use PhpExtended\Score\ScoreCollection;
use PhpExtended\Score\PresumptionGuiltPolicy;

// First, let's image you have three strings and a reference string, and you
// want to know which is the global distance of the three strings from the
// reference

$reference = '<put your reference string here>';
$test1     = '<put your first test string here>';
$test2     = '<put your second test string here>';
$test3     = '<put your third test string here>';

$score1 = new StringLevenshteinScore($reference, $test1);
$score2 = new StringLevenshteinScore($reference, $test2);
$score3 = new StringLevenshteinScore($reference, $test3);

// Next, concatenate the results
$collection = new ScoreCollection();
$collection->add($score1);
$collection->add($score2);
$collection->add($score3);

// Finally, get the mean value
$result = $collection->resolve(new PresumptionGuiltPolicy());

// To get the result as a number between 0 and 1, use the getNormalizedValue()
// of the IScore object $result.

许可证

MIT (见许可证文件)。