module Helpers
(mkCrossValScheme
, queueTake
, stopWords)
where
import qualified Data.PSQueue as PS
import qualified Data.Vector as V
import Debug.Trace
import System.IO.Unsafe
stopWordsFile :: FilePath
stopWordsFile = "../dutch-stop-words.txt"
stopWords :: [String]
stopWords = lines file
where file = unsafePerformIO $ readFile stopWordsFile
mkCrossValScheme :: (Eq a) => [V.Vector a] -> [(V.Vector a,V.Vector a)]
mkCrossValScheme xs = map (leaveOneOut xs) xs
leaveOneOut :: (Eq a) => [V.Vector a] -> V.Vector a -> (V.Vector a,V.Vector a)
leaveOneOut all test = (test, V.concat $ filter (/= test) all)
queueTake :: (Ord k, Ord p, Show k) => Int -> PS.PSQ k p -> [k]
queueTake k queue = queueTake' k queue []
queueTake' :: (Ord k, Ord p) => Int -> PS.PSQ k p -> [k] -> [k]
queueTake' 0 _ acc = acc
queueTake' k queue acc = case mini of
Nothing -> []
Just m -> queueTake' (k 1) (PS.deleteMin queue) (PS.key m:acc)
where mini = PS.findMin queue