module QuickSearch.String.OneShot
( oneShot
, oneShotTopNMatches
, oneShotMatchesWithThreshold
, damerauLevenshteinNorm
, jaro
, jaroWinkler
) where
import Data.Hashable ( Hashable )
import Data.Text.Metrics ( damerauLevenshteinNorm
, jaro
, jaroWinkler
)
import QuickSearch.String ( Entry(..)
, Match
, QuickSearch
, Score
, Scorer
, buildQuickSearch
, matchesWithThreshold
, topNMatches
)
oneShot
:: (Hashable uid1, Eq uid1, Hashable uid2, Eq uid2)
=> ( QuickSearch uid2
-> Int
-> Scorer
-> String
-> [Match Score (Entry String uid2)]
)
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Score (Entry String uid2)])]
oneShot :: (QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)])
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
oneShot QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)]
f Int
n [(String, uid1)]
entries [(String, uid2)]
targets Scorer
scorer =
let qs :: QuickSearch uid2
qs = [(String, uid2)] -> QuickSearch uid2
forall uid.
(Hashable uid, Eq uid) =>
[(String, uid)] -> QuickSearch uid
buildQuickSearch [(String, uid2)]
targets
results :: [[Match Int (Entry String uid2)]]
results = ((String, uid1) -> [Match Int (Entry String uid2)])
-> [(String, uid1)] -> [[Match Int (Entry String uid2)]]
forall a b. (a -> b) -> [a] -> [b]
map (QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)]
f QuickSearch uid2
qs Int
n Scorer
scorer (String -> [Match Int (Entry String uid2)])
-> ((String, uid1) -> String)
-> (String, uid1)
-> [Match Int (Entry String uid2)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, uid1) -> String
forall a b. (a, b) -> a
fst) [(String, uid1)]
entries
in [Entry String uid1]
-> [[Match Int (Entry String uid2)]]
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
forall a b. [a] -> [b] -> [(a, b)]
zip (((String, uid1) -> Entry String uid1)
-> [(String, uid1)] -> [Entry String uid1]
forall a b. (a -> b) -> [a] -> [b]
map (String, uid1) -> Entry String uid1
forall name uid. (name, uid) -> Entry name uid
Entry [(String, uid1)]
entries) [[Match Int (Entry String uid2)]]
results
oneShotTopNMatches
:: (Hashable uid1, Eq uid1, Hashable uid2, Eq uid2)
=> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Score (Entry String uid2)])]
oneShotTopNMatches :: Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
oneShotTopNMatches = (QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)])
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
forall uid1 uid2.
(Hashable uid1, Eq uid1, Hashable uid2, Eq uid2) =>
(QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)])
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
oneShot QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)]
forall uid.
(Hashable uid, Eq uid) =>
QuickSearch uid
-> Int -> Scorer -> String -> [Match Int (Entry String uid)]
topNMatches
oneShotMatchesWithThreshold
:: (Hashable uid1, Eq uid1, Hashable uid2, Eq uid2)
=> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Score (Entry String uid2)])]
oneShotMatchesWithThreshold :: Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
oneShotMatchesWithThreshold = (QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)])
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
forall uid1 uid2.
(Hashable uid1, Eq uid1, Hashable uid2, Eq uid2) =>
(QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)])
-> Int
-> [(String, uid1)]
-> [(String, uid2)]
-> Scorer
-> [(Entry String uid1, [Match Int (Entry String uid2)])]
oneShot QuickSearch uid2
-> Int -> Scorer -> String -> [Match Int (Entry String uid2)]
forall uid.
(Hashable uid, Eq uid) =>
QuickSearch uid
-> Int -> Scorer -> String -> [Match Int (Entry String uid)]
matchesWithThreshold