Code Monkey home page Code Monkey logo

fuzzymatch's Introduction

FuzzyMatch

A simple fuzzy string matching library that provides functionality similar to the Ctrl-p command in Sublime Text.

The code is very raw right now and was created as a way for the author to learn Rust programming. However, I hope to keep adding more functionality as I learn more. The initial implementation is a direct port of the algorithm described in this blog.

Features

Given a string and a pattern, the algorithm finds out whether the string contains all the characters in the pattern signature in order. It uses various heuristics to score the match.

I plan to create a web frontend in the future that will use this fuzzy matcher.

Usage

The code is supplied as a library at the moment. It can be added in the Cargo.toml file of your cargo project with the github link as fuzzymatch = { git = "https://github.com/batuwa/fuzzymatch.git" } and importing it into the module it will be used like any other crate extern crate fuzzymatch. See the fuzzysearch repo for an example.

Simple Match Algorithm

This function tells if the given fuzzy search pattern can be found in the given string in sequence. It can be used for any sub-string matching use-case.

use fuzzymatch::algo::fuzzy_match_simple;

let search = "something";
let my_string = "some search thing";

let matched = fuzzy_match_simple(search, my_string);

println!("Pattern is given string: {:?}", matched);

Scored Match Algorithm

This function provides a score to each matching string based on whether the match occurred in the beginning of the string, beginning of a word, uppercase letter etc. Higher score means better match. It also returns the indices of the matched characters.

use fuzzymatch::algo::fuzzy_match;

let search = "something";
let my_string1 = "some search thing";
let my_string2 = "this is really something";

let (is_match1, score1, matching_indices1) = fuzzy_match(search, my_string1);
let (is_match2, score2, matching_indices1) = fuzzy_match(search, my_string2);

println!("Score for string1 = {:?}", score1);
println!("Score for string2 = {:?}", score2);

fuzzymatch's People

Contributors

batuwa avatar

Watchers

 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.