https://github.com/divineomega/fuzzy-events
Perform actions based on a fuzzy string matches
https://github.com/divineomega/fuzzy-events
Last synced: about 1 year ago
JSON representation
Perform actions based on a fuzzy string matches
- Host: GitHub
- URL: https://github.com/divineomega/fuzzy-events
- Owner: DivineOmega
- License: lgpl-3.0
- Created: 2020-03-10T21:42:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T23:50:51.000Z (over 6 years ago)
- Last Synced: 2025-02-10T05:28:58.485Z (over 1 year ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fuzzy Events
[](https://travis-ci.com/DivineOmega/fuzzy-events)
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.
```bash
composer require divineomega/fuzzy-events
```
### Usage
See the following usage example.
```php
class Greeting implements FuzzyListenerInterface
{
public function handle(string $query)
{
return 'Hello there!';
}
}
```
```php
$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
// ]
```