packages feed

wordchoice 0.1.0.3 → 0.1.0.4

raw patch · 4 files changed

+21/−17 lines, 4 files

Files

README.md view
@@ -25,7 +25,6 @@  $ wordchoice test/ulysses.txt -n10 -o distribution.html ``` - ## Installation  ### Manual
src/Data/Text/WordCount.hs view
@@ -16,7 +16,7 @@ import qualified Data.Map.Lazy as M import Data.Map.Lens import Control.Lens hiding (argument)-import qualified Data.Text as TL -- .Lazy as TL+import qualified Data.Text as T import Data.Tuple import Data.Monoid import Data.List@@ -25,6 +25,7 @@ import Graphics.Rendering.Chart.Backend.Diagrams import Data.Char import Data.Text.WordCount.FileRead+import Graphics.Rendering.Chart.State  -- | Return top n words and their frequencies --@@ -32,21 +33,21 @@ -- >>> topN 2 "hello hello goodbye it is time is it why why why it it" -- [(4,"it"),(3,"why")] -- @-topN :: Int -> TL.Text -> [(Int,TL.Text)]+topN :: Int -> T.Text -> [(Int,T.Text)] topN n = take n . order . buildFreq -displayWords :: [(Int,TL.Text)] -> TL.Text+displayWords :: [(Int,T.Text)] -> T.Text displayWords [] = "" displayWords (pair:pairs) = display pair <> "\n" <> displayWords pairs-    where display (n,str) = (TL.pack . show) n <> ": " <> str+    where display (n,str) = (T.pack . show) n <> ": " <> str -buildFreq :: TL.Text -> M.Map TL.Text Int-buildFreq = count . TL.words . TL.map toLower+buildFreq :: T.Text -> M.Map T.Text Int+buildFreq = count . T.words . T.map toLower -order :: M.Map TL.Text Int -> [(Int, TL.Text)]+order :: M.Map T.Text Int -> [(Int, T.Text)] order = sortBy (flip (comparing fst)) . fmap swap . M.toList -count :: [TL.Text] -> M.Map TL.Text Int+count :: [T.Text] -> M.Map T.Text Int count words = foldr ((.) . wordFunction) id words M.empty     where wordFunction word map = case map ^. at word of             Nothing -> at word ?~ 1 $ map@@ -58,12 +59,14 @@ -- makeFile :: IO () -- makeFile [(4,"it"),(3,"why")] "out.html" -- @-makeFile :: [(Int,TL.Text)] -> FilePath -> IO ()+makeFile :: BarsPlotValue a => [(a, T.Text)] -> FilePath -> IO () makeFile points out = toFile def out (makeDistribution points) +-- | Make a plot from values +makeDistribution :: BarsPlotValue a => [(a, T.Text)] -> EC (Layout PlotIndex a) () makeDistribution points = do     let values = addIndexes (fmap fst points)-    let alabels = fmap (TL.unpack . snd) points+    let alabels = fmap (T.unpack . snd) points     let fillStyle = solidFillStyle (opaque lightblue)     layout_title .= "Word Frequencies"     layout_x_axis . laxis_generate .= autoIndexAxis alabels
src/Data/Text/WordCount/Exec.hs view
@@ -19,7 +19,7 @@ program = Program     <$> (many (argument str         (metavar "FILEPATH"-        <> help "File to analyze")))+        <> help "Files to analyze together")))     <*> (optional (read <$> strOption         (short 'n'         <> long "number"
wordchoice.cabal view
@@ -1,5 +1,5 @@ name:                wordchoice-version:             0.1.0.3+version:             0.1.0.4 synopsis:            Get word counts and distributions description:         A command line tool to compute the word distribution from various types of document, converting to text with pandoc. homepage:            https://github.com/githubuser/wordchoice#readme@@ -16,6 +16,11 @@                    , release.nix cabal-version:       >=1.10 +Flag llvm-fast {+  Description: Enable build with llvm backend+  Default: False+}+ library   hs-source-dirs:      src   exposed-modules:     Data.Text.WordCount@@ -60,10 +65,7 @@   build-depends:    base                   , criterion                   , wordchoice-  if flag(llvm-fast)-    ghc-options:       -threaded -rtsopts -with-rtsopts=-N -fllvm -optlo-O3 -O3-  else-    ghc-options:       -threaded -rtsopts -with-rtsopts=-N -O3+  ghc-options:       -threaded -rtsopts -with-rtsopts=-N -O3   default-language: Haskell2010  source-repository head