This commit is contained in:
lingdocs 2022-08-30 17:57:28 +04:00
parent 07707195b1
commit 02a78b6fcf
8 changed files with 33 additions and 28 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "3.8.4", "version": "3.8.5",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -189,7 +189,7 @@ export const pastEndings: {
], ],
[ [
[{ [{
p: "ۀ", p: "ه",
f: "u" f: "u"
}, },
{ {

View File

@ -8,6 +8,12 @@
import * as T from "../types"; import * as T from "../types";
export const blank: T.PsString = {
p: "_____",
f: "_____",
};
export const kidsBlank: T.PsString = { p: "___", f: "___" };
// just for type safety // just for type safety
export function noPersInfs(s: T.OptionalPersonInflections<T.LengthOptions<T.PsString>>): T.LengthOptions<T.PsString>; export function noPersInfs(s: T.OptionalPersonInflections<T.LengthOptions<T.PsString>>): T.LengthOptions<T.PsString>;
export function noPersInfs(s: T.FullForm<T.PsString>): T.SingleOrLengthOpts<T.PsString>; export function noPersInfs(s: T.FullForm<T.PsString>): T.SingleOrLengthOpts<T.PsString>;

View File

@ -25,16 +25,14 @@ import {
specifyBlockLength, specifyBlockLength,
specifyEquativeLength, specifyEquativeLength,
} from "./blocks-utils"; } from "./blocks-utils";
import {
blank,
kidsBlank,
} from "../../lib/misc-helpers";
export const blank: T.PsString = {
p: "_____",
f: "_____",
};
type BlankoutOptions = { equative?: boolean, ba?: boolean, kidsSection?: boolean, verb?: boolean }; type BlankoutOptions = { equative?: boolean, ba?: boolean, kidsSection?: boolean, verb?: boolean };
export const kidsBlank: T.PsString = { p: "___", f: "___" };
// function compilePs({ blocks, kids, verb: { head, rest }, VP }: CompilePsInput): T.SingleOrLengthOpts<T.PsString[]> { // function compilePs({ blocks, kids, verb: { head, rest }, VP }: CompilePsInput): T.SingleOrLengthOpts<T.PsString[]> {
// if ("long" in rest) { // if ("long" in rest) {
// return { // return {
@ -436,3 +434,4 @@ export function flattenLengths(r: T.SingleOrLengthOpts<T.PsString[] | T.PsString
return [r]; return [r];
} }

View File

@ -251,10 +251,10 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: {
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[] (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[]
> = { > = {
imperfectiveImperative: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([ imperfectiveImperative: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${n ? "don't " : ""}${ec[0]}! (command)`, `$SUBJ ${n ? "don't " : ""}${ec[0]}!`,
]), ]),
perfectiveImperative: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([ perfectiveImperative: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${n ? "don't " : ""}${ec[0]}! (command)`, `$SUBJ ${n ? "don't " : ""}${ec[0]}!`,
]), ]),
}; };
const base = ( const base = (
@ -265,5 +265,6 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: {
: isImperativeTense(vs.tense) : isImperativeTense(vs.tense)
? imperativeBuilders[vs.tense] ? imperativeBuilders[vs.tense]
: (vs.voice === "active" ? modalBuilders : passiveModalBuilders)[vs.tense])(subjectPerson, ec, vs.negative); : (vs.voice === "active" ? modalBuilders : passiveModalBuilders)[vs.tense])(subjectPerson, ec, vs.negative);
return base.map(b => `${b}${typeof object === "object" ? " $OBJ" : ""}${ep ? ` ${ep}` : ""}`.replace(" ", " ").trim()); return base
.map(b => `${b}${typeof object === "object" ? " $OBJ" : ""}${ep ? ` ${ep}` : ""}${isImperativeTense(vs.tense) ? " (command)" : ""}`.replace(" ", " ").trim());
} }

View File

@ -16,9 +16,9 @@ import { getEnglishWord } from "../get-english-word";
import { renderAdjectiveSelection } from "./render-adj"; import { renderAdjectiveSelection } from "./render-adj";
import { isPattern5Entry, isAnimNounEntry, isPattern1Entry } from "../type-predicates"; import { isPattern5Entry, isAnimNounEntry, isPattern1Entry } from "../type-predicates";
export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "subject", soRole: "servant" | "king" | "none", isLocationSandwich: boolean): T.Rendered<T.NPSelection>; export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "subject", soRole: "servant" | "king" | "none", isPuSandwich: boolean): T.Rendered<T.NPSelection>;
export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "object", soRole: "servant" | "king" | "none", isLocationSandwich: boolean): T.Rendered<T.NPSelection>; export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "object", soRole: "servant" | "king" | "none", isPuSandwich: boolean): T.Rendered<T.NPSelection>;
export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "subject" | "object", soRole: "servant" | "king" | "none", isLocationSandwich: boolean): T.Rendered<T.NPSelection> { export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflectEnglish: boolean, role: "subject" | "object", soRole: "servant" | "king" | "none", isPuSandwich: boolean): T.Rendered<T.NPSelection> {
if (typeof NP !== "object") { if (typeof NP !== "object") {
if (role !== "object") { if (role !== "object") {
throw new Error("ObjectNP only allowed for objects"); throw new Error("ObjectNP only allowed for objects");
@ -28,7 +28,7 @@ export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflect
if (NP.selection.type === "noun") { if (NP.selection.type === "noun") {
return { return {
type: "NP", type: "NP",
selection: renderNounSelection(NP.selection, inflected, soRole, undefined, isLocationSandwich), selection: renderNounSelection(NP.selection, inflected, soRole, undefined, isPuSandwich),
}; };
} }
if (NP.selection.type === "pronoun") { if (NP.selection.type === "pronoun") {
@ -46,9 +46,9 @@ export function renderNPSelection(NP: T.NPSelection, inflected: boolean, inflect
throw new Error("unknown NP type"); throw new Error("unknown NP type");
}; };
export function renderNounSelection(n: T.NounSelection, inflected: boolean, role: "servant" | "king" | "none", noArticles?: true | "noArticles", isLocationSandwich?: boolean): T.Rendered<T.NounSelection> { export function renderNounSelection(n: T.NounSelection, inflected: boolean, role: "servant" | "king" | "none", noArticles?: true | "noArticles", isPuSandwich?: boolean): T.Rendered<T.NounSelection> {
const english = getEnglishFromNoun(n.entry, n.number, noArticles); const english = getEnglishFromNoun(n.entry, n.number, noArticles);
const nounInflects = !(isLocationSandwich && isPattern1Entry(n.entry) && n.number === "singular") const nounInflects = !(isPuSandwich && isPattern1Entry(n.entry) && n.number === "singular")
const pashto = ((): T.PsString[] => { const pashto = ((): T.PsString[] => {
const infs = inflectWord(n.entry); const infs = inflectWord(n.entry);
const ps = n.number === "singular" const ps = n.number === "singular"
@ -69,7 +69,7 @@ export function renderNounSelection(n: T.NounSelection, inflected: boolean, role
const person = getPersonNumber(n.gender, n.number); const person = getPersonNumber(n.gender, n.number);
return { return {
...n, ...n,
adjectives: n.adjectives.map(a => renderAdjectiveSelection(a, person, inflected, isLocationSandwich && n.number === "singular")), adjectives: n.adjectives.map(a => renderAdjectiveSelection(a, person, inflected, isPuSandwich && n.number === "singular")),
person, person,
inflected, inflected,
role, role,

View File

@ -14,12 +14,11 @@ export function renderSandwich(s: T.SandwichSelection<T.Sandwich>): T.Rendered<T
inflectInside, inflectInside,
"subject", "subject",
"none", "none",
isLocationSandwich(s), isPuSandwich(s),
), ),
}; };
} }
function isLocationSandwich(s: T.SandwichSelection<T.Sandwich>): boolean { function isPuSandwich(s: T.SandwichSelection<T.Sandwich>): boolean {
// TODO: more nuanced version of this? or just په ? return s.before?.p === "په";
return (s.before?.p === "په") && (s.after?.p === "کې");
} }

View File

@ -39,9 +39,6 @@ import Block, { NPBlock, APBlock } from "./components/blocks/Block";
import { roleIcon } from "./components/vp-explorer/VPExplorerExplanationModal"; import { roleIcon } from "./components/vp-explorer/VPExplorerExplanationModal";
import CompiledPTextDisplay from "./components/CompiledPTextDisplay"; import CompiledPTextDisplay from "./components/CompiledPTextDisplay";
import RenderedBlocksDisplay from "./components/RenderedBlocksDisplay"; import RenderedBlocksDisplay from "./components/RenderedBlocksDisplay";
import {
isPashtoScript,
} from "./lib/is-pashto";
import { import {
makePsString, makePsString,
removeFVarients, removeFVarients,
@ -122,6 +119,8 @@ import {
isFirstPerson, isFirstPerson,
isSecondPerson, isSecondPerson,
isThirdPerson, isThirdPerson,
blank,
kidsBlank,
} from "./lib/misc-helpers"; } from "./lib/misc-helpers";
import { import {
simplifyPhonetics, simplifyPhonetics,
@ -154,9 +153,10 @@ import {
compileEP, compileEP,
compileVP, compileVP,
flattenLengths, flattenLengths,
blank,
kidsBlank,
} from "./lib/phrase-building/compile"; } from "./lib/phrase-building/compile";
import {
isPashtoScript,
} from "./lib/is-pashto";
import { import {
renderAPSelection, renderAPSelection,
} from "./lib/phrase-building/render-ap"; } from "./lib/phrase-building/render-ap";