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

View File

@ -130,13 +130,6 @@ const tests: {
gender: "fem", 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", () => { describe("parsing nouns", () => {

View File

@ -37,13 +37,17 @@ export function parseVP(
return []; return [];
} }
// how to make this into a nice pipeline... 🤔 // how to make this into a nice pipeline... 🤔
const NP1 = parseNP(tokens, lookup); const NP1 = parseNP(tokens, lookup).filter(({ errors }) => !errors.length);
const NP2 = bindParseResult(NP1, (tokens) => parseNP(tokens, lookup), true); const NP2 = bindParseResult(
NP1,
(tokens) => parseNP(tokens, lookup),
true
).filter(({ errors }) => !errors.length);
const vb = bindParseResult( const vb = bindParseResult(
NP2, NP2,
(tokens) => parseVerb(tokens, verbLookup), (tokens) => parseVerb(tokens, verbLookup),
true true
); ).filter(({ errors }) => !errors.length);
// TODO: be able to bind mulitple vals // TODO: be able to bind mulitple vals
return bindParseResult<Omit<T.VBE, "ps">, T.VPSelectionComplete>( return bindParseResult<Omit<T.VBE, "ps">, T.VPSelectionComplete>(
vb, vb,
@ -51,12 +55,20 @@ export function parseVP(
const w: T.ParseResult<T.VPSelectionComplete>[] = []; const w: T.ParseResult<T.VPSelectionComplete>[] = [];
NP1.forEach(({ body: np1 }) => { NP1.forEach(({ body: np1 }) => {
NP2.forEach(({ body: np2 }) => { 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], [np1, np2],
[np2, np1], [np2, np1],
].forEach(([s, o]) => { ].forEach(([s, o]) => {
const errors: T.ParseError[] = []; const errors: T.ParseError[] = [];
const subjPerson = getPersonFromNP(s.selection); const subjPerson = getPersonFromNP(s.selection);
if (getPersonFromNP(s.selection) !== v.person) {
errors.push({
message: "verb does not match subject",
});
} else {
if (s.inflected) { if (s.inflected) {
errors.push({ message: "subject should not be inflected" }); errors.push({ message: "subject should not be inflected" });
} }
@ -70,9 +82,8 @@ export function parseVP(
} else if (o.inflected) { } else if (o.inflected) {
errors.push({ message: "object should not be inflected" }); errors.push({ message: "object should not be inflected" });
} }
if (getPersonFromNP(s.selection) !== v.person) {
errors.push({ message: "verb does not match subject" });
} }
const blocks: T.VPSBlockComplete[] = [ const blocks: T.VPSBlockComplete[] = [
{ {
key: 1, key: 1,

View File

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