cleaner (but maybe much more inneficient) handling of entry standardization

This commit is contained in:
lingdocs 2021-09-16 14:05:01 -04:00
parent 1180401d81
commit 361dfe6ae8
8 changed files with 22 additions and 32 deletions

View File

@ -200,9 +200,9 @@
} }
}, },
"@lingdocs/pashto-inflector": { "@lingdocs/pashto-inflector": {
"version": "1.0.2", "version": "1.0.5",
"resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.2.tgz", "resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz",
"integrity": "sha512-voPdIePrMzLc9RNFjyo0RczOPDoOkIhQ/34CxwfnkOrt7k3EwahPikEWvRIN4+JoxKJI8oA+iFKAN9OoGmY3Yg==", "integrity": "sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg==",
"requires": { "requires": {
"classnames": "^2.2.6", "classnames": "^2.2.6",
"pbf": "^3.2.1", "pbf": "^3.2.1",

View File

@ -14,7 +14,7 @@
"main": "lib/functions/src/index.js", "main": "lib/functions/src/index.js",
"dependencies": { "dependencies": {
"@google-cloud/storage": "^5.8.1", "@google-cloud/storage": "^5.8.1",
"@lingdocs/pashto-inflector": "^1.0.2", "@lingdocs/pashto-inflector": "^1.0.5",
"@types/cors": "^2.8.10", "@types/cors": "^2.8.10",
"@types/google-spreadsheet": "^3.0.2", "@types/google-spreadsheet": "^3.0.2",
"cors": "^2.8.5", "cors": "^2.8.5",

View File

@ -16,7 +16,7 @@ export const publishDictionary = functions.runWith({
try { try {
const response = await publish(); const response = await publish();
res.send(response); res.send(response);
} catch (e) { } catch (e: any) {
res.status(500).send({ ok: false, error: e.message }); res.status(500).send({ ok: false, error: e.message });
} }
} }
@ -39,7 +39,7 @@ export const submissions = functions.runWith({
const response = await receiveSubmissions(suggestions, req.user.level === "editor"); const response = await receiveSubmissions(suggestions, req.user.level === "editor");
// TODO: WARN IF ANY OF THE EDITS DIDN'T HAPPEN // TODO: WARN IF ANY OF THE EDITS DIDN'T HAPPEN
res.send(response); res.send(response);
} catch (e) { } catch (e: any) {
res.status(500).send({ ok: false, error: e.message }); res.status(500).send({ ok: false, error: e.message });
}; };
} }

View File

@ -5,11 +5,11 @@ import {
dictionaryEntryBooleanFields, dictionaryEntryBooleanFields,
dictionaryEntryNumberFields, dictionaryEntryNumberFields,
dictionaryEntryTextFields, dictionaryEntryTextFields,
standardizePashto,
validateEntry, validateEntry,
writeDictionary, writeDictionary,
writeDictionaryInfo, writeDictionaryInfo,
simplifyPhonetics, simplifyPhonetics,
standardizeEntry,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
// import { // import {
// getWordList, // getWordList,
@ -33,14 +33,10 @@ const dictionaryInfoFilename = "dictionary-info";
const url = `${baseUrl}${dictionaryFilename}`; const url = `${baseUrl}${dictionaryFilename}`;
const infoUrl = `${baseUrl}${dictionaryInfoFilename}`; const infoUrl = `${baseUrl}${dictionaryInfoFilename}`;
function standardizePhonetics(f: string): string {
return f.replace(//g, "'");
}
// TODO: Create a seperate function for publishing the Hunspell that can run after the publish function? // TODO: Create a seperate function for publishing the Hunspell that can run after the publish function?
// to keep the publish function time down // to keep the publish function time down
export default async function(): Promise<PublishDictionaryResponse> { export default async function publish(): Promise<PublishDictionaryResponse> {
const entries = await getRawEntries(); const entries = await getRawEntries();
const errors = checkForErrors(entries); const errors = checkForErrors(entries);
if (errors.length) { if (errors.length) {
@ -106,7 +102,7 @@ async function getRawEntries(): Promise<T.DictionaryEntry[]> {
} }
function makeEntries(rows: any[]): T.DictionaryEntry[] { function makeEntries(rows: any[]): T.DictionaryEntry[] {
const entries: T.DictionaryEntry[] = rows.map((row, i): T.DictionaryEntry => { const entries: T.DictionaryEntry[] = rows.map((row): T.DictionaryEntry => {
const e: T.DictionaryEntry = { const e: T.DictionaryEntry = {
i: 1, i: 1,
ts: parseInt(row.ts), ts: parseInt(row.ts),
@ -116,28 +112,20 @@ function makeEntries(rows: any[]): T.DictionaryEntry[] {
e: row.e, e: row.e,
}; };
dictionaryEntryNumberFields.forEach((field: T.DictionaryEntryNumberField) => { dictionaryEntryNumberFields.forEach((field: T.DictionaryEntryNumberField) => {
if (row[field]) { if (row[field]) e[field] = parseInt(row[field]);
e[field] = parseInt(row[field]);
}
}); });
dictionaryEntryTextFields.forEach((field: T.DictionaryEntryTextField) => { dictionaryEntryTextFields.forEach((field: T.DictionaryEntryTextField) => {
if (row[field]) { if (row[field]) e[field] = row[field].trim();
const content = field.slice(-1) === "p" ? standardizePashto(row[field]).trim()
: field.slice(-1) === "f" ? standardizePhonetics(row[field]).trim()
: row[field].trim();
e[field] = content;
}
}); });
dictionaryEntryBooleanFields.forEach((field: T.DictionaryEntryBooleanField) => { dictionaryEntryBooleanFields.forEach((field: T.DictionaryEntryBooleanField) => {
if (row[field]) { if (row[field]) e[field] = true;
e[field] = true;
}
}); });
return e; return standardizeEntry(e);
}); });
// add alphabetical index // add alphabetical index
entries.sort((a, b) => a.p.localeCompare(b.p, "ps")); entries.sort((a, b) => a.p.localeCompare(b.p, "ps"));
const entriesLength = entries.length; const entriesLength = entries.length;
// add index
for (let i = 0; i < entriesLength; i++) { for (let i = 0; i < entriesLength; i++) {
entries[i].i = i; entries[i].i = i;
} }

View File

@ -4,6 +4,7 @@ import {
dictionaryEntryTextFields, dictionaryEntryTextFields,
dictionaryEntryBooleanFields, dictionaryEntryBooleanFields,
dictionaryEntryNumberFields, dictionaryEntryNumberFields,
standardizeEntry,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import * as FT from "../../website/src/types/functions-types"; import * as FT from "../../website/src/types/functions-types";
import * as functions from "firebase-functions"; import * as functions from "firebase-functions";
@ -94,7 +95,7 @@ export async function receiveSubmissions(e: FT.SubmissionsRequest, editor: boole
if (newEntries.length) { if (newEntries.length) {
newEntries.forEach((n) => { newEntries.forEach((n) => {
const entry = { ...n.entry }; const entry = { ...standardizeEntry(n.entry) };
// @ts-ignore // @ts-ignore
delete entry.i; // i not used in dictionary spreadsheet; added while building it delete entry.i; // i not used in dictionary spreadsheet; added while building it
// @ts-ignore // @ts-ignore

View File

@ -6,7 +6,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2", "@fortawesome/fontawesome-free": "^5.15.2",
"@lingdocs/pashto-inflector": "^1.0.3", "@lingdocs/pashto-inflector": "^1.0.5",
"@testing-library/jest-dom": "^5.11.4", "@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0", "@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10", "@testing-library/user-event": "^12.1.10",

View File

@ -16,6 +16,7 @@ import {
Types as T, Types as T,
InlinePs, InlinePs,
validateEntry, validateEntry,
standardizeEntry,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import Entry from "../components/Entry"; import Entry from "../components/Entry";
import * as FT from "../types/functions-types"; import * as FT from "../types/functions-types";

View File

@ -1483,10 +1483,10 @@
"@types/yargs" "^16.0.0" "@types/yargs" "^16.0.0"
chalk "^4.0.0" chalk "^4.0.0"
"@lingdocs/pashto-inflector@^1.0.3": "@lingdocs/pashto-inflector@^1.0.5":
version "1.0.3" version "1.0.5"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.3.tgz#4ba205869f41a540d85d045eee23c484814f1fd8" resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz#59b928e8ca1727572d661781a8db6b9f753052c4"
integrity sha512-bxz94hmCfVfJg2CthViFZ/14cQmhPHtS+uA/d11vViI6qad5Kl4U33jm1ZfS7AaXHasqmnsKyYW7Qn+y/E0yUA== integrity sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg==
dependencies: dependencies:
classnames "^2.2.6" classnames "^2.2.6"
pbf "^3.2.1" pbf "^3.2.1"