Skip to content

Commit

Permalink
more work on parser, getting going on laaR shee etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Jan 29, 2025
1 parent ba06fdf commit 0a1951e
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ function App() {
}

useEffect(() => {
console.log("Will load dictionary");
dictionary
.initialize()
.catch(console.error)
.then((res) => {
console.log({ res });
if (res && res.response === "loaded from saved") {
dictionary.update();
}
Expand Down
93 changes: 92 additions & 1 deletion src/components/src/vp-explorer/AbbreviationFormSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,98 @@ const options = [
value: "shortest",
},
];

const b = {

Check failure on line 24 in src/components/src/vp-explorer/AbbreviationFormSelector.tsx

View workflow job for this annotation

GitHub Actions / ci

'b' is declared but its value is never read.
blocks: [
{
key: 0.200389418248619,
block: {
type: "subjectSelection",
selection: {
type: "NP",
selection: {
type: "noun",
entry: {
i: 13304,
ts: 1527812828,
p: "کور",
f: "kor",
g: "kor",
e: "house, home",
r: 4,
a: 1,
c: "n. m.",
},
gender: "masc",
genderCanChange: false,
number: "singular",
numberCanChange: true,
adjectives: [],
dynamicComplement: false,
genStativeComplement: false,
determiners: {
type: "determiners",
withNoun: true,
determiners: [
{
type: "determiner",
determiner: {
p: "دا",
f: "daa",
type: "det",
demonstrative: true,
},
},
],
},
},
},
},
},
{
key: 0.16909686763985587,
block: { type: "objectSelection", selection: "none" },
},
],
verb: {
type: "verb",
verb: {
entry: {
i: 2146,
ts: 1527813842,
p: "بلېدل",
f: "baledul",
g: "baledul",
e: "to burn, catch fire",
r: 4,
l: 1527813841,
c: "v. stat. comp. intrans.",
ec: "burn,burns,burning,burnt,burned",
},
complement: {
i: 2095,
ts: 1527813841,
p: "بل",
f: "bal",
g: "bal",
e: "on fire, burning",
r: 4,
c: "adj.",
},
},
verbTense: "presentVerb",
perfectTense: "habitualPerfect",
imperativeTense: "imperfectiveImperative",
tenseCategory: "basic",
transitivity: "intransitive",
isCompound: "stative",
voice: "active",
negative: false,
canChangeTransitivity: false,
canChangeVoice: false,
canChangeStatDyn: false,
},
form: { removeKing: false, shrinkServant: false },
};
function formToValue(f: T.FormVersion) {
if (f.removeKing === false && f.shrinkServant === false) {
return "full";
Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/dictionary/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const dictionaryInfoUrl = `${dictionaryBaseUrl}/dictionary-info`;
const dictDb = new DictionaryDb({
url: dictionaryUrl,
infoUrl: dictionaryInfoUrl,
collectionName: "inflector-dict5",
infoLocalStorageKey: "inflector-dict5",
collectionName: "inflector-dict6",
infoLocalStorageKey: "inflector-dict6",
});

function queryP(p: string): T.DictionaryEntry[] {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/src/parsing/parse-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function phMatches(
}

if (!vb) {
// TODO: Is this right??
return true;
}
if (vb.info.type !== "verb") {
Expand All @@ -101,6 +102,15 @@ function phMatches(
// TODO: handle را غل etc! ? or is
return false;
}
if (["لاړ", "لاړه", "لاړې"].includes(ph?.s)) {
if (
isKedulStatEntry(vb.info.verb.entry) &&
vb.info.base === "stem" &&
vb.info.aspect === "perfective"
) {
return true;
}
}
const verbPh = getPhFromVerb(vb.info.verb, vb.info.base);
return verbPh === ph.s;
}
Expand Down
28 changes: 28 additions & 0 deletions src/lib/src/parsing/parse-noun-word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,31 @@ function convertInflection(
},
];
}

export function personsFromPattern1(base: string, r: string): T.Person[] {
if (r === base) {
return [
T.Person.FirstSingMale,
T.Person.SecondSingMale,
T.Person.ThirdSingMale,
T.Person.FirstPlurMale,
T.Person.SecondPlurMale,
T.Person.ThirdPlurMale,
];
}
if (`${base}ه` === r) {
return [
T.Person.FirstSingFemale,
T.Person.SecondSingFemale,
T.Person.ThirdSingFemale,
];
}
if (`${base}ې` === r) {
return [
T.Person.FirstPlurFemale,
T.Person.SecondPlurFemale,
T.Person.ThirdPlurFemale,
];
}
return [];
}
3 changes: 3 additions & 0 deletions src/lib/src/parsing/parse-ph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const phs = [
"ور",
"پرا",
"لا",
"لاړ",
"لاړه",
"لاړې",
];

export function parsePH(
Expand Down
42 changes: 41 additions & 1 deletion src/lib/src/parsing/parse-vp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
import { isSecondPerson, personToGenNum } from "../misc-helpers";
import { equals, zip } from "rambda";
import { isImperativeTense } from "../type-predicates";
import { isKedulStatEntry } from "./parse-verb-helpers";
import { dartlul, raatlul, tlul, wartlul } from "./irreg-verbs";
import { personsFromPattern1 } from "./parse-noun-word";
// to hide equatives type-doubling issue

// TODO: problem with 3rd pers sing verb endings اواز مې دې واورېده

// TODO: word query for kawul/kedul/stat/dyn

// TODO: test all types with pronouns
// TODO: راشم ورشم درشم
// TODO: لاړ شه لاړې شئ imperatives

// TODO: way to get an error message for past participle and equative
// not matching up
Expand Down Expand Up @@ -123,19 +128,22 @@ function getTenses(
return [];
}
const transitivities = getTransitivities(verb.info.verb);
console.log({ tense, transitivities });
if (verb.info.imperative && negative && !negative.imperative) {
return [];
}
if (!verb.info.imperative && negative && negative.imperative) {
return [];
}
const verbEntry = checkForTlulCombos(verb, ph, tense);
if (!verbEntry) return [];
return [
{
tense,
transitivities,
negative: !!negative,
person: verb.person,
verb: verb.info.verb,
verb: verbEntry,
},
];
} else {
Expand Down Expand Up @@ -175,6 +183,38 @@ function getTenses(
}
}

function checkForTlulCombos(
verb: T.ParsedVBE,
ph: T.ParsedPH | undefined,
tense: T.VerbTense | "perfectiveImperative" | "imperfectiveImperative"
): T.VerbEntry | undefined {
if (verb.info.type === "equative") {
throw new Error("should not be equative here");
}
if (
isKedulStatEntry(verb.info.verb.entry) &&
ph &&
(tense === "subjunctiveVerb" || tense === "perfectiveImperative")
) {
const personsFromLar = personsFromPattern1("لاړ", ph.s);
if (personsFromLar.includes(verb.person)) {
return tlul;
}
if (ph.s === "را") {
return raatlul;
}
if (ph.s === "در") {
return dartlul;
}
if (ph.s === "ور") {
return wartlul;
}
// TODO: probably better to check this elsewhere because it wil stop other uses of to become
return undefined;
}
return verb.info.verb;
}

function finishPossibleVPSs({
tense,
transitivities,
Expand Down

0 comments on commit 0a1951e

Please sign in to comment.