messy working with grammatically transitive verbs

This commit is contained in:
adueck 2023-08-31 19:16:31 +04:00
parent a3dbf550f0
commit 77d20ecf02
1 changed files with 477 additions and 347 deletions

View File

@ -29,6 +29,8 @@ import { LookupFunction } from "./lookup";
// TODO: learn how to yank / use plugin for JSON neovim // TODO: learn how to yank / use plugin for JSON neovim
// learn to use jq to edit selected json in vim ?? COOOL // learn to use jq to edit selected json in vim ?? COOOL
// TODO: test grammatically transitive stuff
export function parseVP( export function parseVP(
tokens: Readonly<T.Token[]>, tokens: Readonly<T.Token[]>,
lookup: LookupFunction lookup: LookupFunction
@ -74,13 +76,14 @@ export function parseVP(
} }
const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect); const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect);
const isPast = isPastTense(tense); 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 v: T.VerbSelectionComplete = { const v: T.VerbSelectionComplete = {
type: "verb", type: "verb",
verb: verb.info.verb, verb: verb.info.verb,
transitivity: verb.info.verb.entry.c.includes("intrans") transitivity,
? "intransitive"
: "transitive",
canChangeTransitivity: false, canChangeTransitivity: false,
canChangeStatDyn: false, canChangeStatDyn: false,
negative, negative,
@ -91,8 +94,7 @@ export function parseVP(
}; };
const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP"); const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP");
// TODO: check that verb and PH match if (transitivity === "intransitive") {
if (verb.info.verb.entry.c.includes("intrans")) {
const errors: T.ParseError[] = []; const errors: T.ParseError[] = [];
if (getMiniPronouns(kids).length) { if (getMiniPronouns(kids).length) {
errors.push({ errors.push({
@ -100,7 +102,7 @@ export function parseVP(
}); });
} }
if (nps.length > 1) { if (nps.length > 1) {
return []; continue;
} }
if (nps.length === 0) { if (nps.length === 0) {
const blocks: T.VPSBlockComplete[] = [ const blocks: T.VPSBlockComplete[] = [
@ -119,9 +121,9 @@ export function parseVP(
}, },
}, },
]; ];
return returnParseResult( results.push({
tokens, tokens,
{ body: {
blocks, blocks,
verb: v, verb: v,
externalComplement: undefined, externalComplement: undefined,
@ -130,8 +132,9 @@ export function parseVP(
shrinkServant: false, shrinkServant: false,
}, },
} as T.VPSelectionComplete, } as T.VPSelectionComplete,
errors errors,
); });
continue;
} }
if (getPersonFromNP(nps[0].selection) !== verb.person) { if (getPersonFromNP(nps[0].selection) !== verb.person) {
errors.push({ message: "subject must agree with intransitive verb" }); errors.push({ message: "subject must agree with intransitive verb" });
@ -154,9 +157,9 @@ export function parseVP(
}, },
}, },
]; ];
return returnParseResult( results.push({
tokens, tokens,
{ body: {
blocks, blocks,
verb: v, verb: v,
externalComplement: undefined, externalComplement: undefined,
@ -165,12 +168,13 @@ export function parseVP(
shrinkServant: false, shrinkServant: false,
}, },
} as T.VPSelectionComplete, } as T.VPSelectionComplete,
errors errors,
); });
} else { continue;
} else if (transitivity === "transitive") {
// transitive // transitive
if (nps.length > 2) { if (nps.length > 2) {
return []; continue;
} }
if (nps.length === 0) { if (nps.length === 0) {
// present: // present:
@ -223,7 +227,7 @@ export function parseVP(
}, },
] ]
); );
return blockOpts.flatMap((blocks) => const toAdd = blockOpts.flatMap((blocks) =>
returnParseResult( returnParseResult(
tokens, tokens,
{ {
@ -240,6 +244,8 @@ export function parseVP(
: errors : errors
) )
); );
toAdd.forEach((r) => results.push(r));
continue;
} }
if (nps.length === 1) { if (nps.length === 1) {
const np = nps[0]; const np = nps[0];
@ -250,7 +256,7 @@ export function parseVP(
// past: // past:
// - no king (np is servant) // - no king (np is servant)
// - shrunken servant (np is king) // - shrunken servant (np is king)
return ( const res = (
[ [
{ {
removeKing: true, removeKing: true,
@ -352,9 +358,11 @@ export function parseVP(
: errors, : errors,
})); }));
}); });
res.forEach((r) => results.push(r));
continue;
} else { } else {
if (isPast) { if (isPast) {
return ( const res = (
[ [
[nps[0], nps[1], false], [nps[0], nps[1], false],
[nps[1], nps[0], true], [nps[1], nps[0], true],
@ -416,8 +424,10 @@ export function parseVP(
errors errors
); );
}); });
res.forEach((r) => results.push(r));
continue;
} else { } else {
return ( const res = (
[ [
[nps[0], nps[1], false], [nps[0], nps[1], false],
[nps[1], nps[0], true], [nps[1], nps[0], true],
@ -488,9 +498,114 @@ export function parseVP(
errors errors
); );
}); });
res.forEach((r) => results.push(r));
continue;
}
}
} else {
// grammatically transitive
const errors: T.ParseError[] = [];
if (nps.length === 1) {
if (getMiniPronouns(kids).length) {
errors.push({
message: "unknown mini-pronoun",
});
}
if (verb.person !== T.Person.ThirdPlurMale) {
errors.push({
message:
"grammatically transitive verb must be 3rd pers. masc. plur.",
});
}
if (!nps[0].inflected) {
errors.push({
message:
"subject of grammatically transitive verb must be inflected",
});
}
const blocks: T.VPSBlockComplete[] = [
{
key: 1,
block: makeSubjectSelectionComplete(nps[0].selection),
},
{
key: 2,
block: {
type: "objectSelection",
selection: T.Person.ThirdPlurMale,
},
},
];
results.push({
tokens,
body: {
blocks,
verb: v,
externalComplement: undefined,
form: {
removeKing: false,
shrinkServant: false,
},
} as T.VPSelectionComplete,
errors,
});
continue;
} else if (nps.length === 0) {
const miniPronouns = getMiniPronouns(kids);
if (miniPronouns.length > 1) {
errors.push({
message: "unknown mini-pronoun",
});
}
if (miniPronouns.length === 0) {
errors.push({
message: "subject required for grammatically transitive verb",
});
}
if (verb.person !== T.Person.ThirdPlurMale) {
errors.push({
message:
"grammatically transitive verb must be 3rd pers. masc. plur.",
});
}
getPeopleFromMiniPronouns(kids).forEach((person) => {
const blocks: T.VPSBlockComplete[] = [
{
key: 1,
block: makeSubjectSelectionComplete({
type: "NP",
selection: makePronounSelection(person),
}),
},
{
key: 2,
block: {
type: "objectSelection",
selection: T.Person.ThirdPlurMale,
},
},
];
results.push({
tokens,
body: {
blocks,
verb: v,
externalComplement: undefined,
form: {
removeKing: false,
shrinkServant: false,
},
} as T.VPSelectionComplete,
errors,
});
});
continue;
} else {
continue;
} }
} }
} }
return results;
}); });
} }
@ -588,3 +703,18 @@ function pronounConflictInBlocks(blocks: T.VPSBlockComplete[]): boolean {
} }
return isInvalidSubjObjCombo(subjPerson, objPerson); return isInvalidSubjObjCombo(subjPerson, objPerson);
} }
function getTransitivities(v: T.VerbEntry): T.Transitivity[] {
const transitivities: T.Transitivity[] = [];
const opts = v.entry.c.split("/");
opts.forEach((opt) => {
if (opt.includes("gramm. trans")) {
transitivities.push("grammatically transitive");
} else if (opt.includes("intran")) {
transitivities.push("intransitive");
} else if (opt.includes("trans")) {
transitivities.push("transitive");
}
});
return transitivities;
}