-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from laserpants/next
New API
- Loading branch information
Showing
19 changed files
with
1,888 additions
and
1,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
.stack-work | ||
.cabal-sandbox | ||
cabal.sandbox.config | ||
dist | ||
.stack-work/ | ||
*~ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,39 @@ | ||
# fuzzyset [![Haskell CI](https://github.com/laserpants/fuzzyset-haskell/actions/workflows/haskell.yml/badge.svg)](https://github.com/laserpants/fuzzyset-haskell/actions/workflows/haskell.yml) [![License](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Language](https://img.shields.io/badge/language-Haskell-yellow.svg)](https://www.haskell.org/) [![Hackage](https://img.shields.io/hackage/v/fuzzyset.svg)](http://hackage.haskell.org/package/fuzzyset) | ||
# fuzzyset-haskell | ||
|
||
A fuzzy string set data structure for approximate string matching. | ||
[![License](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) | ||
[![Language](https://img.shields.io/badge/language-Haskell-yellow.svg)](https://www.haskell.org/) | ||
[![Hackage](https://img.shields.io/hackage/v/fuzzyset.svg)](http://hackage.haskell.org/package/fuzzyset) | ||
|
||
## Examples | ||
A fuzzy string set data structure for approximate string matching. | ||
|
||
```haskell | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main where | ||
|
||
import Data.FuzzySet | ||
|
||
states = [ "Alabama" , "Alaska" , "American Samoa" , "Arizona" , "Arkansas" | ||
, "California" , "Colorado" , "Connecticut" , "Delaware" , "District of Columbia" | ||
, "Florida" , "Georgia" , "Guam" , "Hawaii" , "Idaho" | ||
, "Illinois" , "Indiana" , "Iowa" , "Kansas" , "Kentucky" | ||
, "Louisiana" , "Maine" , "Maryland" , "Massachusetts" , "Michigan" | ||
, "Minnesota" , "Mississippi" , "Missouri" , "Montana" , "Nebraska" | ||
, "Nevada" , "New Hampshire" , "New Jersey" , "New Mexico" , "New York" | ||
, "North Carolina" , "North Dakota" , "Northern Marianas Islands" , "Ohio" , "Oklahoma" | ||
, "Oregon" , "Pennsylvania" , "Puerto Rico" , "Rhode Island" , "South Carolina" | ||
, "South Dakota" , "Tennessee" , "Texas" , "Utah" , "Vermont" | ||
, "Virginia" , "Virgin Islands" , "Washington" , "West Virginia" , "Wisconsin" | ||
, "Wyoming" ] | ||
|
||
statesSet = fromList states | ||
|
||
main = mapM_ print (get statesSet "Burger Islands") | ||
``` | ||
In a nutshell: | ||
|
||
The output of this program is: | ||
1. Add data to the set (see `add`, `add_`, `addMany`, and `addMany_`) | ||
2. Query the set (see `find`, `findMin`, `findOne`, `findOneMin`, `closestMatchMin`, and `closestMatch`) | ||
|
||
```haskell | ||
(0.7142857142857143,"Virgin Islands") | ||
(0.5714285714285714,"Rhode Island") | ||
(0.44,"Northern Marianas Islands") | ||
(0.35714285714285715,"Maryland") | ||
``` | ||
Refer to the [Haddock docs](http://hackage.haskell.org/package/fuzzyset) for details. | ||
|
||
Using the same definition of `statesSet` from previous example: | ||
## Example | ||
|
||
```haskell | ||
>>> get statesSet "Why-oh-me-ing" | ||
[(0.5384615384615384,"Wyoming")] | ||
|
||
>>> get statesSet "Connect a cat" | ||
[(0.6923076923076923,"Connecticut")] | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main where ``` | ||
|
||
>>> get statesSet "Transylvania" | ||
[(0.75,"Pennsylvania"),(0.3333333333333333,"California"),(0.3333333333333333,"Arkansas"),(0.3333333333333333,"Kansas")] | ||
import Control.Monad.Trans.Class (lift) | ||
import Data.Text (Text) | ||
import Data.FuzzySet (FuzzySearchT, add_, closestMatch, runDefaultFuzzySearchT) | ||
|
||
>>> get statesSet "CanOfSauce" | ||
[(0.4,"Kansas")] | ||
findMovie :: Text -> FuzzySearchT IO (Maybe Text) | ||
findMovie = closestMatch | ||
|
||
>>> get statesSet "Alaska" | ||
[(1.0,"Alaska")] | ||
prog :: FuzzySearchT IO () | ||
prog = do | ||
add_ "Jurassic Park" | ||
add_ "Terminator" | ||
add_ "The Matrix" | ||
result <- findMovie "The Percolator" | ||
lift (print result) | ||
|
||
>>> get statesSet "Alaskanbraskansas" | ||
[(0.47058823529411764,"Arkansas"),(0.35294117647058826,"Kansas"),(0.35294117647058826,"Alaska"),(0.35294117647058826,"Alabama"),(0.35294117647058826,"Nebraska")] | ||
main :: IO () | ||
main = runDefaultFuzzySearchT prog | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generated from https://fourmolu.github.io/config/ | ||
indentation: 2 | ||
column-limit: none | ||
function-arrows: leading | ||
comma-style: leading | ||
import-export-style: leading | ||
indent-wheres: true | ||
record-brace-space: false | ||
newlines-between-decls: 1 | ||
haddock-style: multi-line | ||
haddock-style-module: null | ||
let-style: auto | ||
in-style: right-align | ||
single-constraint-parens: always | ||
unicode: never | ||
respectful: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.