Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DU zarovnani textu - 5b pg. 39
- -- index - 5b pg. 57 fce. lines, words
- import Data.List
- import Data.String
- txt :: String
- txt = "The spherical k-means algorithm, i.e., the k-means algorithm with cosine similarity, is a popular method for clustering high-dimensional text data. In this algorithm, each document as well as each cluster mean is represented as a high-dimensional unit-length vector. However, it has been mainly used in hatch mode. Thus is, each cluster mean vector is updated, only after all document vectors being assigned, as the (normalized) average of all the document vectors assigned to that cluster. This paper investigates an online version of the spherical k-means algorithm based on the well-known winner-take-all competitive learning. In this online algorithm, each cluster centroid is incrementally updated given a document. We demonstrate that the online spherical k-means algorithm can achieve significantly better clustering results than the batch version, especially when an annealing-type learning rate schedule is used. We also present heuristics to improve the speed, yet almost without loss of clustering quality."
- getwords :: [Char] -> [[Char]]
- getwords w = words w
- -- words, max poc znk, poc znaku, vystup , pole vystupu---- 80 znaku optimal
- makeLines :: [[Char]] ->Int-> Int -> [Char] -> [[Char]] -> [[Char]]
- makeLines [] _ _ [] otp=otp
- makeLines [] _ _ vystup otp=(otp ++ [vystup])
- makeLines (x:xs) mxpoc poc vystup otp =if (muzuPridat mxpoc poc x) then
- (makeLines xs mxpoc (poc+(length x)) (vystup ++ (if poc==0 then x else (" "++x))) otp)
- else (makeLines xs mxpoc (length x) x (otp ++ [vystup]))
- muzuPridat :: Int-> Int->[Char]->Bool
- muzuPridat mxpoc poc slovo =if ((length slovo)+poc)<=mxpoc then True else False
- -- radek, max pocet znaku, zacatek=true/konec=false
- pridejMezery :: [Char] -> Int ->Bool -> [Char]
- pridejMezery r mxp lr =if lr then
- (if (length r)<mxp then (pridejMezery (concat (" ":[r])) mxp lr) else r)
- else (if (length r)<mxp then (pridejMezery (r++" ") mxp lr) else r)
- -- mapM_ putStrLn a
- formatLeft :: [[Char]] -> Int -> [[Char]]-> [[Char]]
- formatLeft [] _ otp = otp
- formatLeft (x:xs) mxp otp = formatLeft xs mxp (otp ++ [(pridejMezery x mxp False)])
- formatRight :: [[Char]] -> Int -> [[Char]]-> [[Char]]
- formatRight [] _ otp = otp
- formatRight (x:xs) mxp otp = formatRight xs mxp (otp ++ [(pridejMezery x mxp True)])
- zarovnejVlevo :: [Char] -> IO()
- zarovnejVlevo x= mapM_ putStrLn (formatLeft (makeLines (getwords x) 80 0 [] [[]] ) 100 [])
- zarovnejVpravo :: [Char] -> IO()
- zarovnejVpravo x= mapM_ putStrLn (formatRight (makeLines (getwords x) 80 0 [] [[]] ) 100 [])
- ------ Index
- printIndexes :: [Char] -> Int -> IO()--
- printIndexes t mp= mapM_ (putStrLn) ([x | x<-("Line -> Word":(getIndexes (makeLines (getwords t) 80 0 [] [[]]) 0 mp [] )),filterEmpty x] )
- filterEmpty :: [Char] -> Bool
- filterEmpty x = if (length x) >0 then True else False
- -- "makelines" Line PocZnkIndex tmpOut
- getIndexes :: [[Char]] -> Int -> Int -> [[Char]] ->[[Char]]
- getIndexes [] _ _ otp=otp
- getIndexes (line:lines) lineNum pocZnk otp =
- getIndexes lines (lineNum+1) pocZnk (otp ++ (getInxLine (words line) lineNum pocZnk [[]] ))
- -- line lineNum pocZnk line/word
- getInxLine :: [[Char]] -> Int -> Int -> [[Char]] ->[[Char]]
- getInxLine [] _ _ otp=otp
- getInxLine (line:lines) lineNum numZnk otp =
- getInxLine lines lineNum numZnk (if (length line)==numZnk
- then (otp ++ [stripChars ".," (concat ((show lineNum ++ " -> ") :[line]))])
- else otp)
- stripChars :: String -> String -> String
- stripChars = filter . flip notElem
- main::IO()
- main = do
- putStr "d"
- -- ZarovnejVlevo txt
- -- ZarovnejVpravo txt
- --printIndexes txt 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement