2017 © Pedro Peláez
 

library chain-select

image

macfja/chain-select

  • Thursday, April 5, 2018
  • by MacFJA
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ChainSelect

Find the best option, (*1)

Installation

The best way to install this lib is to use Composer., (*2)

$ composer require macfja/chain-select

Usage

$runner = new Runner();
$runner->setMinAcceptableScore(0.75);
$runner->addHandler(new MyCustomHandler());
$runner->addHandler(new MyOtherHandler());
$runner->setContext($myContext);

$runner->getFirstAcceptable();

Examples

Simple example with a corpus of text, (*3)

$existingKeywords = [/* your code here*/];
$runner = CorpusHandlerHelper::addCorpus(new Runner(), $existingKeywords);
$runner->setContext($userInput);
$result = $runner->getBestMatch();

if ($result->getScore() === 1.0) {
    // your code here. Example:
    //$page->addKeyword($result->getResult());
} else {
    // your code here. Example:
    //echo 'Did you mean "'.$result->getResult().'"?';
}

A more complex example, (*4)

$runner = new Runner();
$runner->setMinAcceptableScore(0.75);
$runner->addHandler(new class implements HandlerInterface {
    public function execute($context)
    {
        // Some external request that return a score/confidence value
        $percent = doSomethingAwesome($context);
        return new HandlerResult($percent/100, $percent, $context, $this);
    }
    public function accept($context)
    {
        return true;
    }
});
$runner->addHandler(new class implements HandlerInterface {
    public function execute($context)
    {
        // Some voodoo calculation with the context
        $noteOnTen = myHardWorkCalculation($context);
        return new HandlerResult($percent/10, $noteOnTen, $context, $this);
    }
    public function accept($context)
    {
        return true;
    }
});
$runner->setContext($myContext);

$result = $runner->getFirstAcceptable();

var_dump($result);

Contributing

You are welcome to create new issues if you found a bug or have an idea to improve this lib., (*5)

You can also create Pull Request., (*6)

Code quality

The code follow the PSR-1, PSR-2, PSR-4., (*7)

The code is validated/monitored with the following tools :, (*8)

Php LOC, Php CPD, PhpCS, Pdepend, PHPMD, PhpMetrics, Parallel-Lint, PhpAssumption, PhpMagicNumberDetector, PhpStan, Psalm, PhpUnit, Infection, (*9)

You can run the full test-suite with the command:, (*10)

$ composer tests

The Versions