import React, { useState } from "react"; import * as T from "../types"; import InlinePs from "../components/src/InlinePs"; import EntrySelect from "../components/src/EntrySelect"; import * as tp from "../lib/src/type-predicates"; import nounsAdjsUnsafe from "../nouns-adjs"; import { inflectWord } from "../lib/src/pashto-inflector"; import { getInflectionPattern } from "../lib/src/inflection-pattern"; import InflectionsTable from "../components/src/InflectionsTable"; import HumanReadableInflectionPattern from "../components/src/HumanReadableInflectionPattern"; import leftChevron from "./chevron_left-24px.svg"; import rightChevron from "./chevron_right-24px.svg"; const chevStyle = { height: "2rem", width: "2rem", color: "#ccc", }; const nounsAdjs = nounsAdjsUnsafe .filter(x => tp.isNounEntry(x) || tp.isAdjectiveEntry(x)) as (T.NounEntry | T.AdjectiveEntry)[]; function InflectionDemo({ opts }: { opts: T.TextOptions, }) { const [pattern, setPattern] = useState("all"); const [word, setWord] = useState(undefined) const patterns: { value: T.InflectionPattern | "all", label: JSX.Element | string, }[] = [ { value: "all", label: "all types", }, { value: 0, label: "no inflection", }, { value: 1, label: "basic", }, { value: 2, label: <>unstressed {{ p: "ی", f: "ey" }}, }, { value: 3, label: <>stressed {{ p: "ی", f: "éy" }}, }, { value: 4, label: '"Pashtoon" pattern', }, { value: 5, label: "short squish", }, { value: 6, label: <>fem. inan. {{ p: "ي", f: "ee" }}, }, ]; const entries = (nounsAdjs as (T.NounEntry | T.AdjectiveEntry)[]).filter(tp.isPattern(pattern)) function handlePatternChange(e: React.ChangeEvent) { const v = e.target.value; const value = v === "all" ? v : (Number(v) as T.InflectionPattern); setPattern(value); console.log({ word }); if (word && !tp.isPattern(value)(word)) { setWord(undefined); } } function wordForward() { if (!word) { setWord(entries[0]); return; } const oldIndex = entries.findIndex(e => e.ts === word.ts); const newIndex = entries.length === (oldIndex + 1) ? 0 : (oldIndex + 1); setWord(entries[newIndex]); } function wordBack() { if (!word) { setWord(entries[entries.length - 1]); return; } const oldIndex = entries.findIndex(e => e.ts === word.ts); const newIndex = oldIndex === 0 ? (entries.length - 1) : (oldIndex + 1); setWord(entries[newIndex]); } const inf = ((): T.InflectorOutput | false => { if (!word) return false; try { return inflectWord(word); } catch (e) { console.error("error inflecting entry", word); return false; } })(); return

Produces the inflections and plural forms (Pashto and Arabic plurals where applicable) for words

Filter words by inflection pattern:
{patterns.map(({ value, label}) => (
))}
Select word:
{"previous"} {"next"}
{inf ?
{inf.inflections && word && (() => { const pattern = getInflectionPattern(word); return ; })()} {"plural" in inf && inf.plural !== undefined &&
Plural
} {"arabicPlural" in inf && inf.arabicPlural !== undefined &&
Arabic Plural
}
:
}
; } function inflectionSubUrl(pattern: T.InflectionPattern): string { return pattern === 0 ? "" : pattern === 1 ? "#1-basic" : pattern === 2 ? "#2-words-ending-in-an-unstressed-ی---ey" : pattern === 3 ? "#3-words-ending-in-a-stressed-ی---éy" : pattern === 4 ? "#4-words-with-the-pashtoon-pattern" : pattern === 5 ? "#5-shorter-words-that-squish" // : pattern === 6 : "#6-inanimate-feminine-nouns-ending-in-ي---ee" } export default InflectionDemo;