Git Product home page Git Product logo

similar-text-finder's Introduction

Similar Text Finder

Packagist Scrutinizer Code Quality Build Status Code Coverage SensioLabsInsight

TL;DR

Similar text finder. Install via composer, works with any framework: Laravel, Slim, Symfony, etc.

screenshot

// Init Similar Text Finder with a needle and a haystack
$text_finder = new \SimilarText\Finder('bananna', ['apple', 'banana', 'kiwi']);

// Get first similar word (it's banana)
echo $text_finder->first();

Installation

Install with composer composer require rap2hpoutre/similar-text-finder That's all.

You can now use it in your framework's controller, or wherever you want (you don't need a framework anyway).

Usage

Quick start

Just build a new Similar Text Finder like this:

$tf = new \SimilarText\Finder($needle, $haystack);

$needle may be the user input and $haystack should be an array with all your suggestion. You can display the closest response like this:

echo 'Did you mean ' $tf->first() . ' ?';

Or use it in your favorite template engine (Twig, Blade, etc.)

You can get all your suggestion ordered by most approching words like this:

$all = $tf->all();

Example in raw PHP

use SimilarText\Finder;

// User input with a typo (you could get it from $_GET)
$needle = 'tmatoes';

// Your list (from your database or an API)
$haystack = ['salad', 'tomatoes', 'onions', 'mates'];

// Init Text Finder
$finder = new Finder($needle, $haystack);

// Display all results ordered by the most approching
$results = $finder->all();
echo implode(', ', $results);

// You should see something like "tomatoes, mates, onions, salad", yohoo.

similar-text-finder's People

Contributors

josegonzalez avatar rap2hpoutre avatar scrutinizer-auto-fixer avatar

Watchers

 avatar  avatar

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.