Code Monkey home page Code Monkey logo

chainselect's Introduction

ChainSelect

Find the best option

Installation

The best way to install this lib is to use Composer.

$ 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

$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

$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.

You can also create Pull Request.

Code quality

The code follow the PSR-1, PSR-2, PSR-4.

The code is validated/monitored with the following tools :

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

You can run the full test-suite with the command:

$ composer tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.