Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. neighbours :: PairsTally -> String -> WordTally
  2. neighbours [] _ = []
  3. neighbours [((string1, string2), n)] string
  4. | string == string1 = [(string, n)]
  5. | string == string2 = [(string, n)]
  6. | otherwise = []
  7.  
  8. mostCommonNeighbour :: PairsTally -> String -> WordTally
  9. mostCommonNeighbour = mostCommonNeighbour1 . neighbours
  10.  
  11. [("bear",2),("dog",1)]
  12.  
  13. mostCommonNeighbour1 :: [(String, Int)] -> String -> MaybeString
  14. mostCommonNeighbour1 [] _ = "Nothing"
  15. mostCommonNeighbour1 (x:[]) word = fst x
  16. mostCommonNeighbour1 list@(x:xs) word = fst (fst (sortOn snd list))
  17.  
  18.  
  19.  
  20.  
  21.  
  22. mostCommonNeighBour1 :: [(String, Int)] -> String -> (String, Int) -> Maybe String
  23. mostCommonNeighbour1 [] word _ = []
  24. mostCommonNeighbour1 _ "" _ = []
  25. mostCommonNeighbour1 (x:xs) word acc
  26. | word /= fst x && xs == [] = if snd acc == 0 then "Nothing" else fst acc
  27. | word /= fst x = mostCommonNeighbour1 xs
  28. | word == fst x = if snd x > snd acc then acc1 = x in mostCommonNeighbor xs word acc1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement