cleaner (but maybe much more inneficient) handling of entry standardization
This commit is contained in:
parent
1180401d81
commit
361dfe6ae8
|
@ -200,9 +200,9 @@
|
|||
}
|
||||
},
|
||||
"@lingdocs/pashto-inflector": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.2.tgz",
|
||||
"integrity": "sha512-voPdIePrMzLc9RNFjyo0RczOPDoOkIhQ/34CxwfnkOrt7k3EwahPikEWvRIN4+JoxKJI8oA+iFKAN9OoGmY3Yg==",
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz",
|
||||
"integrity": "sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg==",
|
||||
"requires": {
|
||||
"classnames": "^2.2.6",
|
||||
"pbf": "^3.2.1",
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"main": "lib/functions/src/index.js",
|
||||
"dependencies": {
|
||||
"@google-cloud/storage": "^5.8.1",
|
||||
"@lingdocs/pashto-inflector": "^1.0.2",
|
||||
"@lingdocs/pashto-inflector": "^1.0.5",
|
||||
"@types/cors": "^2.8.10",
|
||||
"@types/google-spreadsheet": "^3.0.2",
|
||||
"cors": "^2.8.5",
|
||||
|
|
|
@ -16,7 +16,7 @@ export const publishDictionary = functions.runWith({
|
|||
try {
|
||||
const response = await publish();
|
||||
res.send(response);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
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");
|
||||
// TODO: WARN IF ANY OF THE EDITS DIDN'T HAPPEN
|
||||
res.send(response);
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
res.status(500).send({ ok: false, error: e.message });
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import {
|
|||
dictionaryEntryBooleanFields,
|
||||
dictionaryEntryNumberFields,
|
||||
dictionaryEntryTextFields,
|
||||
standardizePashto,
|
||||
validateEntry,
|
||||
writeDictionary,
|
||||
writeDictionaryInfo,
|
||||
simplifyPhonetics,
|
||||
standardizeEntry,
|
||||
} from "@lingdocs/pashto-inflector";
|
||||
// import {
|
||||
// getWordList,
|
||||
|
@ -33,14 +33,10 @@ const dictionaryInfoFilename = "dictionary-info";
|
|||
const url = `${baseUrl}${dictionaryFilename}`;
|
||||
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?
|
||||
// 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 errors = checkForErrors(entries);
|
||||
if (errors.length) {
|
||||
|
@ -106,7 +102,7 @@ async function getRawEntries(): Promise<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 = {
|
||||
i: 1,
|
||||
ts: parseInt(row.ts),
|
||||
|
@ -116,28 +112,20 @@ function makeEntries(rows: any[]): T.DictionaryEntry[] {
|
|||
e: row.e,
|
||||
};
|
||||
dictionaryEntryNumberFields.forEach((field: T.DictionaryEntryNumberField) => {
|
||||
if (row[field]) {
|
||||
e[field] = parseInt(row[field]);
|
||||
}
|
||||
if (row[field]) e[field] = parseInt(row[field]);
|
||||
});
|
||||
dictionaryEntryTextFields.forEach((field: T.DictionaryEntryTextField) => {
|
||||
if (row[field]) {
|
||||
const content = field.slice(-1) === "p" ? standardizePashto(row[field]).trim()
|
||||
: field.slice(-1) === "f" ? standardizePhonetics(row[field]).trim()
|
||||
: row[field].trim();
|
||||
e[field] = content;
|
||||
}
|
||||
if (row[field]) e[field] = row[field].trim();
|
||||
});
|
||||
dictionaryEntryBooleanFields.forEach((field: T.DictionaryEntryBooleanField) => {
|
||||
if (row[field]) {
|
||||
e[field] = true;
|
||||
}
|
||||
if (row[field]) e[field] = true;
|
||||
});
|
||||
return e;
|
||||
return standardizeEntry(e);
|
||||
});
|
||||
// add alphabetical index
|
||||
entries.sort((a, b) => a.p.localeCompare(b.p, "ps"));
|
||||
const entriesLength = entries.length;
|
||||
// add index
|
||||
for (let i = 0; i < entriesLength; i++) {
|
||||
entries[i].i = i;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
dictionaryEntryTextFields,
|
||||
dictionaryEntryBooleanFields,
|
||||
dictionaryEntryNumberFields,
|
||||
standardizeEntry,
|
||||
} from "@lingdocs/pashto-inflector";
|
||||
import * as FT from "../../website/src/types/functions-types";
|
||||
import * as functions from "firebase-functions";
|
||||
|
@ -94,7 +95,7 @@ export async function receiveSubmissions(e: FT.SubmissionsRequest, editor: boole
|
|||
|
||||
if (newEntries.length) {
|
||||
newEntries.forEach((n) => {
|
||||
const entry = { ...n.entry };
|
||||
const entry = { ...standardizeEntry(n.entry) };
|
||||
// @ts-ignore
|
||||
delete entry.i; // i not used in dictionary spreadsheet; added while building it
|
||||
// @ts-ignore
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"private": true,
|
||||
"dependencies": {
|
||||
"@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/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
Types as T,
|
||||
InlinePs,
|
||||
validateEntry,
|
||||
standardizeEntry,
|
||||
} from "@lingdocs/pashto-inflector";
|
||||
import Entry from "../components/Entry";
|
||||
import * as FT from "../types/functions-types";
|
||||
|
|
|
@ -1483,10 +1483,10 @@
|
|||
"@types/yargs" "^16.0.0"
|
||||
chalk "^4.0.0"
|
||||
|
||||
"@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==
|
||||
"@lingdocs/pashto-inflector@^1.0.5":
|
||||
version "1.0.5"
|
||||
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz#59b928e8ca1727572d661781a8db6b9f753052c4"
|
||||
integrity sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg==
|
||||
dependencies:
|
||||
classnames "^2.2.6"
|
||||
pbf "^3.2.1"
|
||||
|
|
Loading…
Reference in New Issue