Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// We must not crash

const CORPUS_KEY = "infinitype:chosen_corpus";
const DEFAULT_CORPUS = 6;
const initialCorpus =
parseInt(localStorage.getItem(CORPUS_KEY)) || DEFAULT_CORPUS;

const app = Elm.Main.init({
node: document.getElementById("elm"),
flags: {},
flags: { corpus: initialCorpus },
});
const infinitype = document.getElementById("infinitype");

Expand All @@ -12,6 +17,10 @@ const interface = {
prevent: ["ArrowLeft", "ArrowRight"],
};

app.ports.corpusChanged.subscribe(function (corpusIndex) {
localStorage.setItem(CORPUS_KEY, corpusIndex);
});

function notifyWithDefault(event) {
event.preventDefault();
interface.notify(event.key);
Expand Down
32 changes: 32 additions & 0 deletions src/Corpus.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Corpus exposing (..)

import Random exposing (Generator)
import Texts.English1k


type alias Corpus =
{ monosize : Float, name : String, words : String }


defaultCorpus : Corpus
defaultCorpus =
Texts.English1k.corpus


wordBuffer : Int
wordBuffer =
20


makeCorpus : String -> List String
makeCorpus words =
words |> String.split "\n" |> List.filter (not << String.isEmpty)


randomWords : Int -> List String -> Generator (List String)
randomWords count words =
let
fallback =
Maybe.withDefault "EMPTY_CORPUS" (List.head words)
in
Random.list count <| Random.uniform fallback words
Loading