Advertisement
lu4kedr

text format Left/Right

Oct 10th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- DU zarovnani textu - 5b  pg. 39
  2. --    index  - 5b  pg. 57   fce. lines, words
  3. import Data.List
  4.  
  5. import Data.String
  6.  
  7. txt :: String
  8. 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."
  9.  
  10.  
  11. getwords :: [Char] -> [[Char]]
  12. getwords w = words w
  13.  
  14. --           words, max poc znk, poc znaku, vystup , pole vystupu---- 80 znaku optimal
  15. makeLines :: [[Char]] ->Int-> Int -> [Char] -> [[Char]] -> [[Char]]
  16. makeLines [] _ _ [] otp=otp
  17. makeLines [] _ _ vystup otp=(otp ++ [vystup])
  18. makeLines (x:xs) mxpoc poc vystup otp =if (muzuPridat mxpoc poc x) then
  19.     (makeLines xs mxpoc (poc+(length x)) (vystup ++ (if poc==0 then x else (" "++x))) otp)
  20.     else (makeLines xs mxpoc (length x) x (otp ++ [vystup]))
  21.  
  22.  
  23. muzuPridat :: Int-> Int->[Char]->Bool
  24. muzuPridat mxpoc poc slovo =if ((length slovo)+poc)<=mxpoc then True else False
  25.  
  26. --              radek, max pocet znaku, zacatek=true/konec=false
  27. pridejMezery :: [Char] -> Int ->Bool -> [Char]
  28. pridejMezery r mxp lr =if lr then
  29.     (if (length r)<mxp then (pridejMezery (concat (" ":[r])) mxp lr) else r)
  30.     else (if (length r)<mxp then (pridejMezery (r++" ") mxp lr) else r)
  31.  
  32.  
  33. -- mapM_ putStrLn a
  34. formatLeft :: [[Char]] -> Int -> [[Char]]-> [[Char]]
  35. formatLeft [] _ otp = otp
  36. formatLeft (x:xs) mxp otp = formatLeft xs mxp (otp ++ [(pridejMezery x mxp False)])
  37.  
  38. formatRight :: [[Char]] -> Int -> [[Char]]-> [[Char]]
  39. formatRight [] _ otp = otp
  40. formatRight (x:xs) mxp otp = formatRight xs mxp (otp ++ [(pridejMezery x mxp True)])
  41.  
  42. zarovnejVlevo :: [Char] -> IO()
  43. zarovnejVlevo x= mapM_ putStrLn (formatLeft (makeLines (getwords x) 80 0 [] [[]] ) 100 [])
  44.  
  45. zarovnejVpravo :: [Char] -> IO()
  46. zarovnejVpravo x= mapM_ putStrLn (formatRight (makeLines (getwords x) 80 0 [] [[]] ) 100 [])
  47.  
  48.  
  49. ------ Index
  50.  
  51. printIndexes :: [Char] -> Int -> IO()--
  52. printIndexes t mp= mapM_ (putStrLn) ([x | x<-("Line -> Word":(getIndexes (makeLines (getwords t) 80 0 [] [[]]) 0 mp [] )),filterEmpty x] )
  53.  
  54.  
  55. filterEmpty :: [Char] -> Bool
  56. filterEmpty x = if (length x) >0 then True else False
  57.  
  58. --         "makelines"  Line   PocZnkIndex  tmpOut
  59. getIndexes :: [[Char]] -> Int -> Int -> [[Char]] ->[[Char]]
  60. getIndexes [] _ _ otp=otp
  61. getIndexes (line:lines) lineNum pocZnk otp =
  62.     getIndexes lines (lineNum+1) pocZnk (otp ++ (getInxLine (words line) lineNum pocZnk [[]] ))
  63.  
  64.  
  65.  
  66. --            line    lineNum  pocZnk  line/word
  67. getInxLine :: [[Char]] -> Int -> Int -> [[Char]] ->[[Char]]
  68. getInxLine [] _ _ otp=otp
  69. getInxLine (line:lines) lineNum numZnk otp =
  70.     getInxLine lines lineNum numZnk (if (length line)==numZnk
  71.         then (otp ++ [stripChars ".," (concat ((show lineNum ++ " -> ") :[line]))])
  72.         else otp)
  73.  
  74. stripChars :: String -> String -> String
  75. stripChars = filter . flip notElem
  76.  
  77. main::IO()
  78. main = do
  79.   putStr "d"
  80.   -- ZarovnejVlevo txt
  81.   -- ZarovnejVpravo txt
  82.   --printIndexes txt 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement