equative explorer first steps!

This commit is contained in:
lingdocs 2021-10-09 21:38:48 -04:00
parent 4aa3568c72
commit 285efdd026
5 changed files with 138 additions and 12 deletions

View File

@ -0,0 +1,109 @@
import React, { useState } from "react";
import {
Types as T,
defaultTextOptions as opts,
VerbTable,
removeFVarients,
} from "@lingdocs/pashto-inflector";
import {
equativeMachine,
assembleEquativeOutput,
AdjectiveInput,
PredicateInput,
isAdjectiveInput,
EntityInput,
isUnisexNounInput,
UnisexNounInput,
} from "../lib/equative-machine";
import words from "../words/nouns-adjs";
const inputs = {
adjectives: words.filter((w) => isAdjectiveInput(w.entry as EntityInput))
.map((w) => w.entry as AdjectiveInput),
unisexNouns: words.filter((w) => isUnisexNounInput(w.entry as EntityInput))
.map((w) => w.entry as UnisexNounInput),
};
function makeBlock(e: PredicateInput): T.VerbBlock {
const makeP = (p: T.Person): T.ArrayOneOrMore<T.PsString> => {
const b = assembleEquativeOutput(equativeMachine(p, e));
return ("long" in b ? b.long : b) as T.ArrayOneOrMore<T.PsString>;
};
return [
[makeP(0), makeP(6)],
[makeP(1), makeP(7)],
[makeP(2), makeP(8)],
[makeP(3), makeP(9)],
[makeP(4), makeP(10)],
[makeP(5), makeP(11)],
];
}
type PredicateType = "adjectives" | "unisexNouns";
function EquativeExplorer() {
const predicateTypes: PredicateType[] = ["adjectives", "unisexNouns"];
const [predicate, setPredicate] = useState<number>(inputs.adjectives[0].ts);
const [predicateType, setPredicateType] = useState<PredicateType>("adjectives");
function handlePredicateSelect(e: React.ChangeEvent<HTMLSelectElement>) {
setPredicate(parseInt(e.target.value));
}
function handlePredicateTypeSelect(e: React.ChangeEvent<HTMLInputElement>) {
const pt = e.target.value as PredicateType;
setPredicateType(pt);
setPredicate(inputs[pt][0].ts);
}
// @ts-ignore
const pe = (inputs[predicateType].find((a: AdjectiveInput | UnisexNounInput) => (
a.ts === predicate
))) as PredicateInput;
console.log("pe is", pe);
const block = makeBlock(pe);
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>
<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((adj: AdjectiveInput | UnisexNounInput) => (
<option key={adj.ts} value={adj.ts+"s"}>{adj.p} - {removeFVarients(adj.f)}</option>
))}
</select>
</div>
<VerbTable textOptions={opts} block={block} />
</>;
}
export default EquativeExplorer;

View File

@ -0,0 +1,9 @@
---
title: Equative Explorer 🌎
---
import EquativeExplorer from "../../components/EquativeExplorer";
This is in progress... will be able to explore much more soon. 👷‍♂️
<EquativeExplorer />

View File

@ -16,6 +16,8 @@ import * as presentEquative from "!babel-loader!mdx-loader!./equatives/present-e
import * as subjunctiveHabitualEquative from "!babel-loader!mdx-loader!./equatives/subjunctive-habitual-equative.mdx";
// @ts-ignore
import * as otherEquatives from "!babel-loader!mdx-loader!./equatives/other-equatives.mdx";
// @ts-ignore
import * as equativeExplorer from "!babel-loader!mdx-loader!./equatives/equative-explorer.mdx";
// @ts-ignore
import * as nounsGender from "!babel-loader!mdx-loader!./nouns/nouns-gender.mdx";
@ -97,6 +99,10 @@ const contentTree = [
import: otherEquatives,
slug: "other-equatives",
},
{
import: equativeExplorer,
slug: "equative-explorer",
},
],
},
{

View File

@ -131,7 +131,8 @@ function makePronoun(sub: T.Person): T.PsString[] {
function makeUnisexNoun(e: UnisexNounInput, subjPerson: T.Person | undefined): T.PsString[] {
// reuse english from make noun - do the a / an sensitivity
// if it's the predicate - get the inflection according to the subjPerson
const isPredicate = !!subjPerson;
const isPredicate = subjPerson !== undefined;
console.log("making", e, "isPredicate", isPredicate);
if (isPredicate) {
const inf = inflectWord(e);
// TODO: Use if no inflections // FIX THIS
@ -141,12 +142,13 @@ function makeUnisexNoun(e: UnisexNounInput, subjPerson: T.Person | undefined): T
throw Error("improper unisex noun");
}
// if plural // anim // chose that
// otherwise just chose inflection (or add both)
const pashto = ("plural" in inf && personIsPlural(subjPerson))
// otherwise just chose inflection (or add both) // needed for older version of typescript
const pashto = ("plural" in inf && inf.plural !== undefined && personIsPlural(subjPerson || 0))
// @ts-ignore
? inf.plural[personGender(subjPerson)][0] as T.ArrayOneOrMore<T.PsString>
: chooseInflection(inf.inflections, subjPerson);
const english = getEnglishFromNoun(e, personIsPlural(subjPerson), "predicate");
// needed for older version of typescript
: chooseInflection(inf.inflections, subjPerson || 0);
const english = getEnglishFromNoun(e, personIsPlural(subjPerson || 0), "predicate");
return addEnglish(english, pashto);
}
// if it's the subject - TO BE IMPLEMENTED
@ -263,11 +265,11 @@ function getEnglishParticiple(entry: T.DictionaryEntry): string {
: participle;
}
function isPersonInput(e: EntityInput): e is PersonInput {
export function isPersonInput(e: EntityInput): e is PersonInput {
return typeof e === "number";
}
function isNounInput(e: EntityInput): e is NounInput {
export function isNounInput(e: EntityInput): e is NounInput {
if (isPersonInput(e)) return false;
if ("entry" in e && !("gender" in e)) {
// e
@ -276,13 +278,13 @@ function isNounInput(e: EntityInput): e is NounInput {
return false;
}
function isParticipleInput(e: EntityInput): e is ParticipleInput {
export function isParticipleInput(e: EntityInput): e is ParticipleInput {
if (isPersonInput(e)) return false;
if ("entry" in e) return false;
return !!e.c?.startsWith("v.");
}
function isSpecifiedUnisexNounInput(e: EntityInput): e is SpecifiedUnisexNounInput {
export function isSpecifiedUnisexNounInput(e: EntityInput): e is SpecifiedUnisexNounInput {
if (isPersonInput(e)) return false;
if ("entry" in e && "gender" in e) {
// e
@ -291,13 +293,13 @@ function isSpecifiedUnisexNounInput(e: EntityInput): e is SpecifiedUnisexNounInp
return false;
}
function isUnisexNounInput(e: EntityInput): e is UnisexNounInput {
export function isUnisexNounInput(e: EntityInput): e is UnisexNounInput {
if (isPersonInput(e)) return false;
if ("entry" in e) return false;
return !!e.c?.includes("unisex");
}
function isAdjectiveInput(e: EntityInput): e is AdjectiveInput {
export function isAdjectiveInput(e: EntityInput): e is AdjectiveInput {
if (isPersonInput(e)) return false;
if ("entry" in e) return false;
if (isNounInput(e)) return false;

File diff suppressed because one or more lines are too long