-
Notifications
You must be signed in to change notification settings - Fork 2
/
ithkuil-perf.ts
155 lines (136 loc) · 3.43 KB
/
ithkuil-perf.ts
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import {
ALL_AFFILIATIONS,
ALL_AFFIX_DEGREES,
ALL_ASPECTS,
ALL_CASE_SCOPES,
ALL_CASES,
ALL_CONFIGURATIONS,
ALL_CONTEXTS,
ALL_EFFECTS,
ALL_ESSENCES,
ALL_EXTENSIONS,
ALL_FUNCTIONS,
ALL_ILLOCUTION_OR_VALIDATIONS,
ALL_LEVELS,
ALL_MOODS,
ALL_PERSPECTIVES,
ALL_PHASES,
ALL_REFERENTS,
ALL_SPECIFICATIONS,
ALL_STEMS,
ALL_VALENCES,
ALL_VERSIONS,
formativeToIthkuil,
type Affix,
type SlotIII,
ALL_AFFIX_TYPES,
type PartialCA,
} from "@zsnout/ithkuil/generate"
import { randomItem } from "./random-item.js"
import { readFileSync } from "fs"
import { parseFormative } from "@zsnout/ithkuil/parse/index.js"
export function generate() {
function cs(): string {
let output = randomItem("bcčdḑfgjklmnňprřsštţvxz")
while (Math.random() < 0.5) {
output += randomItem(
"bcčdḑfghjklļmnňprřsštţvxz".replace(output.at(-1)!, ""),
)
}
return output
}
function referent() {
return randomItem(ALL_REFERENTS)!
}
function root(): SlotIII {
if (Math.random() < 0.25) {
return { cs: cs(), degree: randomItem(ALL_AFFIX_DEGREES)! }
}
if (Math.random() < 0.33) {
return [referent()]
}
if (Math.random() < 0.5) {
return Math.floor(Math.random() * 10000)
}
return cs()
}
function ca(): PartialCA {
return {
affiliation: randomItem(ALL_AFFILIATIONS),
configuration: randomItem(ALL_CONFIGURATIONS),
extension: randomItem(ALL_EXTENSIONS),
perspective: randomItem(ALL_PERSPECTIVES),
essence: randomItem(ALL_ESSENCES),
}
}
function affix(): Affix {
if (Math.random() < 0.2) {
return { case: randomItem(ALL_CASES)! }
}
if (Math.random() < 0.25) {
return {
case: randomItem(ALL_CASES)!,
isInverse: randomItem([true, false]),
type: randomItem(ALL_AFFIX_TYPES)!,
}
}
if (Math.random() < 0.33) {
return { ca: ca() }
}
return {
cs: cs(),
degree: randomItem(ALL_AFFIX_DEGREES)!,
type: randomItem([1, 2])!,
}
}
function affixes(): Affix[] {
const output: Affix[] = []
while (Math.random() < 0.25) {
output.push(affix())
}
return output
}
return formativeToIthkuil({
root: root(),
type: randomItem(["UNF/C", "UNF/K", "FRM"]),
concatenationType: randomItem([1, 2, "none"]),
caseScope: randomItem(ALL_CASE_SCOPES),
mood: randomItem(ALL_MOODS),
case: randomItem(ALL_CASES),
illocutionValidation: randomItem(ALL_ILLOCUTION_OR_VALIDATIONS),
specification: randomItem(ALL_SPECIFICATIONS),
function: randomItem(ALL_FUNCTIONS),
context: randomItem(ALL_CONTEXTS),
version: randomItem(ALL_VERSIONS),
stem: randomItem(ALL_STEMS),
ca: ca(),
slotVAffixes: affixes(),
slotVIIAffixes: affixes(),
vn: randomItem([
...ALL_VALENCES,
...ALL_PHASES,
...ALL_EFFECTS,
...ALL_LEVELS,
...ALL_ASPECTS,
]),
})
}
export async function genMany(count: number) {
const data = Array.from({ length: count }, generate).join("\n")
const fs = await import("fs")
return fs.writeFileSync("./input.txt", data)
}
const input = readFileSync("./input.txt", "utf8")
const start = Date.now()
input.split("\n").map((x) => {
try {
const result = parseFormative(x)
if (!result) {
throw new Error()
}
} catch (value) {
throw new Error(x + ": " + String(value))
}
})
const end = Date.now()
console.log(end - start)