aboutsummaryrefslogtreecommitdiff
path: root/src/Data.elm
blob: 4708ca16e69c22d4b739dd163851b6985b1c8df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{-
   - This file is part of `typers`.
   -
   - `typers` is free software: you can redistribute it and/or modify
   - it under the terms of the GNU Affero Public License as published by
   - the Free Software Foundation, either version 3 of the License, or
   - (at your option) any later version.
   -
   - `typers` is distributed in the hope that it will be useful,
   - but WITHOUT ANY WARRANTY; without even the implied warranty of
   - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   - GNU Affero Public License for more details.
   -
   - You should have received a copy of the GNU Affero Public License
   - along with `typers`.  If not, see <https://www.gnu.org/licenses/>.
-}


module Data exposing (defaultConfig, randomParagraph)

import Base exposing (Config)
import Random
import Utils exposing (listIdx, triple)


defaultConfig : Config
defaultConfig =
    Config True True 50


textData : List String
textData =
    "the of to and a in is it you that he was for on are with as I his they be at one have this from or had by not word but what some we can out other were all there when up use your how said an each she which do their time if will way about many then them write would like so these her long make thing see him two has look more day could go come did number sound no most people my over know water than call first who may down side been now find any new work part take get place made live where after back little only round man year came show every good me give our under name very through just form sentence great think say help low line differ turn cause much mean before move right boy old too same tell does set three want air well also play small end put home read hand port large spell add even land here must big high such follow act why ask men change went light kind off need house picture try us again animal point mother world near build self earth father head stand own page should country found answer school grow study still learn plant cover food sun four between state keep eye never last let thought city tree cross farm hard start might story saw far sea draw left late run don't while press close night real life few north open seem together next white children begin got walk example ease paper group always music those both mark often letter until mile river car feet care second book carry took science eat room friend began idea fish mountain stop once base hear horse cut sure watch color face wood main enough plain girl usual young ready above ever red list though feel talk bird soon body dog family direct pose leave song measure door product black short numeral class wind question happen complete ship area half rock order fire south problem piece told knew pass since top whole king space heard best hour better true during hundred five remember step early hold west ground interest reach fast verb sing listen six table travel less morning ten simple several vowel toward war lay against pattern slow center love person money serve appear road map rain rule govern pull cold notice voice unit power town fine certain fly fall lead cry dark machine note wait plan figure star box noun field rest correct able pound done beauty drive stood contain front teach week final gave green oh quick develop ocean warm free minute strong special mind behind clear tail produce fact street inch multiply nothing course stay wheel full force blue object decide surface deep moon island foot system busy test record boat common gold possible plane stead dry wonder laugh thousand ago ran check game shape equate hot miss brought heat snow tire bring yes distant fill east paint language among"
        |> String.split " "


punctuations : List String
punctuations =
    ", ! . ? ... ; :" |> String.split " "


falseWeightedBool : Random.Generator Bool
falseWeightedBool =
    Random.weighted ( 5, True ) [ ( 95, False ) ]


randomWord : Config -> Random.Generator ( Int, Bool, Bool )
randomWord config =
    let
        idx =
            Random.int 0 499

        punct =
            if config.punctuation then
                falseWeightedBool

            else
                Random.constant False

        caps =
            if config.capitals then
                falseWeightedBool

            else
                Random.constant False
    in
    Random.map3 triple idx punct caps


capitalize : String -> String
capitalize s =
    (String.toUpper <| String.left 1 s) ++ String.dropLeft 1 s


configureWord : ( Int, Bool, Bool ) -> Random.Generator String
configureWord ( idx, punct, caps ) =
    let
        w =
            listIdx textData idx

        p =
            if punct then
                listIdx punctuations (modBy (List.length punctuations) idx)

            else
                Just ""

        pw =
            Maybe.withDefault "" <| Maybe.map2 (++) w p
    in
    if caps then
        Random.constant <| capitalize pw

    else
        Random.constant pw


randomParagraph : Config -> Random.Generator (List String)
randomParagraph config =
    randomWord config
        |> Random.andThen configureWord
        |> Random.list config.length