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", "name": "@lingdocs/pashto-inflector",
"version": "1.0.3", "version": "1.0.4",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -26,9 +26,10 @@ export const dictionaryEntryTextFields: T.DictionaryEntryTextField[] = [
"ec", "ec",
"ep", "ep",
]; ];
export const dictionaryEntryBooleanFields: T.DictionaryEntryBooleanField[] = [ export const dictionaryEntryBooleanFields: T.DictionaryEntryBooleanField[] = [
"noInf", "shortIntrans", "noOo", "sepOo", "diacExcept", "noInf", "shortIntrans", "noOo", "sepOo", "diacExcept",
] ];
export const dictionaryEntryNumberFields: T.DictionaryEntryNumberField[] = [ export const dictionaryEntryNumberFields: T.DictionaryEntryNumberField[] = [
"ts", "i", "l", "separationAtP", "separationAtF", "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 * as T from "../types";
import { standardizePhonetics } from "./standardize-pashto";
const toTest: { const toTest: {
input: any, input: any,
@ -159,3 +160,8 @@ test("validateEntry should work", () => {
expect(validateEntry(t.input as T.DictionaryEntry)).toEqual(t.output); 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 { import {
phoneticsToDiacritics, phoneticsToDiacritics,
} from "./phonetics-to-diacritics"; } from "./phonetics-to-diacritics";
import { standardizePashto, standardizePhonetics } from "./standardize-pashto";
const textFieldPairs: [T.DictionaryEntryTextField, T.DictionaryEntryTextField][] = [ const textFieldPairs: [T.DictionaryEntryTextField, T.DictionaryEntryTextField][] = [
["p", "f"], ["p", "f"],
@ -28,6 +29,20 @@ const requiredFields: T.DictionaryEntryField[] = [
"ts", "i", "p", "f", "e", "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 | { export function validateEntry(entry: T.DictionaryEntry): T.DictionaryEntryError | {
ok: true, ok: true,
} | { } | {

View File

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