<commit_before>
module HarmLang.HarmonyDistributionModel
where

import HarmLang.Types

import Data.Map

--DIST:

type (Dist Chord) ChordDistribution

type Double Probability



--HarmonyDistributionModel



--A few helper functions:


sliceKmers :: Int -> ChordProgression -> [ChordProgression]
sliceKmers i h:hs = if length h:hs < i then [] else (take i h:hs) : (sliceKmers i hs)

k :: Int
k = 3

data HarmonyDistributionModel = HarmonyDistributionModel Integer (Data.Map ChordProgression ChordDistribution) --Double (ChordProgression -> Double) (Map ChordProgression Chord)
--type HarmDistModel HarmonyDistributionModel

type HarmonyDistributionModel HDM

buildHarmonyDistributionModel :: [ChordProgression] -> Integer -> HarmonyDistributionModel
buildHarmonyDistributionModel cpArr k =
  let listVals = foldr (++) [] (map (\ cp -> (map (\ kmer -> (take k kmer, last kmer) (sliceKmers (k + 1))  ))) cpArr) --TODO this is slow.
      listValLists = map (\ (key, val) -> (key, [val])) listVals
      mapAll = Data.Map.fromListWith (++) listValLists
      --mapAllSorted = map List.sort mapAll
      mapAllDist = map equally mapAll
  in mapAllDist
    

hdmChoose :: Double -> HDM -> HDM -> HDM
hdmChoose = error "No hdm choose."

--TODO Switch to pattern matching
hdmAskK :: HDM -> Integer
hdmAskK (k _) = k

-- chord progression must be of length k
distAfter :: HDM -> ChordProgression -> Dist Chord
distAfter hdm cp = if length cp /= k then error "bad cp length" else
  case (findKey cp hdm) of<commit_msg>Partially fixed HarmonyDistributionModel<commit_after>
module HarmLang.HarmonyDistributionModel
where

import HarmLang.Types

import HarmLang.Probability

import qualified Data.Map 

--DIST:

type ChordDistribution = (Dist Chord)

type Probability = Double



--HarmonyDistributionModel



--A few helper functions:


sliceKmers :: Int -> ChordProgression -> [ChordProgression]
sliceKmers i (h:hs) = if length h:hs < i then [] else (take i h:hs) : (sliceKmers i hs)

k :: Int
k = 3

data HarmonyDistributionModel = HarmonyDistributionModel Integer (Data.Map.Map ChordProgression ChordDistribution) --Double (ChordProgression -> Double) (Map ChordProgression Chord)
--type HarmDistModel HarmonyDistributionModel

type HDM = HarmonyDistributionModel

buildHarmonyDistributionModel :: [ChordProgression] -> Integer -> HarmonyDistributionModel
buildHarmonyDistributionModel cpArr kVal =
  let listVals = foldr (++) [] (map (\ cp -> (map (\ kmer -> (take kVal kmer, last kmer) (sliceKmers (kVal + 1))  ))) cpArr) --TODO this is slow.
      listValLists = map (\ (key, val) -> (key, [val])) listVals
      mapAll = Data.Map.fromListWith (++) listValLists
      --mapAllSorted = map List.sort mapAll
      mapAllDist = Data.Map.map equally mapAll
  in mapAllDist
    

hdmChoose :: Double -> HDM -> HDM -> HDM
hdmChoose = error "No hdm choose."

--TODO Switch to pattern matching
hdmAskK :: HDM -> Integer
hdmAskK kVal _ = kVal

-- chord progression must be of length k
distAfter :: HDM -> ChordProgression -> Dist Chord
distAfter (_ hdmMap) cp = if length cp /= k then error "bad cp length" else
  case (Data.Map.(!) cp hdmMap) of
{'fraction_non_alphanumeric': 0.1040868454661558, 'fraction_numerical': 0.001277139208173691, 'mean_word_length': 3.9572784810126582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5887469', 'n_tokens_mistral': 1039, 'n_tokens_neox': 976, 'n_words': 326}