more and testing on parse-vp
This commit is contained in:
parent
288718f69a
commit
4b54289c48
|
@ -50,7 +50,7 @@ function ParserDemo({ opts }: { opts: T.TextOptions }) {
|
|||
{errors.length > 0 && (
|
||||
<>
|
||||
<div className="alert alert-danger" role="alert">
|
||||
{errors.length > 0 ? (
|
||||
{errors.length > 1 ? (
|
||||
<>
|
||||
<div>possible errors:</div>
|
||||
<ul>
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
import { verbLookup, wordQuery } from "./lookup";
|
||||
import { parseVerb } from "./parse-verb";
|
||||
import { tokenizer } from "./tokenizer";
|
||||
import { removeKeys } from "./utils";
|
||||
|
||||
const wahul = wordQuery("وهل", "verb");
|
||||
const leekul = wordQuery("لیکل", "verb");
|
||||
|
@ -1502,11 +1503,7 @@ tests.forEach(({ label, cases }) => {
|
|||
),
|
||||
];
|
||||
}, []);
|
||||
expect(removeIs(vbs)).toIncludeSameMembers(removeIs(madeVbsS));
|
||||
expect(removeKeys(vbs)).toIncludeSameMembers(removeKeys(madeVbsS));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function removeIs(a: any): any {
|
||||
return JSON.parse(JSON.stringify(a, (k, v) => (k === "i" ? undefined : v)));
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
// check that aawu stuff is working
|
||||
// check oo`azmooy -
|
||||
// check څاته
|
||||
// laaRa shum etc
|
||||
|
||||
export function parseVerb(
|
||||
tokens: Readonly<T.Token[]>,
|
||||
|
|
|
@ -0,0 +1,660 @@
|
|||
/* eslint-disable jest/no-conditional-expect */
|
||||
/* eslint-disable jest/valid-title */
|
||||
import * as T from "../../../types";
|
||||
import {
|
||||
makeObjectSelectionComplete,
|
||||
makeSubjectSelection,
|
||||
makeSubjectSelectionComplete,
|
||||
} from "../phrase-building/blocks-utils";
|
||||
import {
|
||||
makeNounSelection,
|
||||
makePronounSelection,
|
||||
} from "../phrase-building/make-selections";
|
||||
import { lookup, verbLookup, wordQuery } from "./lookup";
|
||||
import { parseVP } from "./parse-vp";
|
||||
import { tokenizer } from "./tokenizer";
|
||||
import { tlul } from "./irreg-verbs";
|
||||
import { removeKeys } from "./utils";
|
||||
|
||||
const sarey = wordQuery("سړی", "noun");
|
||||
const rasedul = wordQuery("رسېدل", "verb");
|
||||
const maashoom = wordQuery("ماشوم", "noun");
|
||||
const leedul = wordQuery("لیدل", "verb");
|
||||
|
||||
const tests: {
|
||||
label: string;
|
||||
cases: {
|
||||
input: string;
|
||||
output: T.VPSelectionComplete[];
|
||||
error?: boolean;
|
||||
}[];
|
||||
}[] = [
|
||||
{
|
||||
label: "nothing / failures",
|
||||
cases: [
|
||||
{
|
||||
input: "",
|
||||
output: [],
|
||||
},
|
||||
{
|
||||
input: "زه سړی رسېږم",
|
||||
output: [],
|
||||
},
|
||||
{
|
||||
input: "زه سړی ماشوم ولید",
|
||||
output: [],
|
||||
},
|
||||
{
|
||||
input: "ما ځم",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "سړی زه ویني",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "سړي ما ولیدلم",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
input: "زه ماشومانو وینم",
|
||||
output: [],
|
||||
error: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "intransitive full kernels",
|
||||
cases: [
|
||||
{
|
||||
input: "زه ځم",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingMale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: tlul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
|
||||
selection: makePronounSelection(T.Person.FirstSingFemale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: tlul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: "سړی رسېږي",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: rasedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: "سړی به ورسېږي",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: rasedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "perfectiveFuture",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "intransitive no king",
|
||||
cases: [
|
||||
{
|
||||
input: "ځم",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingMale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: tlul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
|
||||
selection: makePronounSelection(T.Person.FirstSingFemale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: {
|
||||
type: "objectSelection",
|
||||
selection: "none",
|
||||
},
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: tlul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "past tense transitive full kernels",
|
||||
cases: [
|
||||
{
|
||||
input: "سړي ماشومه ولیده",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: {
|
||||
...makeNounSelection(maashoom, undefined),
|
||||
gender: "fem",
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "perfectivePast",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "transitive full kernels",
|
||||
cases: [
|
||||
{
|
||||
input: "سړی ماشومه ویني",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: {
|
||||
...makeNounSelection(maashoom, undefined),
|
||||
gender: "fem",
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: {
|
||||
...makeNounSelection(maashoom, undefined),
|
||||
gender: "fem",
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: "سړی ما ویني",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingMale),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingFemale),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: false,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "transitive no king",
|
||||
cases: [
|
||||
{
|
||||
input: "سړي ولیدله",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.ThirdSingFemale),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "perfectivePast",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: "سړی وینم",
|
||||
output: [
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingMale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
blocks: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(T.Person.FirstSingFemale),
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete({
|
||||
type: "NP",
|
||||
selection: makeNounSelection(sarey, undefined),
|
||||
}),
|
||||
},
|
||||
],
|
||||
verb: {
|
||||
type: "verb",
|
||||
verb: leedul,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense: "presentVerb",
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
},
|
||||
externalComplement: undefined,
|
||||
form: {
|
||||
removeKing: true,
|
||||
shrinkServant: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "transitive shrunken servant",
|
||||
cases: [],
|
||||
},
|
||||
];
|
||||
|
||||
tests.forEach(({ label, cases }) => {
|
||||
test(label, () => {
|
||||
cases.forEach(({ input, output, error }) => {
|
||||
const tokens = tokenizer(input);
|
||||
const parsed = parseVP(tokens, lookup, verbLookup);
|
||||
if (error) {
|
||||
expect(parsed.filter((x) => x.errors.length).length).toBeTruthy();
|
||||
} else {
|
||||
expect(parsed.map((p) => removeKeys(p.body))).toIncludeSameMembers(
|
||||
removeKeys(output)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -17,7 +17,7 @@ import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
|
|||
|
||||
// make impossible subjects like I saw me, error
|
||||
|
||||
// PROBLEM! ته وینې doesn't work cause it just takes ته as a verb phrase ?
|
||||
// TODO: transitivity options
|
||||
|
||||
export function parseVP(
|
||||
tokens: Readonly<T.Token[]>,
|
||||
|
@ -51,6 +51,19 @@ export function parseVP(
|
|||
const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect);
|
||||
const isPast = isPastTense(tense);
|
||||
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
verb: verb.info.verb,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
|
||||
const nps = blocks.filter(
|
||||
(x): x is { inflected: boolean; selection: T.NPSelection } =>
|
||||
"inflected" in x
|
||||
|
@ -61,18 +74,6 @@ export function parseVP(
|
|||
return [];
|
||||
}
|
||||
if (nps.length === 0) {
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
verb: verb.info.verb,
|
||||
transitivity: "intransitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
const blocks: T.VPSBlockComplete[] = [
|
||||
{
|
||||
key: 1,
|
||||
|
@ -99,7 +100,6 @@ export function parseVP(
|
|||
},
|
||||
} as T.VPSelectionComplete);
|
||||
}
|
||||
if (nps.length === 1) {
|
||||
const errors: T.ParseError[] = [];
|
||||
if (getPersonFromNP(nps[0].selection) !== verb.person) {
|
||||
errors.push({ message: "subject must agree with intransitive verb" });
|
||||
|
@ -122,18 +122,6 @@ export function parseVP(
|
|||
},
|
||||
},
|
||||
];
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
verb: verb.info.verb,
|
||||
transitivity: "intransitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
return returnParseResult(
|
||||
tokens,
|
||||
{
|
||||
|
@ -147,7 +135,6 @@ export function parseVP(
|
|||
} as T.VPSelectionComplete,
|
||||
errors
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// transitive
|
||||
if (nps.length > 2) {
|
||||
|
@ -158,6 +145,13 @@ export function parseVP(
|
|||
}
|
||||
if (nps.length === 1) {
|
||||
const np = nps[0];
|
||||
// possibilities
|
||||
// present:
|
||||
// - no king (np is servant)
|
||||
// - shrunken servant (np is king)
|
||||
// past:
|
||||
// - no king (np is servant)
|
||||
// - shrunken servant (np is king)
|
||||
return (
|
||||
[
|
||||
{
|
||||
|
@ -171,14 +165,20 @@ export function parseVP(
|
|||
] as const
|
||||
).flatMap((form) => {
|
||||
const errors: T.ParseError[] = [];
|
||||
if (form.removeKing) {
|
||||
// king is gone
|
||||
// servant is there
|
||||
const king: T.NPSelection = {
|
||||
const king: T.NPSelection = form.removeKing
|
||||
? {
|
||||
type: "NP",
|
||||
selection: makePronounSelection(verb.person),
|
||||
};
|
||||
const servant = np.selection;
|
||||
}
|
||||
: np.selection;
|
||||
const servants: T.NPSelection[] = form.shrinkServant
|
||||
? getPeopleFromKids(kids).map((person) => ({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
}))
|
||||
: [np.selection];
|
||||
// check for vp structure errors
|
||||
if (form.removeKing) {
|
||||
if (!isPast) {
|
||||
if (isFirstOrSecondPersPronoun(np.selection))
|
||||
if (!np.inflected) {
|
||||
|
@ -195,79 +195,13 @@ export function parseVP(
|
|||
});
|
||||
}
|
||||
}
|
||||
const blocks: T.VPSBlockComplete[] = !isPast
|
||||
? [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete(king),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete(servant),
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
key: 1,
|
||||
block: makeSubjectSelectionComplete(servant),
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
block: makeObjectSelectionComplete(king),
|
||||
},
|
||||
];
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
// @ts-ignore
|
||||
verb: verb.info.verb,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
return returnParseResult(
|
||||
tokens,
|
||||
{
|
||||
blocks,
|
||||
verb: v,
|
||||
externalComplement: undefined,
|
||||
form,
|
||||
} as T.VPSelectionComplete,
|
||||
errors
|
||||
);
|
||||
} else {
|
||||
// servant is shrunken
|
||||
// king is there
|
||||
const king = np.selection;
|
||||
const shrunkenServantPeople = getPeopleFromKids(kids);
|
||||
if (!shrunkenServantPeople.length) {
|
||||
return [];
|
||||
}
|
||||
const servants = shrunkenServantPeople.map(
|
||||
(person): T.NPSelection => ({
|
||||
type: "NP",
|
||||
selection: makePronounSelection(person),
|
||||
})
|
||||
);
|
||||
if (!isPast) {
|
||||
if (np.inflected) {
|
||||
} else if (np.inflected) {
|
||||
errors.push({
|
||||
message:
|
||||
"object of a past tense transitive verb should not be inflected",
|
||||
message: !isPast
|
||||
? "object of a past tense transitive verb should not be inflected"
|
||||
: "subject of a non-past tense transitive verb should not be inflected",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (np.inflected) {
|
||||
errors.push({
|
||||
message:
|
||||
"subject of a non-past tense transitive verb should not be inflected",
|
||||
});
|
||||
}
|
||||
}
|
||||
const blocksOps: T.VPSBlockComplete[][] = servants.map((servant) =>
|
||||
!isPast
|
||||
? [
|
||||
|
@ -291,19 +225,6 @@ export function parseVP(
|
|||
},
|
||||
]
|
||||
);
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
// @ts-ignore
|
||||
verb: verb.info.verb,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
return blocksOps.map((blocks) => ({
|
||||
tokens,
|
||||
body: {
|
||||
|
@ -314,15 +235,7 @@ export function parseVP(
|
|||
} as T.VPSelectionComplete,
|
||||
errors,
|
||||
}));
|
||||
}
|
||||
});
|
||||
// possibilities
|
||||
// present:
|
||||
// - no king (np is servant)
|
||||
// - shrunken servant (np is king)
|
||||
// past:
|
||||
// - no king (np is servant)
|
||||
// - shrunken servant (np is king)
|
||||
} else {
|
||||
if (isPast) {
|
||||
return (
|
||||
|
@ -363,19 +276,6 @@ export function parseVP(
|
|||
if (flip) {
|
||||
blocks = blocks.reverse();
|
||||
}
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
// @ts-ignore
|
||||
verb: verb.info.verb,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
return returnParseResult(
|
||||
tokens,
|
||||
{
|
||||
|
@ -438,19 +338,6 @@ export function parseVP(
|
|||
if (flip) {
|
||||
blocks = blocks.reverse();
|
||||
}
|
||||
const v: T.VerbSelectionComplete = {
|
||||
type: "verb",
|
||||
// @ts-ignore
|
||||
verb: verb.info.verb,
|
||||
transitivity: "transitive",
|
||||
canChangeTransitivity: false,
|
||||
canChangeStatDyn: false,
|
||||
negative: false,
|
||||
tense,
|
||||
canChangeVoice: true,
|
||||
isCompound: false,
|
||||
voice: "active",
|
||||
};
|
||||
return returnParseResult(
|
||||
tokens,
|
||||
{
|
||||
|
@ -468,7 +355,6 @@ export function parseVP(
|
|||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -496,262 +382,6 @@ function getPeopleFromKids(kids: T.ParsedKid[]): T.Person[] {
|
|||
return p;
|
||||
}
|
||||
|
||||
// // how to make this into a nice pipeline... 🤔
|
||||
// const NP1 = parseNP(tokens, lookup).filter(({ errors }) => !errors.length);
|
||||
// const ba = bindParseResult(NP1, (tokens, np1) => {
|
||||
// const b = parseBa(tokens);
|
||||
// if (!b.length) {
|
||||
// return [
|
||||
// {
|
||||
// tokens,
|
||||
// body: {
|
||||
// np1,
|
||||
// ba: false,
|
||||
// },
|
||||
// errors: [],
|
||||
// },
|
||||
// ];
|
||||
// } else {
|
||||
// return b.map(({ tokens, errors }) => ({
|
||||
// body: {
|
||||
// np1,
|
||||
// ba: true,
|
||||
// },
|
||||
// errors,
|
||||
// tokens,
|
||||
// }));
|
||||
// }
|
||||
// });
|
||||
// const NP2 = bindParseResult<
|
||||
// {
|
||||
// np1: {
|
||||
// inflected: boolean;
|
||||
// selection: T.NPSelection;
|
||||
// };
|
||||
// ba: boolean;
|
||||
// },
|
||||
// {
|
||||
// np1: {
|
||||
// inflected: boolean;
|
||||
// selection: T.NPSelection;
|
||||
// };
|
||||
// ba: boolean;
|
||||
// np2:
|
||||
// | {
|
||||
// inflected: boolean;
|
||||
// selection: T.NPSelection;
|
||||
// }
|
||||
// | undefined;
|
||||
// }
|
||||
// >(ba, (tokens, { np1, ba }) => {
|
||||
// const np2s = parseNP(tokens, lookup);
|
||||
// if (!np2s.length) {
|
||||
// const r: T.ParseResult<{
|
||||
// np1: {
|
||||
// inflected: boolean;
|
||||
// selection: T.NPSelection;
|
||||
// };
|
||||
// ba: boolean;
|
||||
// np2: undefined;
|
||||
// }>[] = [
|
||||
// {
|
||||
// tokens,
|
||||
// body: {
|
||||
// np1,
|
||||
// np2: undefined,
|
||||
// ba,
|
||||
// },
|
||||
// errors: [],
|
||||
// },
|
||||
// ];
|
||||
// return r;
|
||||
// }
|
||||
// return np2s.map((p) => ({
|
||||
// tokens: p.tokens,
|
||||
// body: {
|
||||
// np1,
|
||||
// np2: p.body,
|
||||
// ba,
|
||||
// },
|
||||
// errors: p.errors,
|
||||
// }));
|
||||
// }).filter(({ errors }) => !errors.length);
|
||||
// const vb = bindParseResult(NP2, (tokens, nps) => {
|
||||
// const vb = parseVerb(tokens, verbLookup);
|
||||
// // TODO make a nice functor that just maps or adds in the body
|
||||
// return vb.map((p) => ({
|
||||
// tokens: p.tokens,
|
||||
// body: {
|
||||
// np2: nps.np2,
|
||||
// v: p.body,
|
||||
// np1: nps.np1,
|
||||
// ba: nps.ba,
|
||||
// },
|
||||
// errors: p.errors,
|
||||
// }));
|
||||
// }).filter(({ errors }) => !errors.length);
|
||||
// // TODO: be able to bind mulitple vals
|
||||
// return bindParseResult(vb, (tokens, { np1, np2, v: [ph, v], ba }) => {
|
||||
// const w: T.ParseResult<T.VPSelectionComplete>[] = [];
|
||||
// if (v.info.type === "equative") {
|
||||
// throw new Error("not yet implemented");
|
||||
// }
|
||||
// const isPast = v.info.base === "root";
|
||||
// const intransitive =
|
||||
// v.info.type === "verb" && v.info.verb.entry.c.includes("intrans.");
|
||||
// if (intransitive) {
|
||||
// if (np2) return [];
|
||||
// const s = np1;
|
||||
// const errors: T.ParseError[] = [];
|
||||
// if (s.inflected) {
|
||||
// errors.push({
|
||||
// message: "subject of intransitive verb should not be inflected",
|
||||
// });
|
||||
// }
|
||||
// if (getPersonFromNP(s.selection) !== v.person) {
|
||||
// errors.push({
|
||||
// message: "subject should agree with intransitive verb",
|
||||
// });
|
||||
// }
|
||||
// const blocks: T.VPSBlockComplete[] = [
|
||||
// {
|
||||
// key: 1,
|
||||
// block: makeSubjectSelectionComplete(s.selection),
|
||||
// },
|
||||
// {
|
||||
// key: 2,
|
||||
// block: {
|
||||
// type: "objectSelection",
|
||||
// selection: "none",
|
||||
// },
|
||||
// },
|
||||
// ];
|
||||
// const verb: T.VerbSelectionComplete = {
|
||||
// type: "verb",
|
||||
// verb: v.info.type === "verb" ? v.info.verb : kedulStat,
|
||||
// transitivity: "intransitive",
|
||||
// canChangeTransitivity: false,
|
||||
// canChangeStatDyn: false,
|
||||
// negative: false,
|
||||
// tense: getTenseFromRootsStems(ba, v.info.base, v.info.aspect),
|
||||
// canChangeVoice: true,
|
||||
// isCompound: false,
|
||||
// voice: "active",
|
||||
// };
|
||||
// w.push({
|
||||
// tokens,
|
||||
// body: {
|
||||
// blocks,
|
||||
// verb,
|
||||
// externalComplement: undefined,
|
||||
// form: {
|
||||
// removeKing: false,
|
||||
// shrinkServant: false,
|
||||
// },
|
||||
// },
|
||||
// errors,
|
||||
// });
|
||||
// } else {
|
||||
// // transitive verb
|
||||
// if (!(np1 && np2)) return [];
|
||||
// [[np1, np2, false] as const, [np2, np1, true] as const].forEach(
|
||||
// ([s, o, reversed]) => {
|
||||
// if (v.info.type === "equative") {
|
||||
// throw new Error("not yet implemented");
|
||||
// }
|
||||
// if (!s || !o) return [];
|
||||
// // TODO: check if perfective head MATCHES verb
|
||||
// if (v.info.aspect === "perfective" && !ph) {
|
||||
// return [];
|
||||
// }
|
||||
// const subjPerson = getPersonFromNP(s.selection);
|
||||
// const errors: T.ParseError[] = [];
|
||||
// if (intransitive) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// if (isPast) {
|
||||
// if (getPersonFromNP(o.selection) !== v.person) {
|
||||
// errors.push({
|
||||
// message: "transitive past tense verb does not match object",
|
||||
// });
|
||||
// } else {
|
||||
// if (!s.inflected) {
|
||||
// errors.push({
|
||||
// message: "transitive past tense subject should be inflected",
|
||||
// });
|
||||
// }
|
||||
// if (o.inflected) {
|
||||
// errors.push({
|
||||
// message:
|
||||
// "transitive past tense object should not be inflected",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (getPersonFromNP(s.selection) !== v.person) {
|
||||
// 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,
|
||||
// block: makeSubjectSelectionComplete(s.selection),
|
||||
// },
|
||||
// {
|
||||
// key: 2,
|
||||
// block: makeObjectSelectionComplete(o.selection),
|
||||
// },
|
||||
// ];
|
||||
// if (reversed) {
|
||||
// blocks.reverse();
|
||||
// }
|
||||
// const verb: T.VerbSelectionComplete = {
|
||||
// type: "verb",
|
||||
// verb: v.info.type === "verb" ? v.info.verb : kedulStat,
|
||||
// transitivity: "transitive",
|
||||
// canChangeTransitivity: false,
|
||||
// canChangeStatDyn: false,
|
||||
// negative: false,
|
||||
// tense: getTenseFromRootsStems(ba, v.info.base, v.info.aspect),
|
||||
// canChangeVoice: true,
|
||||
// isCompound: false,
|
||||
// voice: "active",
|
||||
// };
|
||||
// w.push({
|
||||
// tokens,
|
||||
// body: {
|
||||
// blocks,
|
||||
// verb,
|
||||
// externalComplement: undefined,
|
||||
// form: {
|
||||
// removeKing: false,
|
||||
// shrinkServant: false,
|
||||
// },
|
||||
// },
|
||||
// errors,
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
|
||||
function getTenseFromRootsStems(
|
||||
hasBa: boolean,
|
||||
base: "root" | "stem",
|
||||
|
|
|
@ -2,7 +2,10 @@ import { Token } from "../../../types";
|
|||
import { standardizePashto } from "../standardize-pashto";
|
||||
|
||||
export function tokenizer(s: string): Token[] {
|
||||
const words = standardizePashto(s).trim().split(/ +/);
|
||||
const words = standardizePashto(s)
|
||||
.trim()
|
||||
.split(/ +/)
|
||||
.filter((x) => x);
|
||||
const indexed: { i: number; s: string }[] = [];
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
indexed.push({ i, s: words[i] });
|
||||
|
|
|
@ -102,3 +102,9 @@ export function isCompleteResult<C extends object>(
|
|||
): boolean {
|
||||
return !r.tokens.length && !r.errors.length;
|
||||
}
|
||||
|
||||
export function removeKeys(a: any): any {
|
||||
return JSON.parse(
|
||||
JSON.stringify(a, (k, v) => (k === "i" || k === "key" ? undefined : v))
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue