From 271df7f2fdf08784d0cf4f87f60bdc0bb556f1d7 Mon Sep 17 00:00:00 2001
From: lingdocs <71590811+lingdocs@users.noreply.github.com>
Date: Tue, 14 Sep 2021 21:13:15 -0400
Subject: [PATCH] displaying plural results
---
functions/package-lock.json | 12 +++---
functions/package.json | 2 +-
website/package.json | 2 +-
website/src/components/ExtraEntryInfo.tsx | 12 +++---
website/src/lib/inflection-search-helpers.ts | 20 ++++------
website/src/lib/search-pile.ts | 40 +++++++++++++-------
website/src/screens/EntryEditor.tsx | 6 ++-
website/src/screens/IsolatedEntry.tsx | 15 +++++++-
website/src/screens/Wordlist.tsx | 4 +-
website/src/types.d.ts | 2 +
website/yarn.lock | 8 ++--
11 files changed, 72 insertions(+), 51 deletions(-)
diff --git a/functions/package-lock.json b/functions/package-lock.json
index de57a0f..a7719d3 100644
--- a/functions/package-lock.json
+++ b/functions/package-lock.json
@@ -200,9 +200,9 @@
}
},
"@lingdocs/pashto-inflector": {
- "version": "0.9.2",
- "resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.2.tgz",
- "integrity": "sha512-9tmPPezEvPFR/tPkBuF/bj79dCAviFTGOmCVDbRCymXmv4gWWhH4lCueYOYhyWZ4vXcihMflVpRSmLtUDXmdjQ==",
+ "version": "1.0.2",
+ "resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.2.tgz",
+ "integrity": "sha512-voPdIePrMzLc9RNFjyo0RczOPDoOkIhQ/34CxwfnkOrt7k3EwahPikEWvRIN4+JoxKJI8oA+iFKAN9OoGmY3Yg==",
"requires": {
"classnames": "^2.2.6",
"pbf": "^3.2.1",
@@ -1697,9 +1697,9 @@
}
},
"protocol-buffers-schema": {
- "version": "3.5.2",
- "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.5.2.tgz",
- "integrity": "sha512-LPzSaBYp/TcbuSlpGwqT5jR9kvJ3Zp5ic2N5c2ybx6XB/lSfEHq2D7ja8AgoxHoMD91wXFALJoXsvshKPuXyew=="
+ "version": "3.6.0",
+ "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz",
+ "integrity": "sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw=="
},
"proxy-addr": {
"version": "2.0.6",
diff --git a/functions/package.json b/functions/package.json
index 52f4e65..9a30f21 100644
--- a/functions/package.json
+++ b/functions/package.json
@@ -14,7 +14,7 @@
"main": "lib/functions/src/index.js",
"dependencies": {
"@google-cloud/storage": "^5.8.1",
- "@lingdocs/pashto-inflector": "^0.9.2",
+ "@lingdocs/pashto-inflector": "^1.0.2",
"@types/cors": "^2.8.10",
"@types/google-spreadsheet": "^3.0.2",
"cors": "^2.8.5",
diff --git a/website/package.json b/website/package.json
index d51fcf4..09a4a90 100644
--- a/website/package.json
+++ b/website/package.json
@@ -6,7 +6,7 @@
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2",
- "@lingdocs/pashto-inflector": "^0.9.2",
+ "@lingdocs/pashto-inflector": "^1.0.3",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
diff --git a/website/src/components/ExtraEntryInfo.tsx b/website/src/components/ExtraEntryInfo.tsx
index 76d716f..4d28668 100644
--- a/website/src/components/ExtraEntryInfo.tsx
+++ b/website/src/components/ExtraEntryInfo.tsx
@@ -13,7 +13,7 @@ const InflectionsInfo = ({ entry, textOptions }: {
entry: Types.DictionaryEntry,
textOptions: Types.TextOptions,
}) => {
- const inf = ((): Types.Inflections | false => {
+ const inf = ((): Types.InflectorOutput | false => {
try {
return inflectWord(entry);
} catch (e) {
@@ -25,20 +25,20 @@ const InflectionsInfo = ({ entry, textOptions }: {
return null;
}
// unisex noun / adjective
- if ("masc" in inf && "fem" in inf) {
+ if (inf.inflections && "masc" in inf.inflections && "fem" in inf.inflections) {
return (
- {inf.masc[1][0]}
+ {inf.inflections.masc[1][0]}
{` `}
- {inf.fem[0][0]}
+ {inf.inflections.fem[0][0]}
);
}
// masculine noun
- if ("masc" in inf) {
+ if (inf.inflections && "masc" in inf.inflections) {
return (
- {inf.masc[1][0]}
+ {inf.inflections.masc[1][0]}
);
}
diff --git a/website/src/lib/inflection-search-helpers.ts b/website/src/lib/inflection-search-helpers.ts
index c1870f9..88bf7da 100644
--- a/website/src/lib/inflection-search-helpers.ts
+++ b/website/src/lib/inflection-search-helpers.ts
@@ -51,23 +51,16 @@ function conflateUnisexPeople(arr: (string | T.Person)[]): (string | T.Person)[]
return newArr;
}
-export function displayPositionResult(res: (T.Person | "plain" | "1st" | "2nd")[] | null): string {
+export function displayPositionResult(res: (T.Person | "plain" | "1st" | "2nd" | "plural")[] | null): string {
const conflated = res
? conflateUnisexPeople(res)
: ["Doesn't change"];
return conflated.map((x) => {
- if (x === "plain") {
- return "Plain";
- }
- if (x === "1st") {
- return "1st Inflection";
- }
- if (x === "2nd") {
- return "2nd Inflection";
- }
- if (typeof x === "string") {
- return x;
- }
+ if (x === "plural") return "";
+ if (x === "plain") return "Plain";
+ if (x === "1st") return "1st Inflection";
+ if (x === "2nd") return "2nd Inflection";
+ if (typeof x === "string") return x;
return x === null ? "Same for all" : getEnglishPersonInfo(x);
}).join(" / ");
}
@@ -109,6 +102,7 @@ export function displayFormResult(res: string[]): string {
.replace("MascPlur", "(with a masc. plur. object)")
.replace("FemSing", "(with a fem. sing. object)")
.replace("FemPlur", "(with a fem. plur. object)")
+ .replace("ArabicPlural", "Arabic Plural")
.replace("Fem", "Fem.")
.replace("Masc", "Masc.")
}
\ No newline at end of file
diff --git a/website/src/lib/search-pile.ts b/website/src/lib/search-pile.ts
index 2f7aa7e..9da6052 100644
--- a/website/src/lib/search-pile.ts
+++ b/website/src/lib/search-pile.ts
@@ -11,17 +11,21 @@ import {
isVerbBlock,
isImperativeBlock,
isInflectionSet,
+ isPluralInflectionSet,
} from "@lingdocs/pashto-inflector";
import { personFromVerbBlockPos } from "@lingdocs/pashto-inflector";
-const inflectionNames: InflectionName[] = ["plain", "1st", "2nd"];
+const inflectionNames: { inflections: InflectionName[], plural: PluralInflectionName[] } = {
+ inflections: ["plain", "1st", "2nd"],
+ plural: ["plural", "2nd"],
+};
type ObPile = { [key: string]: ObRec; }
type ObRec = T.VerbBlock | T.ImperativeBlock | T.InflectionSet | T.PsString | boolean | null | string | ObPile;
type SinglePsResult = T.PsString | null;
type BlockResult = { ps: T.PsString, pos: T.Person[] | InflectionName[] }[];
-type InflectionSetResult = { ps: T.PsString, pos: InflectionName[] }[];
+type InflectionSetResult = { ps: T.PsString, pos: (InflectionName | PluralInflectionName)[] }[];
type BlockResultRaw = { ps: T.PsString, pos: [number, number][] }[];
type RowResult = { ps: T.PsString, pos: (0 | 1)[] }[];
@@ -46,6 +50,7 @@ export function searchPile(pile: ObPile, searchFun: (s: T.PsString) => boolean,
function searchObRecord(record: ObRec): null | BlockResult | SinglePsResult | InflectionSearchResult[] {
// hit a bottom part a tree, see if what we're looking for is there
if (Array.isArray(record)) {
+ // @ts-ignore
return searchBlock(record, searchFun);
}
if (typeof record !== "object") return null;
@@ -65,7 +70,7 @@ export function searchPile(pile: ObPile, searchFun: (s: T.PsString) => boolean,
}
const result = searchObRecord(value);
// Result: Hit the bottom and nothing found
- if (result === null) {
+ if (result === null || result === undefined) {
return res;
}
// Result: Hit a PsString with what we want at the bottom
@@ -115,6 +120,20 @@ function searchBlock(block: T.VerbBlock | T.ImperativeBlock | T.InflectionSet, s
}
return null;
}
+ if (isInflectionSet(block)) {
+ const results = searchInflectionSet(block, searchFun, "inflections");
+ if (results.length) {
+ return results;
+ }
+ return null;
+ }
+ if (isPluralInflectionSet(block)) {
+ const results = searchInflectionSet(block, searchFun, "plural");
+ if (results.length) {
+ return results;
+ }
+ return null;
+ }
if (isImperativeBlock(block)) {
const results = searchVerbBlock(block, searchFun);
if (results.length) {
@@ -125,13 +144,6 @@ function searchBlock(block: T.VerbBlock | T.ImperativeBlock | T.InflectionSet, s
}
return null;
}
- if (isInflectionSet(block)) {
- const results = searchInflectionSet(block, searchFun);
- if (results.length) {
- return results;
- }
- return null;
- }
return null;
}
@@ -173,18 +185,18 @@ export function searchVerbBlock(vb: T.VerbBlock | T.ImperativeBlock, searchFun:
}, []);
}
-function searchInflectionSet(inf: T.InflectionSet, searchFun: (ps: T.PsString) => boolean): InflectionSetResult {
+function searchInflectionSet(inf: T.InflectionSet | T.PluralInflectionSet, searchFun: (ps: T.PsString) => boolean, type: "inflections" | "plural"): InflectionSetResult {
return inf.reduce((all: InflectionSetResult, item, i): InflectionSetResult => {
const matching = item.filter(searchFun);
if (i === 0) {
- return matching.map(ps => ({ ps, pos: [inflectionNames[i]] }))
+ return matching.map(ps => ({ ps, pos: [inflectionNames[type][i]] }))
}
matching.forEach(it => {
const index = all.findIndex(x => x.ps.f === it.f);
if (index !== -1) {
- all[index].pos.push(inflectionNames[i])
+ all[index].pos.push(inflectionNames[type][i])
} else {
- all.push({ ps: it, pos: [inflectionNames[i]] });
+ all.push({ ps: it, pos: [inflectionNames[type][i]] });
}
})
return all;
diff --git a/website/src/screens/EntryEditor.tsx b/website/src/screens/EntryEditor.tsx
index a8ecbde..f4608ee 100644
--- a/website/src/screens/EntryEditor.tsx
+++ b/website/src/screens/EntryEditor.tsx
@@ -175,7 +175,7 @@ function EntryEditor({ isolatedEntry, dictionary, searchParams, textOptions, use
}
const complement = entry.l ? dictionary.findOneByTs(entry.l) : undefined;
- const inflections = ((): T.Inflections | false => {
+ const inf = ((): T.InflectorOutput | false => {
try {
return inflectWord(entry);
} catch (e) {
@@ -334,7 +334,9 @@ function EntryEditor({ isolatedEntry, dictionary, searchParams, textOptions, use
}
- {inflections && }
+ {inf && inf.inflections && }
+ {inf && "plural" in inf && }
+ {inf && "arabicPlural" in inf && }
{/* TODO: aay tail from state options */}
{
+ const inf = ((): T.InflectorOutput | false => {
try {
return inflectWord(entry);
} catch (e) {
@@ -95,6 +95,7 @@ function IsolatedEntry({ state, dictionary, isolateEntry }: {
return false;
}
})();
+ console.log(inf);
return
{entry.p} - LingDocs Pashto Dictionary
@@ -187,7 +188,17 @@ function IsolatedEntry({ state, dictionary, isolateEntry }: {
}
{editSubmitted && Thank you for your help!
}
- {inflections && }
+ {inf && <>
+ {inf.inflections && }
+ {"plural" in inf &&
+
Plural
+
+ }
+ {"arabicPlural" in inf &&
+
Arabic Plural
+
+ }
+ >}
{/* TODO: State options for tail type here */}
None to review
Next word up for review {dayjs().to(nextUp.dueDate)}:
- {removeFVariants(ps)}
+ {removeFVarients(ps)}
;
})()
diff --git a/website/src/types.d.ts b/website/src/types.d.ts
index 29d05f3..dfd44c2 100644
--- a/website/src/types.d.ts
+++ b/website/src/types.d.ts
@@ -158,6 +158,8 @@ type WordlistWordDoc = WordlistWord & { _rev: string, _id: string };
type InflectionName = "plain" | "1st" | "2nd";
+type PluralInflectionName = "plural" | "2nd";
+
type InflectionSearchResult = {
form: string[],
matches: {
diff --git a/website/yarn.lock b/website/yarn.lock
index 04e2e03..2095552 100644
--- a/website/yarn.lock
+++ b/website/yarn.lock
@@ -1483,10 +1483,10 @@
"@types/yargs" "^16.0.0"
chalk "^4.0.0"
-"@lingdocs/pashto-inflector@^0.9.2":
- version "0.9.2"
- resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.2.tgz#7ef3b3344c3eb3e3d1db77142ef83f0ac7e8e230"
- integrity sha512-9tmPPezEvPFR/tPkBuF/bj79dCAviFTGOmCVDbRCymXmv4gWWhH4lCueYOYhyWZ4vXcihMflVpRSmLtUDXmdjQ==
+"@lingdocs/pashto-inflector@^1.0.3":
+ version "1.0.3"
+ resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.3.tgz#4ba205869f41a540d85d045eee23c484814f1fd8"
+ integrity sha512-bxz94hmCfVfJg2CthViFZ/14cQmhPHtS+uA/d11vViI6qad5Kl4U33jm1ZfS7AaXHasqmnsKyYW7Qn+y/E0yUA==
dependencies:
classnames "^2.2.6"
pbf "^3.2.1"