basic vp parsing starting

This commit is contained in:
adueck 2023-08-05 21:14:29 +04:00
parent e910de719f
commit 3221bb1e89
4 changed files with 56 additions and 70 deletions

View File

@ -1,5 +1,4 @@
import * as T from "../../../types";
import { endsInConsonant } from "../p-text-helpers";
import {
isPattern1Entry,
isPattern2Entry,
@ -394,18 +393,19 @@ export function getInflectionQueries(
predicate: isPattern1Entry,
},
});
if (noun) {
// bundled plural
queries.push({
search: { p: s.slice(0, -1) },
details: {
inflection: [0],
plural: true,
gender: ["masc"],
predicate: (e) => !isPattern5Entry(e) && endsInConsonant(e),
},
});
}
// TODO: Bundled plural only works when there is a quantifier in front of it !
// if (noun) {
// // bundled plural
// queries.push({
// search: { p: s.slice(0, -1) },
// details: {
// inflection: [0],
// plural: true,
// gender: ["masc"],
// predicate: (e) => !isPattern5Entry(e) && endsInConsonant(e),
// },
// });
// }
queries.push({
search: { infbp: s.slice(0, -1) },
details: {

View File

@ -130,13 +130,6 @@ const tests: {
gender: "fem",
},
},
{
inflected: false,
selection: {
...makeNounSelection(daktar, undefined),
number: "plural",
},
},
],
},
{
@ -1370,23 +1363,6 @@ const tests: {
},
],
},
{
category: "bundled plurals",
cases: [
{
input: "کوره",
output: [
{
inflected: false,
selection: {
...makeNounSelection(kor, undefined),
number: "plural",
},
},
],
},
],
},
];
describe("parsing nouns", () => {

View File

@ -37,13 +37,17 @@ export function parseVP(
return [];
}
// how to make this into a nice pipeline... 🤔
const NP1 = parseNP(tokens, lookup);
const NP2 = bindParseResult(NP1, (tokens) => parseNP(tokens, lookup), true);
const NP1 = parseNP(tokens, lookup).filter(({ errors }) => !errors.length);
const NP2 = bindParseResult(
NP1,
(tokens) => parseNP(tokens, lookup),
true
).filter(({ errors }) => !errors.length);
const vb = bindParseResult(
NP2,
(tokens) => parseVerb(tokens, verbLookup),
true
);
).filter(({ errors }) => !errors.length);
// TODO: be able to bind mulitple vals
return bindParseResult<Omit<T.VBE, "ps">, T.VPSelectionComplete>(
vb,
@ -51,28 +55,35 @@ export function parseVP(
const w: T.ParseResult<T.VPSelectionComplete>[] = [];
NP1.forEach(({ body: np1 }) => {
NP2.forEach(({ body: np2 }) => {
// NICE TODO: IF there's an error in any of the NPS, don't try
// to make the VPS - just show them that error
// for that we probably need a different type of
[
[np1, np2],
[np2, np1],
].forEach(([s, o]) => {
const errors: T.ParseError[] = [];
const subjPerson = getPersonFromNP(s.selection);
if (s.inflected) {
errors.push({ message: "subject should not be inflected" });
}
if (o.selection.selection.type === "pronoun") {
if (!isThirdPerson(subjPerson) && !o.inflected) {
errors.push({
message:
"1st or 2nd person object pronoun should be inflected",
});
}
} else if (o.inflected) {
errors.push({ message: "object should not be inflected" });
}
if (getPersonFromNP(s.selection) !== v.person) {
errors.push({ message: "verb does not match subject" });
errors.push({
message: "verb does not match subject",
});
} else {
if (s.inflected) {
errors.push({ message: "subject should not be inflected" });
}
if (o.selection.selection.type === "pronoun") {
if (!isThirdPerson(subjPerson) && !o.inflected) {
errors.push({
message:
"1st or 2nd person object pronoun should be inflected",
});
}
} else if (o.inflected) {
errors.push({ message: "object should not be inflected" });
}
}
const blocks: T.VPSBlockComplete[] = [
{
key: 1,

View File

@ -33,22 +33,21 @@ export function bindParseResult<C extends object, D extends object>(
},
ignorePrevious?: boolean
): T.ParseResult<D>[] {
// const prev = ignorePrevious
// ? (() => {
// const resArr: T.ParseResult<C>[] = [];
// previous.filter((item) => {
// var i = resArr.findIndex(
// (x) => x.tokens.length === item.tokens.length
// );
// if (i <= -1) {
// resArr.push(item);
// }
// return null;
// });
// return resArr;
// })()
// : previous;
const prev = previous;
const prev = ignorePrevious
? (() => {
const resArr: T.ParseResult<C>[] = [];
previous.filter((item) => {
var i = resArr.findIndex(
(x) => x.tokens.length === item.tokens.length
);
if (i <= -1) {
resArr.push(item);
}
return null;
});
return resArr;
})()
: previous;
const nextPossibilities = prev.flatMap(({ tokens, body, errors }) => {
const res = f(tokens, body);
const { errors: errsPassed, next } = Array.isArray(res)