-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Fuzzy set for approximate string matching
--   
--   This library is based on the Python and JavaScript libraries with the
--   same name.
@package fuzzyset
@version 0.1.0.6

module Data.FuzzySet.Types
data FuzzySetItem
FuzzySetItem :: !Double -> !Text -> FuzzySetItem
[vectorMagnitude] :: FuzzySetItem -> !Double
[normalizedEntry] :: FuzzySetItem -> !Text
data GramInfo
GramInfo :: !Int -> !Int -> GramInfo
[itemIndex] :: GramInfo -> !Int
[gramCount] :: GramInfo -> !Int

-- | Type alias for representing gram sizes.
type Size = Int
type ExactSet = HashMap Text Text
type MatchDict = HashMap Text [GramInfo]
type ItemMap = HashMap Size (Vector FuzzySetItem)

-- | Opaque fuzzy string set data type. Use <a>defaultSet</a>,
--   <a>mkSet</a>, or <a>fromList</a> to create <a>FuzzySet</a>s.
data FuzzySet
FuzzySet :: !Size -> !Size -> !Bool -> !ExactSet -> !MatchDict -> !ItemMap -> FuzzySet
[gramSizeLower] :: FuzzySet -> !Size
[gramSizeUpper] :: FuzzySet -> !Size
[useLevenshtein] :: FuzzySet -> !Bool
[exactSet] :: FuzzySet -> !ExactSet
[matchDict] :: FuzzySet -> !MatchDict
[items] :: FuzzySet -> !ItemMap
data GetContext
GetContext :: !Text -> !Double -> !FuzzySet -> GetContext
[key] :: GetContext -> !Text
[minScore] :: GetContext -> !Double
[set] :: GetContext -> !FuzzySet

-- | A <a>FuzzySet</a> with the following field values:
--   
--   <pre>
--   { gramSizeLower  = 2
--   , gramSizeUpper  = 3
--   , useLevenshtein = True
--   , exactSet       = ε
--   , matchDict      = ε
--   , items          = ε }
--   </pre>
defaultSet :: FuzzySet
instance GHC.Show.Show Data.FuzzySet.Types.GetContext
instance GHC.Show.Show Data.FuzzySet.Types.FuzzySet
instance GHC.Classes.Eq Data.FuzzySet.Types.FuzzySet
instance GHC.Show.Show Data.FuzzySet.Types.GramInfo
instance GHC.Classes.Eq Data.FuzzySet.Types.GramInfo
instance GHC.Show.Show Data.FuzzySet.Types.FuzzySetItem
instance GHC.Classes.Eq Data.FuzzySet.Types.FuzzySetItem
instance Data.Default.Class.Default Data.FuzzySet.Types.FuzzySet

module Data.FuzzySet.Lens
_items :: Lens' FuzzySet ItemMap
_matchDict :: Lens' FuzzySet MatchDict
_exactSet :: Lens' FuzzySet ExactSet
_useLevenshtein :: Lens' FuzzySet Bool
_gramSizeLower :: Lens' FuzzySet Size
_gramSizeUpper :: Lens' FuzzySet Size
_vectorMagnitude :: Lens' FuzzySetItem Double
_normalizedEntry :: Lens' FuzzySetItem Text

module Data.FuzzySet.Util

-- | Return the normalized Levenshtein distance between the two strings.
distance :: Text -> Text -> Double

-- | Insert the character <i>ch</i> at the beginning and end of the input
--   string.
enclosedIn :: Text -> Char -> Text

-- | Normalize the input by
--   
--   <ul>
--   <li>removing non-word characters, except for spaces and commas;
--   and</li>
--   <li>converting alphabetic characters to lowercase.</li>
--   </ul>
normalized :: Text -> Text

-- | Returns the euclidian norm, or <i>magnitude</i>, of the input list
--   interpreted as a vector. That is, &lt;math&gt; for the input
--   &lt;math&gt; where &lt;math&gt; is the element at position <i>i</i> in
--   the input list.
norm :: (Integral a, Floating b) => [a] -> b

-- | Return <i>n</i> characters starting from offset <i>m</i> in the input
--   string.
substr :: Int -> Int -> Text -> Text

-- | Empty HashMap
ε :: HashMap k v

-- | <pre>
--   (&lt;$$&gt;) = fmap ∘ fmap
--   </pre>
(<$$>) :: (Functor f, Functor g) => (a -> b) -> g (f a) -> g (f b)

-- | Unicode minus sign symbol. Slightly longer than the hyphen-minus
--   commonly used, U+2212 aligns naturally with the horizontal bar of the
--   + symbol.
(−) :: Num α => α -> α -> α

-- | Another unicode operator. This one for multiplication.
(×) :: Num α => α -> α -> α

