divineomega / fuzzy-events
Perform actions based on fuzzy string matches
Fund package maintenance!
DivineOmega
v1.0.0
2020-03-10 23:39 UTC
Requires
- php: >=7.1
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0||^8.0
This package is auto-updated.
Last update: 2024-10-24 09:42:32 UTC
README
Fuzzy events is a PHP package that allows you to perform actions based on a fuzzy string matches.
Installation
Install using the following Composer command.
composer require divineomega/fuzzy-events
Usage
See the following usage example.
class Greeting implements FuzzyListenerInterface { public function handle(string $query) { return 'Hello there!'; } }
$listeners = [ Greeting::class => [ 'Hello', 'Hi', 'Hey', 'Greetings', 'Howdy', 'Hello there', 'Hi there', ], ]; $confidenceThreshold = 75; $dispatcher = new FuzzyDispatcher($listeners, $confidenceThreshold); $response = $dispatcher->fire('Greetingz!'); // $response = 'Hello there!' try { $dispatcher->fire('Goodbye!'); } catch (ConfidenceTooLowException $e) { // No matches within specified confidence threshold! } $confidences = $dispatcher->getConfidences('Hi!'); // $confidences = [ // Greeting::class => 80 // ]