also added validation for all the variations in the optional fields

This commit is contained in:
adueck 2023-01-25 19:33:14 +05:00
parent b59709bc1c
commit 66989dee67
6 changed files with 67 additions and 25 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.6.0", "version": "5.7.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.6.0", "version": "5.7.0",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.6.0", "version": "5.7.0",
"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

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "5.6.0", "version": "5.7.0",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "5.6.0", "version": "5.7.0",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",

View File

@ -253,6 +253,32 @@ const toTest: {
erroneousFields: ["f"], erroneousFields: ["f"],
}, },
}, },
{
input: {"ts":1527815870,"i":183,"p":"اثر","f":"asar","g":"asar","e":"influence, impression, tracks, affect","r":4,"c":"n. m.","app":"اثرات, آثار","apf":"asráat, aasáar"},
output: { ok: true },
},
{
input: {"ts":1527815870,"i":183,"p":"اثر","f":"asar","g":"asar","e":"influence, impression, tracks, affect","r":4,"c":"n. m.","app":"اثرات, آثار","apf":"asráat, aa sáar"},
output: {
errors: ["spacing discrepency between app and apf"],
p: "اثر",
f: "asar",
e: "influence, impression, tracks, affect",
ts: 1527815870,
erroneousFields: ["app", "apf"],
},
},
{
input: {"ts":1527815870,"i":183,"p":"اثر","f":"asar","g":"asar","e":"influence, impression, tracks, affect","r":4,"c":"n. m.","app":"اثرات, آثار","apf":"asráat"},
output: {
errors: ["difference in variation length between app and apf", "script and phonetics do not match for app and apf"],
p: "اثر",
f: "asar",
e: "influence, impression, tracks, affect",
ts: 1527815870,
erroneousFields: ["app", "apf"],
},
},
]; ];
test("validateEntry should work", () => { test("validateEntry should work", () => {

View File

@ -83,33 +83,49 @@ export function validateEntry(entry: T.DictionaryEntry): T.DictionaryEntryError
erroneousFields.add(errField); erroneousFields.add(errField);
return; return;
} }
if (!phoneticsToDiacritics(p, f) && !entry.diacExcept) { if (!isRequired && p.includes(", ")) {
errors.add(`script and phonetics do not match for ${pField} and ${fField}`); const pVars = p.split(", ");
erroneousFields.add(pField) const fVars = f.split(", ");
erroneousFields.add(fField); if (pVars.length !== fVars.length) {
} errors.add(`difference in variation length between ${pField} and ${fField}`);
const firstF = removeFVarients(f);
if (firstF.includes("-")) {
if (firstF.includes(" ")) {
errors.add(`presence of both hyphen and space in ${fField}`);
erroneousFields.add(fField);
}
const fWords = firstF.split("-");
const pWords = p.split(" ");
if (fWords.length !== pWords.length) {
errors.add(`hyphen/spacing discrepency between ${pField} and ${fField}`);
erroneousFields.add(pField); erroneousFields.add(pField);
erroneousFields.add(fField); erroneousFields.add(fField);
} }
pVars.forEach((pVar, i) => {
checkPhoneticsAndSpacing(pVar, fVars[i] || "");
});
} else { } else {
// check spacing checkPhoneticsAndSpacing(p, f);
const fWords = firstF.split(" "); }
const pWords = p.split(" "); function checkPhoneticsAndSpacing(p: string, f: string) {
if (fWords.length !== pWords.length) { if (!phoneticsToDiacritics(p, f) && !entry.diacExcept) {
errors.add(`spacing discrepency between ${pField} and ${fField}`); errors.add(`script and phonetics do not match for ${pField} and ${fField}`);
erroneousFields.add(pField); erroneousFields.add(pField);
erroneousFields.add(fField); erroneousFields.add(fField);
} }
const firstF = removeFVarients(f);
if (firstF.includes("-")) {
if (firstF.includes(" ")) {
errors.add(`presence of both hyphen and space in ${fField}`);
erroneousFields.add(fField);
}
const fWords = firstF.split("-");
const pWords = p.split(" ");
if (fWords.length !== pWords.length) {
errors.add(`hyphen/spacing discrepency between ${pField} and ${fField}`);
erroneousFields.add(pField);
erroneousFields.add(fField);
}
} else {
// check spacing
const fWords = firstF.split(" ");
const pWords = p.split(" ");
if (fWords.length !== pWords.length) {
errors.add(`spacing discrepency between ${pField} and ${fField}`);
erroneousFields.add(pField);
erroneousFields.add(fField);
}
}
} }
}); });
if ((entry.separationAtP && !entry.separationAtF)) { if ((entry.separationAtP && !entry.separationAtF)) {