An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Fuzzy Events

[![Build Status](https://travis-ci.com/DivineOmega/fuzzy-events.svg?branch=master)](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
// ]
```