diff options
Diffstat (limited to '')
| -rw-r--r-- | app/Util.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/app/Util.hs b/app/Util.hs index 094f229..ee8a5e6 100644 --- a/app/Util.hs +++ b/app/Util.hs @@ -23,9 +23,10 @@ import qualified Data.Vector as V import Text.FuzzyFind (Alignment (score), bestMatch) -data MatchResult a b +data MatchResult a b c = Exact a | Fuzzy b + | Ambiguous [c] | None deriving Show @@ -41,18 +42,22 @@ data DoubleMap code long = DoubleMap , back :: Map long code } -findStationName :: T.Text -> FuzzySet -> MatchResult (Double, Text) (Double, Text) +findStationName :: T.Text -> FuzzySet -> MatchResult (Double, Text) (Double, Text) (Double, Text) findStationName query set = case sorted of [exact] -> Exact exact _ -> case maybeHbf of station:_ -> Fuzzy station _ -> case results of - station:_ -> Fuzzy station - _ -> None + [] -> None + [station] -> Fuzzy station + s1:s2:_ + | fst s1 - fst s2 < 10 -> Ambiguous $ (takeWhile ((> fst s1 - 10) . fst) results) + | otherwise -> Fuzzy s1 where sorted = results & fmap (\(_, match) -> (fromIntegral . maybe 0 score . bestMatch (T.unpack query) $ T.unpack match, match)) & sortOn (Down . fst) + -- check if difference between first two is <10 or such results = find query set maybeHbf = filter (T.isInfixOf "Hbf" . snd) sorted @@ -102,7 +107,8 @@ readData = do putStrLn "Static data ready." let betriebsstellenFiltered = betriebsstellen - & V.filter (\line -> line !! 4 `notElem` ["BUSH", "LGR", "ÜST", "BFT", "ABZW", "BK", "AWAN", "ANST", "LGR"]) + & V.filter (\line -> line !! 4 `notElem` ["BUSH", "LGR", "ÜST", "ABZW", "BK", "AWAN", "ANST", "LGR"] + && line !! 5 `notElem` [ "TrSt" ]) let ril100set = addMany (V.toList (V.map (!! 2) betriebsstellenFiltered)) (emptySet 5 6 False) let ril100map = mkDoubleMap $ fmap (\line -> (Ril100 (line !! 1), line !! 2)) betriebsstellen |
