Text.Fuzzy

fuzzy-0.1.1.0: Filters a list based on a fuzzy string search.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Fuzzy

Description

Fuzzy string search in Haskell. Uses `TextualMonoid` to be able to run on different types of strings.

Synopsis

- data TextualMonoid s => Fuzzy t s = Fuzzy {
  - original :: t
  - rendered :: s
  - score :: Int
  }
- match :: TextualMonoid s => s -> t -> s -> s -> (t -> s) -> Bool -> Maybe (Fuzzy t s)
- filter :: TextualMonoid s => s -> [t] -> s -> s -> (t -> s) -> Bool -> [Fuzzy t s]
- simpleFilter :: TextualMonoid s => s -> [s] -> [s]
- test :: TextualMonoid s => s -> s -> Bool

# Documentation

data TextualMonoid s => Fuzzy t s #

Included in the return type of ``match`` and ``filter``. Contains the original value given, the rendered string and the matching score.

Constructors

Fuzzy |
Fields original :: t rendered :: s score :: Int

#### Instances

Instances details

(TextualMonoid s, Show t, Show s) => Show (Fuzzy t s) # |
Instance details Defined in Text.Fuzzy Methods showsPrec :: Int -> Fuzzy t s -> ShowS # show :: Fuzzy t s -> String # showList :: [Fuzzy t s] -> ShowS #
(TextualMonoid s, Eq t, Eq s) => Eq (Fuzzy t s) # |
Instance details Defined in Text.Fuzzy Methods (==) :: Fuzzy t s -> Fuzzy t s -> Bool # (/=) :: Fuzzy t s -> Fuzzy t s -> Bool #

match #

Arguments

:: TextualMonoid s |
=> s | Pattern.
-> t | The value containing the text to search in.
-> s | The text to add before each match.
-> s | The text to add after each match.
-> (t -> s) | The function to extract the text from the container.
-> Bool | Case sensitivity.
-> Maybe (Fuzzy t s) | The original value, rendered string and score.

Returns the rendered output and the matching score for a pattern and a text. Two examples are given below:

    >>> match "fnt" "infinite" "" "" id True
    Just ("infinite",3)

    >>> match "hsk" ("Haskell",1995) "<" ">" fst False
    Just ("<H>a<s><k>ell",5)

filter #

Arguments

:: TextualMonoid s |
=> s | Pattern.
-> [t] | The list of values containing the text to search in.
-> s | The text to add before each match.
-> s | The text to add after each match.
-> (t -> s) | The function to extract the text from the container.
-> Bool | Case sensitivity.
-> [Fuzzy t s] | The list of results, sorted, highest score first.

The function to filter a list of values by fuzzy search on the text extracted from them.

    >>> filter "ML" [("Standard ML", 1990),("OCaml",1996),("Scala",2003)] "<" ">" fst False
    [Fuzzy {original = ("Standard ML",1990), rendered = "Standard <M><L>", score = 4},Fuzzy {original = ("OCaml",1996), rendered = "OCa<m><l>", score = 4}]

simpleFilter #

Arguments

:: TextualMonoid s |
=> s | Pattern to look for.
-> [s] | List of texts to check.
-> [s] | The ones that match.

Return all elements of the list that have a fuzzy match against the pattern. Runs with default settings where nothing is added around the matches, as case insensitive.

    >>> simpleFilter "vm" ["vim", "emacs", "virtual machine"]
    ["vim","virtual machine"]

test :: TextualMonoid s => s -> s -> Bool #

Returns false if the pattern and the text do not match at all. Returns true otherwise.

    >>> test "brd" "bread"
    True