module Data.FuzzySet.Internal
getMatch :: GetContext -> Size -> [(Double, Text)]
results :: GetContext -> Size -> [(Double, Text)]
matches :: FuzzySet -> HashMap Text Int -> HashMap Int Int

-- | Normalize the input string, call <a>grams</a> on the normalized input,
--   and then translate the result to a <a>HashMap</a> with the
--   <i>n</i>-grams as keys and <a>Int</a> values corresponding to the
--   number of occurences of the key in the generated gram list.
--   
--   <pre>
--   &gt;&gt;&gt; gramMap "xxxx" 2
--   fromList [("-x",1), ("xx",3), ("x-",1)]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; Data.HashMap.Strict.lookup "nts" (gramMap "intrent'srestaurantsomeoftrent'saunt'santswantsamtorentsomepants" 3)
--   Just 8
--   </pre>
gramMap :: Text -> Size -> HashMap Text Int

-- | Break apart the normalized input string into a list of <i>n</i>-grams.
--   For instance, the string "Destroido Corp." is first normalized into
--   the form "destroido corp", and then enclosed in hyphens, so that it
--   becomes "-destroido corp-". The <i>3</i>-grams generated from this
--   normalized string are
--   
--   <pre>
--   "-de", "des", "est", "str", "tro", "roi", "oid", "ido", "do ", "o c", " co", "cor", "orp", "rp-"
--   </pre>
--   
--   Given a normalized string of length <i>s</i>, we take all substrings
--   of length <i>n</i>, letting the offset range from &lt;math&gt;. The
--   number of <i>n</i>-grams for a normalized string of length <i>s</i> is
--   thus &lt;math&gt;, where &lt;math&gt;.
grams :: Text -> Size -> [Text]


-- | A fuzzy string set data structure for approximate string matching.
--   This implementation is based on the Python and JavaScript libraries
--   with the same name:
--   
--   <ul>
--   <li><a>JavaScript version</a></li>
--   <li><a>Python version</a></li>
--   </ul>
module Data.FuzzySet

-- | Opaque fuzzy string set data type. Use <a>defaultSet</a>,
--   <a>mkSet</a>, or <a>fromList</a> to create <a>FuzzySet</a>s.
data FuzzySet

-- | Type alias for representing gram sizes.
type Size = Int

-- | Initialize a <a>FuzzySet</a>.
mkSet :: Size -> Size -> Bool -> FuzzySet

-- | A <a>FuzzySet</a> with the following field values:
--   
--   <pre>
--   { gramSizeLower  = 2
--   , gramSizeUpper  = 3
--   , useLevenshtein = True
--   , exactSet       = ε
--   , matchDict      = ε
--   , items          = ε }
--   </pre>
defaultSet :: FuzzySet

-- | Create a fuzzy string set with entries from the given list.
--   
--   <pre>
--   fromList = addMany defaultSet
--   </pre>
fromList :: [Text] -> FuzzySet

-- | Add an entry to the set, or do nothing if a key identical to the
--   provided value already exists in the set.
add :: FuzzySet -> Text -> FuzzySet

-- | Add an entry to the set and return a pair with the new set, and a
--   boolean to indicate if a new entry was inserted, or not.
addToSet :: FuzzySet -> Text -> (FuzzySet, Bool)

-- | Add a list of entries to the set, in one go.
--   
--   <pre>
--   addMany = foldr (flip add)
--   </pre>
addMany :: FuzzySet -> [Text] -> FuzzySet

-- | Try to match the given string against the entries in the set, using a
--   minimum score of 0.33. Return a list of results ordered by similarity
--   score, with the closest match first.
get :: FuzzySet -> Text -> [(Double, Text)]

-- | Try to match the given string against the entries in the set, and
--   return a list of all results with a score greater than or equal to the
--   specified minimum score (i.e., the first argument). The results are
--   ordered by similarity score, with the closest match first.
getWithMinScore :: Double -> FuzzySet -> Text -> [(Double, Text)]

-- | Try to match the given string against the entries in the set, and
--   return the closest match, if one is found.
getOne :: FuzzySet -> Text -> Maybe Text

-- | Return the number of entries in the set.
--   
--   <pre>
--   &gt;&gt;&gt; size (defaultSet `add` "map" `add` "cap")
--   2
--   </pre>
size :: FuzzySet -> Int

-- | Return a boolean indicating whether the provided set is empty.
--   
--   <pre>
--   &gt;&gt;&gt; isEmpty (fromList [])
--   True
--   </pre>
isEmpty :: FuzzySet -> Bool

-- | Return the elements of the set.
--   
--   <pre>
--   &gt;&gt;&gt; values (fromList ["bass", "craze", "space", "lace", "daze", "haze", "ace", "maze"])
--   ["space","daze","bass","maze","ace","craze","lace","haze"]
--   </pre>
values :: FuzzySet -> [Text]
