working towards parsing perfect verbs
This commit is contained in:
parent
28f79729a4
commit
56770b5041
|
@ -1,8 +1,10 @@
|
|||
import * as T from "../../../types";
|
||||
import { LookupFunction } from "./lookup";
|
||||
import { parseEquative } from "./parse-equative";
|
||||
import { parseKidsSection } from "./parse-kids-section";
|
||||
import { parseNeg } from "./parse-negative";
|
||||
import { parseNP } from "./parse-np";
|
||||
import { parsePastPart } from "./parse-past-part";
|
||||
import { parsePH } from "./parse-ph";
|
||||
import { parseVerb } from "./parse-verb";
|
||||
import { bindParseResult, returnParseResult } from "./utils";
|
||||
|
@ -26,6 +28,8 @@ export function parseBlocks(
|
|||
const np = prevPh ? [] : parseNP(tokens, lookup);
|
||||
const ph = vbExists || prevPh ? [] : parsePH(tokens);
|
||||
const vb = parseVerb(tokens, lookup);
|
||||
const vbp = parsePastPart(tokens, lookup);
|
||||
const eq = parseEquative(tokens);
|
||||
const neg = parseNeg(tokens);
|
||||
const kidsR = parseKidsSection(tokens, []);
|
||||
const allResults: T.ParseResult<T.ParsedBlock | T.ParsedKidsSection>[] = [
|
||||
|
@ -33,6 +37,8 @@ export function parseBlocks(
|
|||
...ph,
|
||||
...neg,
|
||||
...vb,
|
||||
...vbp,
|
||||
...eq,
|
||||
...kidsR,
|
||||
];
|
||||
// TODO: is this necessary?
|
||||
|
@ -76,7 +82,10 @@ export function parseBlocks(
|
|||
});
|
||||
}
|
||||
|
||||
function phMatches(ph: T.ParsedPH | undefined, vb: T.ParsedVBE | undefined) {
|
||||
function phMatches(
|
||||
ph: T.ParsedPH | undefined,
|
||||
vb: T.ParsedVBE | T.ParsedVBP | undefined
|
||||
) {
|
||||
if (!ph) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
import * as T from "../../../types";
|
||||
|
||||
export function parseEquative(
|
||||
tokens: Readonly<T.Token[]>
|
||||
): T.ParseResult<T.ParsedVBE>[] {
|
||||
if (tokens.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const [{ s }, ...rest] = tokens;
|
||||
const match = table.find((x) => x.ps.includes(s));
|
||||
if (!match) {
|
||||
return [];
|
||||
}
|
||||
return match.people.flatMap((person) =>
|
||||
match.tenses.map((tense) => ({
|
||||
tokens: rest,
|
||||
body: {
|
||||
type: "VB",
|
||||
info: {
|
||||
type: "equative",
|
||||
tense,
|
||||
},
|
||||
person,
|
||||
},
|
||||
errors: [],
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: NOT COMPLETE / CORRECT
|
||||
const table: {
|
||||
ps: string[];
|
||||
tenses: T.EquativeTenseWithoutBa[];
|
||||
people: T.Person[];
|
||||
}[] = [
|
||||
{
|
||||
ps: ["یم"],
|
||||
tenses: ["present", "habitual"],
|
||||
people: [T.Person.FirstSingMale, T.Person.FirstSingFemale],
|
||||
},
|
||||
{
|
||||
ps: ["یې"],
|
||||
tenses: ["present", "habitual"],
|
||||
people: [T.Person.SecondSingMale, T.Person.SecondSingFemale],
|
||||
},
|
||||
{
|
||||
ps: ["یو"],
|
||||
tenses: ["present", "habitual"],
|
||||
people: [T.Person.FirstPlurMale, T.Person.FirstPlurFemale],
|
||||
},
|
||||
{
|
||||
ps: ["یئ"],
|
||||
tenses: ["present", "habitual"],
|
||||
people: [T.Person.SecondPlurMale, T.Person.SecondPlurFemale],
|
||||
},
|
||||
{
|
||||
ps: ["وم"],
|
||||
tenses: ["subjunctive", "past"],
|
||||
people: [T.Person.FirstSingMale, T.Person.FirstSingFemale],
|
||||
},
|
||||
{
|
||||
ps: ["وې"],
|
||||
tenses: ["subjunctive", "past"],
|
||||
people: [T.Person.SecondSingMale, T.Person.SecondSingFemale],
|
||||
},
|
||||
{
|
||||
ps: ["وو"],
|
||||
tenses: ["subjunctive", "past"],
|
||||
people: [T.Person.FirstPlurMale, T.Person.FirstPlurFemale],
|
||||
},
|
||||
{
|
||||
ps: ["وئ"],
|
||||
tenses: ["subjunctive", "past"],
|
||||
people: [T.Person.SecondPlurMale, T.Person.SecondPlurFemale],
|
||||
},
|
||||
{
|
||||
ps: ["دی"],
|
||||
tenses: ["present"],
|
||||
people: [T.Person.ThirdSingMale],
|
||||
},
|
||||
{
|
||||
ps: ["ده"],
|
||||
tenses: ["present"],
|
||||
people: [T.Person.ThirdSingFemale],
|
||||
},
|
||||
{
|
||||
ps: ["دي"],
|
||||
tenses: ["present"],
|
||||
people: [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale],
|
||||
},
|
||||
{
|
||||
ps: ["وي"],
|
||||
tenses: ["habitual"],
|
||||
people: [
|
||||
T.Person.ThirdSingMale,
|
||||
T.Person.ThirdSingFemale,
|
||||
T.Person.ThirdPlurMale,
|
||||
T.Person.ThirdPlurFemale,
|
||||
],
|
||||
},
|
||||
{
|
||||
ps: ["وای", "وی"],
|
||||
tenses: ["pastSubjunctive"],
|
||||
people: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||||
},
|
||||
];
|
|
@ -0,0 +1,64 @@
|
|||
import * as T from "../../../types";
|
||||
import { LookupFunction } from "./lookup";
|
||||
import { returnParseResult } from "./utils";
|
||||
|
||||
export function parsePastPart(
|
||||
tokens: Readonly<T.Token[]>,
|
||||
lookup: LookupFunction
|
||||
): T.ParseResult<T.ParsedVBP>[] {
|
||||
if (tokens.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const [{ s }, ...rest] = tokens;
|
||||
const ending: "ی" | "ي" | "ې" = s.at(-1) as "ی" | "ي" | "ې";
|
||||
if (!ending || !["ی", "ي", "ې"].includes(ending)) {
|
||||
return [];
|
||||
}
|
||||
// TODO: ALSO HANDLE SHORT FORMS
|
||||
const wOutEnd = s.slice(0, -1);
|
||||
const matches = lookup(wOutEnd, "participle");
|
||||
const genNums = endingGenderNum(ending);
|
||||
return matches
|
||||
.flatMap<T.ParsedVBP>((verb) =>
|
||||
genNums.map<T.ParsedVBP>((genNum) => ({
|
||||
type: "VB",
|
||||
info: {
|
||||
type: "ppart",
|
||||
verb,
|
||||
genNum,
|
||||
},
|
||||
}))
|
||||
)
|
||||
.flatMap((m) => returnParseResult(rest, m));
|
||||
}
|
||||
|
||||
function endingGenderNum(ending: "ی" | "ي" | "ې"): T.GenderNumber[] {
|
||||
if (ending === "ی") {
|
||||
return [
|
||||
{
|
||||
gender: "masc",
|
||||
number: "singular",
|
||||
},
|
||||
];
|
||||
}
|
||||
if (ending === "ي") {
|
||||
return [
|
||||
{
|
||||
gender: "masc",
|
||||
number: "plural",
|
||||
},
|
||||
];
|
||||
}
|
||||
// if (ending === "ې") {
|
||||
return [
|
||||
{
|
||||
gender: "fem",
|
||||
number: "singular",
|
||||
},
|
||||
{
|
||||
gender: "fem",
|
||||
number: "plural",
|
||||
},
|
||||
];
|
||||
// }
|
||||
}
|
|
@ -22,6 +22,7 @@ const leedul = wordQuery("لیدل", "verb");
|
|||
const kenaastul = wordQuery("کېناستل", "verb");
|
||||
const wurul = wordQuery("وړل", "verb");
|
||||
const akheestul = wordQuery("اخیستل", "verb");
|
||||
const khandul = wordQuery("خندل", "verb");
|
||||
|
||||
const tests: {
|
||||
label: string;
|
||||
|
@ -51,6 +52,11 @@ const tests: {
|
|||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "تلم مې",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "سړی زه ویني",
|
||||
output: [],
|
||||
|
@ -1381,6 +1387,258 @@ const tests: {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "grammatically transitive",
|
||||
cases: [
|
||||
{
|
||||
input: "زه خاندم",
|
||||
output: getPeople(1, "sing").map<T.VPSelectionComplete>((person) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: khandul,
|
||||
transitivity: "grammatically transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
input: "خاندم",
|
||||
output: getPeople(1, "sing").map<T.VPSelectionComplete>((person) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: khandul,
|
||||
transitivity: "grammatically transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
input: "ما خندل",
|
||||
output: getPeople(1, "sing").map<T.VPSelectionComplete>((person) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: khandul,
|
||||
transitivity: "grammatically transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "imperfectivePast",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
input: "خندل مې",
|
||||
output: getPeople(1, "sing").map<T.VPSelectionComplete>((person) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: khandul,
|
||||
transitivity: "grammatically transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "imperfectivePast",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: true,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
input: "خندل",
|
||||
output: [],
|
||||
},
|
||||
{
|
||||
input: "خاندم مې",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "زه وینم",
|
||||
output: getPeople(1, "sing").map<T.VPSelectionComplete>((person) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "grammatically transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
input: "ما ولیدل",
|
||||
output: getPeople(1, "sing").flatMap<T.VPSelectionComplete>((person) =>
|
||||
(
|
||||
["transitive", "grammatically transitive"] as const
|
||||
).map<T.VPSelectionComplete>((transitivity) => ({
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block:
|
||||
transitivity === "grammatically transitive"
|
||||
? {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
}
|
||||
: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.ThirdPlurMale),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity,
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "perfectivePast",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: transitivity === "transitive",
|
||||
shrinkServant: false,
|
||||
},
|
||||
}))
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
tests.forEach(({ label, cases }) => {
|
||||
|
@ -1394,6 +1652,7 @@ tests.forEach(({ label, cases }) => {
|
|||
expect(parsed.map((p) => removeKeys(p.body))).toIncludeSameMembers(
|
||||
removeKeys(output)
|
||||
);
|
||||
expect(parsed.every((p) => p.errors.length === 0)).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -55,6 +55,7 @@ export function parseVP(
|
|||
if (!verb || verb.type !== "VB" || verb.info.type !== "verb") {
|
||||
return [];
|
||||
}
|
||||
// TODO: check for either VBE or Equative and VBP
|
||||
if (
|
||||
!negativeInPlace({
|
||||
neg: negIndex,
|
||||
|
@ -67,7 +68,6 @@ export function parseVP(
|
|||
return [];
|
||||
}
|
||||
if (verb.info.aspect === "perfective") {
|
||||
// TODO: check that the perfective head is in the right place and actually matches
|
||||
if (!ph) {
|
||||
return [];
|
||||
}
|
||||
|
@ -77,11 +77,44 @@ export function parseVP(
|
|||
}
|
||||
}
|
||||
const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect);
|
||||
const isPast = isPastTense(tense);
|
||||
const transitivities = getTransitivities(verb.info.verb);
|
||||
const results: T.ParseResult<T.VPSelectionComplete>[] = [];
|
||||
// eww... pretty imperative way of doing this...
|
||||
for (let transitivity of transitivities) {
|
||||
const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP");
|
||||
const miniPronouns = getMiniPronouns(kids);
|
||||
return finishPossibleVPSs({
|
||||
tense,
|
||||
transitivities,
|
||||
nps,
|
||||
miniPronouns,
|
||||
tokens,
|
||||
negative,
|
||||
verb,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function finishPossibleVPSs({
|
||||
tense,
|
||||
transitivities,
|
||||
nps,
|
||||
miniPronouns,
|
||||
negative,
|
||||
verb,
|
||||
tokens,
|
||||
}: {
|
||||
tense: T.VerbTense;
|
||||
transitivities: T.Transitivity[];
|
||||
nps: T.ParsedNP[];
|
||||
miniPronouns: T.ParsedMiniPronoun[];
|
||||
tokens: Readonly<T.Token[]>;
|
||||
negative: boolean;
|
||||
verb: T.ParsedVBE;
|
||||
}): T.ParseResult<T.VPSelectionComplete>[] {
|
||||
const isPast = isPastTense(tense);
|
||||
return transitivities.flatMap<T.ParseResult<T.VPSelectionComplete>>(
|
||||
(transitivity): T.ParseResult<T.VPSelectionComplete>[] => {
|
||||
if (verb.info.type === "equative") {
|
||||
return [];
|
||||
}
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
verb: verb.info.verb,
|
||||
|
@ -94,17 +127,58 @@ export function parseVP(
|
|||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
|
||||
const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP");
|
||||
if (transitivity === "intransitive") {
|
||||
return finishIntransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson: verb.person,
|
||||
});
|
||||
} else if (transitivity === "transitive") {
|
||||
return finishTransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson: verb.person,
|
||||
isPast,
|
||||
});
|
||||
} else {
|
||||
return finishGrammaticallyTransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson: verb.person,
|
||||
isPast,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function finishIntransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson,
|
||||
}: {
|
||||
miniPronouns: T.ParsedMiniPronoun[];
|
||||
nps: T.ParsedNP[];
|
||||
tokens: Readonly<T.Token[]>;
|
||||
v: T.VerbSelectionComplete;
|
||||
verbPerson: T.Person;
|
||||
}): T.ParseResult<T.VPSelectionComplete>[] {
|
||||
const errors: T.ParseError[] = [];
|
||||
if (getMiniPronouns(kids).length) {
|
||||
if (miniPronouns.length) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun",
|
||||
});
|
||||
}
|
||||
if (nps.length > 1) {
|
||||
continue;
|
||||
return [];
|
||||
}
|
||||
if (nps.length === 0) {
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
|
@ -112,7 +186,7 @@ export function parseVP(
|
|||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verb.person),
|
||||
selection: makePronounSelection(verbPerson),
|
||||
}),
|
||||
},
|
||||
{
|
||||
|
@ -123,7 +197,8 @@ export function parseVP(
|
|||
},
|
||||
},
|
||||
];
|
||||
results.push({
|
||||
return [
|
||||
{
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
|
@ -135,10 +210,10 @@ export function parseVP(
|
|||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
});
|
||||
continue;
|
||||
},
|
||||
];
|
||||
}
|
||||
if (getPersonFromNP(nps[0].selection) !== verb.person) {
|
||||
if (getPersonFromNP(nps[0].selection) !== verbPerson) {
|
||||
errors.push({ message: "subject must agree with intransitive verb" });
|
||||
}
|
||||
if (nps[0].inflected) {
|
||||
|
@ -159,7 +234,8 @@ export function parseVP(
|
|||
},
|
||||
},
|
||||
];
|
||||
results.push({
|
||||
return [
|
||||
{
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
|
@ -171,12 +247,28 @@ export function parseVP(
|
|||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
});
|
||||
continue;
|
||||
} else if (transitivity === "transitive") {
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function finishTransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson,
|
||||
isPast,
|
||||
}: {
|
||||
miniPronouns: T.ParsedMiniPronoun[];
|
||||
nps: T.ParsedNP[];
|
||||
tokens: Readonly<T.Token[]>;
|
||||
v: T.VerbSelectionComplete;
|
||||
verbPerson: T.Person;
|
||||
isPast: boolean;
|
||||
}): T.ParseResult<T.VPSelectionComplete>[] {
|
||||
// transitive
|
||||
if (nps.length > 2) {
|
||||
continue;
|
||||
return [];
|
||||
}
|
||||
if (nps.length === 0) {
|
||||
// present:
|
||||
|
@ -186,7 +278,6 @@ export function parseVP(
|
|||
// - no king (object)
|
||||
// - servant (subject) is shrunken
|
||||
const errors: T.ParseError[] = [];
|
||||
const miniPronouns = getMiniPronouns(kids);
|
||||
if (miniPronouns.length > 1) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun in kid's section",
|
||||
|
@ -201,7 +292,7 @@ export function parseVP(
|
|||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verb.person),
|
||||
selection: makePronounSelection(verbPerson),
|
||||
}),
|
||||
},
|
||||
{
|
||||
|
@ -224,12 +315,12 @@ export function parseVP(
|
|||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verb.person),
|
||||
selection: makePronounSelection(verbPerson),
|
||||
}),
|
||||
},
|
||||
]
|
||||
);
|
||||
const toAdd = blockOpts.flatMap((blocks) =>
|
||||
return blockOpts.flatMap((blocks) =>
|
||||
returnParseResult(
|
||||
tokens,
|
||||
{
|
||||
|
@ -246,8 +337,6 @@ export function parseVP(
|
|||
: errors
|
||||
)
|
||||
);
|
||||
toAdd.forEach((r) => results.push(r));
|
||||
continue;
|
||||
}
|
||||
if (nps.length === 1) {
|
||||
const np = nps[0];
|
||||
|
@ -258,7 +347,7 @@ export function parseVP(
|
|||
// past:
|
||||
// - no king (np is servant)
|
||||
// - shrunken servant (np is king)
|
||||
const res = (
|
||||
return (
|
||||
[
|
||||
{
|
||||
removeKing: true,
|
||||
|
@ -269,23 +358,23 @@ export function parseVP(
|
|||
shrinkServant: true,
|
||||
},
|
||||
] as const
|
||||
).flatMap((form) => {
|
||||
).flatMap<T.ParseResult<T.VPSelectionComplete>>((form) => {
|
||||
const errors: T.ParseError[] = [];
|
||||
const king: T.NPSelection = form.removeKing
|
||||
? {
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verb.person),
|
||||
selection: makePronounSelection(verbPerson),
|
||||
}
|
||||
: np.selection;
|
||||
const servants: T.NPSelection[] = form.shrinkServant
|
||||
? getPeopleFromMiniPronouns(kids).map((person) => ({
|
||||
? getPeopleFromMiniPronouns(miniPronouns).map((person) => ({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}))
|
||||
: [np.selection];
|
||||
// check for vp structure errors
|
||||
if (form.removeKing) {
|
||||
if (getMiniPronouns(kids).length) {
|
||||
if (miniPronouns.length) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun in kid's section",
|
||||
});
|
||||
|
@ -314,7 +403,7 @@ export function parseVP(
|
|||
: "subject of a non-past tense transitive verb should not be inflected",
|
||||
});
|
||||
}
|
||||
if (getPersonFromNP(king) !== verb.person) {
|
||||
if (getPersonFromNP(king) !== verbPerson) {
|
||||
errors.push({
|
||||
message: `${
|
||||
isPast ? "past tense" : "non-past tense"
|
||||
|
@ -360,11 +449,9 @@ export function parseVP(
|
|||
: errors,
|
||||
}));
|
||||
});
|
||||
res.forEach((r) => results.push(r));
|
||||
continue;
|
||||
} else {
|
||||
if (isPast) {
|
||||
const res = (
|
||||
return (
|
||||
[
|
||||
[nps[0], nps[1], false],
|
||||
[nps[1], nps[0], true],
|
||||
|
@ -383,8 +470,7 @@ export function parseVP(
|
|||
}
|
||||
if (!s.inflected) {
|
||||
errors.push({
|
||||
message:
|
||||
"subject of transitive past tense verb must be inflected",
|
||||
message: "subject of transitive past tense verb must be inflected",
|
||||
});
|
||||
}
|
||||
if (o.inflected) {
|
||||
|
@ -393,10 +479,9 @@ export function parseVP(
|
|||
"object of past tense transitive verb must not be inflected",
|
||||
});
|
||||
}
|
||||
if (getPersonFromNP(o.selection) !== verb.person) {
|
||||
if (getPersonFromNP(o.selection) !== verbPerson) {
|
||||
errors.push({
|
||||
message:
|
||||
"past tense transitive verb must agree with the object",
|
||||
message: "past tense transitive verb must agree with the object",
|
||||
});
|
||||
}
|
||||
let blocks: T.VPSBlockComplete[] = [
|
||||
|
@ -426,10 +511,8 @@ export function parseVP(
|
|||
errors
|
||||
);
|
||||
});
|
||||
res.forEach((r) => results.push(r));
|
||||
continue;
|
||||
} else {
|
||||
const res = (
|
||||
return (
|
||||
[
|
||||
[nps[0], nps[1], false],
|
||||
[nps[1], nps[0], true],
|
||||
|
@ -467,7 +550,7 @@ export function parseVP(
|
|||
"subject of transitive non-past tense verb must not be inflected",
|
||||
});
|
||||
}
|
||||
if (getPersonFromNP(s.selection) !== verb.person) {
|
||||
if (getPersonFromNP(s.selection) !== verbPerson) {
|
||||
errors.push({
|
||||
message:
|
||||
"non-past tense transitive verb must agree with the subject",
|
||||
|
@ -500,29 +583,43 @@ export function parseVP(
|
|||
errors
|
||||
);
|
||||
});
|
||||
res.forEach((r) => results.push(r));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// grammatically transitive
|
||||
}
|
||||
|
||||
function finishGrammaticallyTransitive({
|
||||
miniPronouns,
|
||||
nps,
|
||||
tokens,
|
||||
v,
|
||||
verbPerson,
|
||||
isPast,
|
||||
}: {
|
||||
miniPronouns: T.ParsedMiniPronoun[];
|
||||
nps: T.ParsedNP[];
|
||||
tokens: Readonly<T.Token[]>;
|
||||
v: T.VerbSelectionComplete;
|
||||
verbPerson: T.Person;
|
||||
isPast: boolean;
|
||||
}): T.ParseResult<T.VPSelectionComplete>[] {
|
||||
const errors: T.ParseError[] = [];
|
||||
if (isPast) {
|
||||
if (nps.length === 1) {
|
||||
if (getMiniPronouns(kids).length) {
|
||||
if (miniPronouns.length) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun",
|
||||
});
|
||||
}
|
||||
if (verb.person !== T.Person.ThirdPlurMale) {
|
||||
if (verbPerson !== T.Person.ThirdPlurMale) {
|
||||
errors.push({
|
||||
message:
|
||||
"grammatically transitive verb must be 3rd pers. masc. plur.",
|
||||
});
|
||||
}
|
||||
if (!nps[0].inflected) {
|
||||
if (isPast && !nps[0].inflected) {
|
||||
errors.push({
|
||||
message:
|
||||
"subject of grammatically transitive verb must be inflected",
|
||||
"subject of past tense grammatically transitive verb must be inflected",
|
||||
});
|
||||
}
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
|
@ -538,7 +635,8 @@ export function parseVP(
|
|||
},
|
||||
},
|
||||
];
|
||||
results.push({
|
||||
return [
|
||||
{
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
|
@ -550,10 +648,9 @@ export function parseVP(
|
|||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
});
|
||||
continue;
|
||||
},
|
||||
];
|
||||
} else if (nps.length === 0) {
|
||||
const miniPronouns = getMiniPronouns(kids);
|
||||
if (miniPronouns.length > 1) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun",
|
||||
|
@ -564,13 +661,13 @@ export function parseVP(
|
|||
message: "subject required for grammatically transitive verb",
|
||||
});
|
||||
}
|
||||
if (verb.person !== T.Person.ThirdPlurMale) {
|
||||
if (verbPerson !== T.Person.ThirdPlurMale) {
|
||||
errors.push({
|
||||
message:
|
||||
"grammatically transitive verb must be 3rd pers. masc. plur.",
|
||||
});
|
||||
}
|
||||
getPeopleFromMiniPronouns(kids).forEach((person) => {
|
||||
return getPeopleFromMiniPronouns(miniPronouns).map((person) => {
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
{
|
||||
key: 1,
|
||||
|
@ -587,7 +684,7 @@ export function parseVP(
|
|||
},
|
||||
},
|
||||
];
|
||||
results.push({
|
||||
return {
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
|
@ -599,17 +696,98 @@ export function parseVP(
|
|||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
};
|
||||
});
|
||||
});
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
// non-past
|
||||
if (miniPronouns.length) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun",
|
||||
});
|
||||
}
|
||||
if (nps.length === 1) {
|
||||
const subj = nps[0];
|
||||
if (verbPerson !== getPersonFromNP(subj.selection)) {
|
||||
errors.push({
|
||||
message: "non-past verb must agree with subject",
|
||||
});
|
||||
}
|
||||
if (nps[0].inflected) {
|
||||
errors.push({
|
||||
message:
|
||||
"subject of non-past tense grammatically transitive verb must not be inflected",
|
||||
});
|
||||
}
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete(nps[0].selection),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
];
|
||||
return [
|
||||
{
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
verb: v,
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
},
|
||||
];
|
||||
} else if (nps.length === 0) {
|
||||
if (miniPronouns.length > 1) {
|
||||
errors.push({
|
||||
message: "unknown mini-pronoun",
|
||||
});
|
||||
}
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verbPerson),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: T.Person.ThirdPlurMale,
|
||||
},
|
||||
},
|
||||
];
|
||||
return [
|
||||
{
|
||||
tokens,
|
||||
body: {
|
||||
blocks,
|
||||
verb: v,
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function getMiniPronouns(kids: T.ParsedKid[]): T.ParsedMiniPronoun[] {
|
||||
return kids.filter((k): k is T.ParsedMiniPronoun =>
|
||||
|
|
12
src/types.ts
12
src/types.ts
|
@ -726,9 +726,7 @@ export type EquativeTenseWithoutBa =
|
|||
| "subjunctive"
|
||||
| "habitual"
|
||||
| "past"
|
||||
| "wouldBe"
|
||||
| "pastSubjunctive"
|
||||
| "wouldHaveBeen";
|
||||
| "pastSubjunctive";
|
||||
export type PerfectTense = `${EquativeTense}Perfect`;
|
||||
export type AbilityTense = `${VerbTense}Modal`;
|
||||
export type ImperativeTense = `${Aspect}Imperative`;
|
||||
|
@ -1196,7 +1194,12 @@ export type Block = {
|
|||
| VHead;
|
||||
};
|
||||
|
||||
export type ParsedBlock = ParsedNP | ParsedPH | ParsedVBE | NegativeBlock;
|
||||
export type ParsedBlock =
|
||||
| ParsedNP
|
||||
| ParsedPH
|
||||
| ParsedVBE
|
||||
| ParsedVBP
|
||||
| NegativeBlock;
|
||||
|
||||
export type ParsedKidsSection = {
|
||||
type: "kids";
|
||||
|
@ -1213,6 +1216,7 @@ export type ParsedPH = {
|
|||
s: string;
|
||||
};
|
||||
export type ParsedVBE = Omit<VBE, "ps">;
|
||||
export type ParsedVBP = Omit<VBP, "ps">;
|
||||
|
||||
export type Kid = {
|
||||
key: number;
|
||||
|
|
Loading…
Reference in New Issue