Skip to content

Commit 90103e2

Browse files
committed
update threshold to round number and simplify do rolling shuffle instead of erroring on large output number
1 parent 938bac9 commit 90103e2

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {
2222
} from "./settings_frontend.ts";
2323
import { translate } from "./translator/translator.ts";
2424

25-
const DICTIONARY_AUTO_PARSE_THRESHOLD = 5000;
25+
const DICTIONARY_AUTO_PARSE_THRESHOLD = 5_000;
2626
const INITIAL_PAGE_SIZE = 100;
27-
const MAX_PAGE_SIZE = 25248;
27+
const MAX_PAGE_SIZE = 20_000;
2828

2929
// never change this
3030
const DICTIONARY_KEY = "dictionary";

src/translator/translator.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { randomIntegerBetween } from "@std/random/integer-between";
12
import { shuffle } from "@std/random/shuffle";
23
import { IterableResult, ResultError } from "../compound.ts";
34
import { parser } from "../parser/parser.ts";
@@ -6,7 +7,7 @@ import * as EnglishComposer from "./composer.ts";
67
import { fixMultipleSentences } from "./fixer.ts";
78
import { multipleSentences } from "./sentence.ts";
89

9-
const RANDOMIZATION_LIMIT = 25248;
10+
const RANDOMIZATION_LIMIT = 20_000;
1011

1112
export function translate(tokiPona: string): IterableResult<string> {
1213
return new IterableResult([], function* () {
@@ -20,16 +21,15 @@ export function translate(tokiPona: string): IterableResult<string> {
2021
const unique: Set<string> = new Set();
2122
if (settings.randomize) {
2223
for (const result of iterableResult) {
23-
if (unique.size > RANDOMIZATION_LIMIT) {
24-
yield {
25-
type: "error",
26-
error: new ResultError("too many output to shuffle"),
27-
};
28-
return;
29-
}
3024
switch (result.type) {
3125
case "value":
3226
unique.add(result.value);
27+
if (unique.size > RANDOMIZATION_LIMIT) {
28+
const sample = [...unique];
29+
const value = sample[randomIntegerBetween(0, sample.length)];
30+
unique.delete(value);
31+
yield { type: "value", value };
32+
}
3333
break;
3434
case "error":
3535
aggregateErrors.push(result.error);

0 commit comments

Comments
 (0)