validate entry function

This commit is contained in:
lingdocs 2021-09-16 13:52:52 -04:00
parent 8adf583540
commit 26f226a7fa
5 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
"version": "1.0.3",
"version": "1.0.4",
"author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com",

View File

@ -26,9 +26,10 @@ export const dictionaryEntryTextFields: T.DictionaryEntryTextField[] = [
"ec",
"ep",
];
export const dictionaryEntryBooleanFields: T.DictionaryEntryBooleanField[] = [
"noInf", "shortIntrans", "noOo", "sepOo", "diacExcept",
]
];
export const dictionaryEntryNumberFields: T.DictionaryEntryNumberField[] = [
"ts", "i", "l", "separationAtP", "separationAtF",
];

View File

@ -6,8 +6,9 @@
*
*/
import { validateEntry } from "./validate-entry";
import { standardizeEntry, validateEntry } from "./validate-entry";
import * as T from "../types";
import { standardizePhonetics } from "./standardize-pashto";
const toTest: {
input: any,
@ -159,3 +160,8 @@ test("validateEntry should work", () => {
expect(validateEntry(t.input as T.DictionaryEntry)).toEqual(t.output);
});
});
test("standardizeEntry", () => {
expect(standardizeEntry({"i":195,"ts":1527822036,"p":"اجتماعي","f":"ijtimaaee, ijtimaayee","g":"ijtimaaee,ijtimaayee","e":"public, social, societal","c":"adj."}))
.toEqual({"i":195,"ts":1527822036,"p":"اجتماعي","f":"ijtimaa'ee, ijtimaayee","g":"ijtimaaee,ijtimaayee","e":"public, social, societal","c":"adj."});
});

View File

@ -10,6 +10,7 @@ import * as T from "../types";
import {
phoneticsToDiacritics,
} from "./phonetics-to-diacritics";
import { standardizePashto, standardizePhonetics } from "./standardize-pashto";
const textFieldPairs: [T.DictionaryEntryTextField, T.DictionaryEntryTextField][] = [
["p", "f"],
@ -28,6 +29,20 @@ const requiredFields: T.DictionaryEntryField[] = [
"ts", "i", "p", "f", "e",
];
export function standardizeEntry(entry: T.DictionaryEntry): T.DictionaryEntry {
return textFieldPairs.reduce((e, pair) => {
return {
...e,
...entry[pair[0]] ? {
[pair[0]]: standardizePashto(entry[pair[0]] as string),
} : {},
...entry[pair[1]] ? {
[pair[1]]: standardizePhonetics(entry[pair[1]] as string),
} : {},
};
}, { ...entry });
}
export function validateEntry(entry: T.DictionaryEntry): T.DictionaryEntryError | {
ok: true,
} | {

View File

@ -36,7 +36,10 @@ import {
isUnisexSet,
isInflectionSet,
} from "./lib/p-text-helpers";
import { standardizePashto } from "./lib/standardize-pashto";
import {
standardizePashto,
standardizePhonetics,
} from "./lib/standardize-pashto";
import { phoneticsToDiacritics } from "./lib/phonetics-to-diacritics";
import {
convertSpelling,
@ -48,7 +51,8 @@ import {
dictionaryEntryTextFields,
} from "./lib/fields";
import {
validateEntry
validateEntry,
standardizeEntry,
} from "./lib/validate-entry";
import {
readDictionary,
@ -93,9 +97,11 @@ export {
makePsString,
removeFVarients,
standardizePashto,
standardizePhonetics,
convertSpelling,
revertSpelling,
validateEntry,
standardizeEntry,
isNounAdjOrVerb,
simplifyPhonetics,
phoneticsToDiacritics,
@ -136,6 +142,8 @@ export {
dictionaryEntryTextFields,
dictionaryEntryNumberFields,
dictionaryEntryBooleanFields,
dictionaryEntryPhoneticsTextFields,
dictionaryEntryPashtoTextFields,
// TYPES
Types,
}