bit of a messy fix for the problem of adjectives inflecting in location sandwiches
This commit is contained in:
parent
7893802787
commit
3effddfb64
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lingdocs/pashto-inflector",
|
"name": "@lingdocs/pashto-inflector",
|
||||||
"version": "3.7.9",
|
"version": "3.8.0",
|
||||||
"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",
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
personIsPlural,
|
personIsPlural,
|
||||||
} from "../../lib/misc-helpers";
|
} from "../../lib/misc-helpers";
|
||||||
import { renderSandwich } from "./render-sandwich";
|
import { renderSandwich } from "./render-sandwich";
|
||||||
|
import { isPattern1Entry } from "../type-predicates";
|
||||||
|
|
||||||
function chooseInflection(inflections: T.UnisexSet<T.InflectionSet>, pers: T.Person, inflected?: boolean): T.ArrayOneOrMore<T.PsString> {
|
function chooseInflection(inflections: T.UnisexSet<T.InflectionSet>, pers: T.Person, inflected?: boolean): T.ArrayOneOrMore<T.PsString> {
|
||||||
const gender = personGender(pers);
|
const gender = personGender(pers);
|
||||||
|
@ -29,14 +30,20 @@ export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, infl
|
||||||
return chooseInflection(infs.inflections, person, inflected);
|
return chooseInflection(infs.inflections, person, inflected);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.Rendered<T.AdjectiveSelection> {
|
export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean, isLocationSingSandwich?: boolean): T.Rendered<T.AdjectiveSelection> {
|
||||||
const eWord = getEnglishWord(a.entry);
|
const eWord = getEnglishWord(a.entry);
|
||||||
const e = !eWord
|
const e = !eWord
|
||||||
? undefined
|
? undefined
|
||||||
: typeof eWord === "string"
|
: typeof eWord === "string"
|
||||||
? eWord
|
? eWord
|
||||||
: (eWord.singular || undefined);
|
: (eWord.singular || undefined);
|
||||||
const ps = inflectAdjective(a, person, inflected);
|
const ps = inflectAdjective(
|
||||||
|
a,
|
||||||
|
person,
|
||||||
|
isLocationSingSandwich && isPattern1Entry(a.entry)
|
||||||
|
? false
|
||||||
|
: inflected,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
type: "adjective",
|
type: "adjective",
|
||||||
entry: a.entry,
|
entry: a.entry,
|
||||||
|
|
|
@ -43,7 +43,7 @@ function getEPSBlocksAndKids(EP: T.EPSelectionComplete): { kids: T.Kid[], blocks
|
||||||
makeBlock({
|
makeBlock({
|
||||||
type: "predicateSelection",
|
type: "predicateSelection",
|
||||||
selection: EP.predicate.selection.type === "NP"
|
selection: EP.predicate.selection.type === "NP"
|
||||||
? renderNPSelection(EP.predicate.selection, false, false, "subject", "king")
|
? renderNPSelection(EP.predicate.selection, false, false, "subject", "king", false)
|
||||||
// we won't have an unselected complement in the EP - TODO: make safer?
|
// we won't have an unselected complement in the EP - TODO: make safer?
|
||||||
: renderComplementSelection(EP.predicate.selection, commandingPerson) as T.Rendered<T.ComplementSelection>,
|
: renderComplementSelection(EP.predicate.selection, commandingPerson) as T.Rendered<T.ComplementSelection>,
|
||||||
}),
|
}),
|
||||||
|
@ -119,7 +119,7 @@ function renderEPSBlocks(blocks: T.EPSBlockComplete[]): T.Block[] {
|
||||||
}
|
}
|
||||||
return makeBlock({
|
return makeBlock({
|
||||||
type: "subjectSelection",
|
type: "subjectSelection",
|
||||||
selection: renderNPSelection(block.selection, false, false, "subject", "none"),
|
selection: renderNPSelection(block.selection, false, false, "subject", "none", false),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@ import {
|
||||||
} from "../../lib/np-tools";
|
} from "../../lib/np-tools";
|
||||||
import { getEnglishWord } from "../get-english-word";
|
import { getEnglishWord } from "../get-english-word";
|
||||||
import { renderAdjectiveSelection } from "./render-adj";
|
import { renderAdjectiveSelection } from "./render-adj";
|
||||||
import { isPattern5Entry, isAnimNounEntry } 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"): T.Rendered<T.NPSelection>;
|
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: "object", soRole: "servant" | "king" | "none"): 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: "subject" | "object", soRole: "servant" | "king" | "none"): 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> {
|
||||||
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),
|
selection: renderNounSelection(NP.selection, inflected, soRole, undefined, isLocationSandwich),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (NP.selection.type === "pronoun") {
|
if (NP.selection.type === "pronoun") {
|
||||||
|
@ -46,12 +46,13 @@ 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"): T.Rendered<T.NounSelection> {
|
export function renderNounSelection(n: T.NounSelection, inflected: boolean, role: "servant" | "king" | "none", noArticles?: true | "noArticles", isLocationSandwich?: 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 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"
|
||||||
? getInf(infs, "inflections", n.gender, false, inflected)
|
? getInf(infs, "inflections", n.gender, false, nounInflects)
|
||||||
: (() => {
|
: (() => {
|
||||||
const plural = getInf(infs, "plural", n.gender, true, inflected);
|
const plural = getInf(infs, "plural", n.gender, true, inflected);
|
||||||
return [
|
return [
|
||||||
|
@ -68,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)),
|
adjectives: n.adjectives.map(a => renderAdjectiveSelection(a, person, inflected, isLocationSandwich && n.number === "singular")),
|
||||||
person,
|
person,
|
||||||
inflected,
|
inflected,
|
||||||
role,
|
role,
|
||||||
|
@ -132,6 +133,7 @@ function renderPossesor(possesor: T.PossesorSelection | undefined, possesorRole:
|
||||||
possesorRole === "subj/obj" ? true : false,
|
possesorRole === "subj/obj" ? true : false,
|
||||||
"subject",
|
"subject",
|
||||||
possesorRole === "subj/obj" ? "none" : possesorRole,
|
possesorRole === "subj/obj" ? "none" : possesorRole,
|
||||||
|
false,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import * as T from "../../types";
|
import * as T from "../../types";
|
||||||
import { isPattern1Entry, isPattern5Entry, isAnimNounEntry } from "../type-predicates";
|
import { isPattern5Entry, isAnimNounEntry } from "../type-predicates";
|
||||||
import { renderNPSelection } from "./render-np";
|
import { renderNPSelection } from "./render-np";
|
||||||
|
|
||||||
export function renderSandwich(s: T.SandwichSelection<T.Sandwich>): T.Rendered<T.SandwichSelection<T.Sandwich>> {
|
export function renderSandwich(s: T.SandwichSelection<T.Sandwich>): T.Rendered<T.SandwichSelection<T.Sandwich>> {
|
||||||
const inflectInside = (isLocationSandwich(s) && s.inside.selection.type === "noun" && isPattern1Entry(s.inside.selection.entry) && s.inside.selection.number === "singular")
|
const inflectInside: boolean | "locationSandwich" = (s.inside.selection.type === "noun" && isPattern5Entry(s.inside.selection.entry) && isAnimNounEntry(s.inside.selection.entry))
|
||||||
? false
|
|
||||||
: (s.inside.selection.type === "noun" && isPattern5Entry(s.inside.selection.entry) && isAnimNounEntry(s.inside.selection.entry))
|
|
||||||
? false
|
? false
|
||||||
: true;
|
: true;
|
||||||
return {
|
return {
|
||||||
|
@ -16,11 +14,12 @@ export function renderSandwich(s: T.SandwichSelection<T.Sandwich>): T.Rendered<T
|
||||||
inflectInside,
|
inflectInside,
|
||||||
"subject",
|
"subject",
|
||||||
"none",
|
"none",
|
||||||
|
isLocationSandwich(s),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLocationSandwich(s: T.SandwichSelection<T.Sandwich>): boolean {
|
function isLocationSandwich(s: T.SandwichSelection<T.Sandwich>): boolean {
|
||||||
// TODO: more nuanced version of this?
|
// TODO: more nuanced version of this? or just په ?
|
||||||
return s.before?.p === "په" && s.after?.f === "کې";
|
return (s.before?.p === "په") && (s.after?.p === "کې");
|
||||||
}
|
}
|
|
@ -292,7 +292,7 @@ function renderVPBlocks(blocks: T.VPSBlockComplete[], config: {
|
||||||
...blocks,
|
...blocks,
|
||||||
makeBlock({
|
makeBlock({
|
||||||
type: "subjectSelection",
|
type: "subjectSelection",
|
||||||
selection: renderNPSelection(block.selection, config.inflectSubject, false, "subject", config.king === "subject" ? "king" : "servant"),
|
selection: renderNPSelection(block.selection, config.inflectSubject, false, "subject", config.king === "subject" ? "king" : "servant", false),
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ function renderVPBlocks(blocks: T.VPSBlockComplete[], config: {
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
const selection = renderNPSelection(object, config.inflectObject, true, "object", config.king === "object" ? "king" : "servant");
|
const selection = renderNPSelection(object, config.inflectObject, true, "object", config.king === "object" ? "king" : "servant", false);
|
||||||
return [
|
return [
|
||||||
...blocks,
|
...blocks,
|
||||||
makeBlock({
|
makeBlock({
|
||||||
|
|
Loading…
Reference in New Issue