shoot unisex nouns are a bit buggy/crashy, need to fix those up before releasing further

This commit is contained in:
lingdocs 2021-10-09 22:48:14 -04:00
parent 723cf331f9
commit e2cae7638b
4 changed files with 100 additions and 50 deletions

View File

@ -4,6 +4,7 @@ import {
defaultTextOptions as opts,
VerbTable,
removeFVarients,
getEnglishWord,
} from "@lingdocs/pashto-inflector";
import {
equativeMachine,
@ -17,11 +18,18 @@ import {
} from "../lib/equative-machine";
import words from "../words/nouns-adjs";
function uniqueSort(arr: AdjectiveInput[]): AdjectiveInput[];
function uniqueSort(arr: UnisexNounInput[]): UnisexNounInput[];
function uniqueSort(arr: (AdjectiveInput | UnisexNounInput)[]): (AdjectiveInput | UnisexNounInput)[] {
return arr
.filter((v, i, a) => a.findIndex((e) => e.ts === v.ts) === i)
.sort((a, b) => a.p.localeCompare(b.p));
}
const inputs = {
adjectives: words.filter((w) => isAdjectiveInput(w.entry as EntityInput))
.map((w) => w.entry as AdjectiveInput).sort((a, b) => a.p.localeCompare(b.p)),
unisexNouns: words.filter((w) => isUnisexNounInput(w.entry as EntityInput))
.map((w) => w.entry as UnisexNounInput).sort((a, b) => a.p.localeCompare(b.p)),
adjectives: uniqueSort(words.filter((w) => isAdjectiveInput(w.entry as EntityInput))
.map((w) => w.entry as AdjectiveInput)),
unisexNouns: uniqueSort(words.filter((w) => isUnisexNounInput(w.entry as EntityInput))
.map((w) => w.entry as UnisexNounInput)),
};
function makeBlock(e: PredicateInput): T.VerbBlock {
@ -40,12 +48,26 @@ function makeBlock(e: PredicateInput): T.VerbBlock {
}
type PredicateType = "adjectives" | "unisexNouns";
// type SubjectType = "pronouns" | "nouns";
// TODO: Plural nouns like shoode
const defaultTs = 1527815306;
const defaultPe = inputs.adjectives.find(a => a.ts === defaultTs) as AdjectiveInput;
function EquativeExplorer() {
// TODO: Use sticky state
const predicateTypes: PredicateType[] = ["adjectives", "unisexNouns"];
const [predicate, setPredicate] = useState<number>(1527815306);
const predicateTypes: PredicateType[] = ["adjectives", "unisexNouns"];
// const subjectTypes: SubjectType[] = ["pronouns", "nouns"];
const [predicate, setPredicate] = useState<number>(defaultTs);
// const [subjectType, setSubjectType] = useState<SubjectType>("pronouns");
const [predicateType, setPredicateType] = useState<PredicateType>("adjectives");
function makeOptionLabel(e: T.DictionaryEntry): string {
const eng = getEnglishWord(e);
// @ts-ignore - with dumb old typescript
const english = typeof eng === "string" ? eng : eng.plural;
return `${e.p} - ${removeFVarients(e.f)} (${english})`;
}
function handlePredicateSelect(e: React.ChangeEvent<HTMLSelectElement>) {
setPredicate(parseInt(e.target.value));
}
@ -58,50 +80,79 @@ function EquativeExplorer() {
const pe = (inputs[predicateType].find((a: AdjectiveInput | UnisexNounInput) => (
a.ts === predicate
))) as PredicateInput;
console.log("pe is", pe);
const block = makeBlock(pe);
const block = (() => {
try {
return makeBlock(pe);
} catch (e) {
console.error("error making equative");
console.error(e);
setPredicate(defaultTs);
setPredicateType("adjectives");
return makeBlock(defaultPe);
}
})();
return <>
<div className="form-group">
<label htmlFor="predicate-select"><strong>Predicate:</strong></label>
<div className="form-check">
<input
className="form-check-input"
type="radio"
name="adjectivesPredicateRadio"
id="adjectivesPredicateRadio"
value={predicateTypes[0]}
checked={predicateType === "adjectives"}
onChange={handlePredicateTypeSelect}
/>
<label className="form-check-label" htmlFor="adjectivesPredicateRadio">
Adjectives
</label>
<div className="d-flex flex-row">
{/* <div className="form-group">
<label htmlFor="subject-select"><strong>Subject:</strong></label>
<div className="form-check">
<input
className="form-check-input"
type="radio"
name="pronounsSubjectRadio"
id="pronounsSubjectRadio"
value={subjectTypes[0]}
checked={subjectType === "pronouns"}
onChange={handlePredicateTypeSelect}
/>
<label className="form-check-label" htmlFor="adjectivesPredicateRadio">
Pronouns
</label>
</div>
</div> */}
<div className="form-group">
<label htmlFor="predicate-select"><strong>Predicate:</strong></label>
<div className="form-check">
<input
className="form-check-input"
type="radio"
name="adjectivesPredicateRadio"
id="adjectivesPredicateRadio"
value={predicateTypes[0]}
checked={predicateType === "adjectives"}
onChange={handlePredicateTypeSelect}
/>
<label className="form-check-label" htmlFor="adjectivesPredicateRadio">
Adjectives
</label>
</div>
{/* hiding this because it's a bit buggy still */}
<div className="form-check mb-2" style={{ display: "none" }}>
<input
className="form-check-input"
type="radio"
name="unisexNounsPredicateRadio"
id="unisexNounsPredicateRadio"
value={predicateTypes[1]}
checked={predicateType === "unisexNouns"}
onChange={handlePredicateTypeSelect}
/>
<label className="form-check-label" htmlFor="unisexNounsPredicateRadio">
Unisex Nouns
</label>
</div>
<select
className="form-control"
id="predicate-select"
value={predicate}
onChange={handlePredicateSelect}
>
{inputs[predicateType].map((e: AdjectiveInput | UnisexNounInput) => (
<option key={e.ts+"s"} value={e.ts}>{makeOptionLabel(e)}</option>
))}
</select>
</div>
<div className="form-check mb-2">
<input
className="form-check-input"
type="radio"
name="unisexNounsPredicateRadio"
id="unisexNounsPredicateRadio"
value={predicateTypes[1]}
checked={predicateType === "unisexNouns"}
onChange={handlePredicateTypeSelect}
/>
<label className="form-check-label" htmlFor="unisexNounsPredicateRadio">
Unisex Nouns
</label>
</div>
<select
className="form-control"
id="predicate-select"
value={predicate}
onChange={handlePredicateSelect}
>
{inputs[predicateType].map((e: AdjectiveInput | UnisexNounInput) => (
<option key={e.ts+"s"} value={e.ts}>{e.p} - {removeFVarients(e.f)}</option>
))}
</select>
</div>
<VerbTable textOptions={opts} block={block} />
</>;

View File

@ -4,6 +4,6 @@ title: Equative Explorer 🌎
import EquativeExplorer from "../../components/EquativeExplorer";
This is in progress... will be able to explore much more soon. 👷‍♂️
This is in progress and a bit buggy... will be able to explore much more soon. 👷‍♂️
<EquativeExplorer />

View File

@ -122,7 +122,6 @@ module.exports = [
{ ts: 1527814373, e: "lost" }, // ورک - wruk
{ ts: 1527822838, e: "decayed, spoiled, rotten" }, // وروست - wrost
{ ts: 1609949334478, e: "roasted" }, // وریت - wreet
{ ts: 1527823106, e: "cheerful" }, // ورین - wreen
{ ts: 1527811544, e: "standing" }, // ولاړ - waláaR, wuláaR
{ ts: 1527815498, e: "aforementioned" }, // یاد - yaad
{ ts: 1527815434, e: "cold" }, // یخ - yakh, yukh

File diff suppressed because one or more lines are too long