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",
"version": "5.6.0",
"version": "5.7.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "pashto-inflector",
"version": "5.6.0",
"version": "5.7.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {

View File

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

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

View File

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

View File

@ -253,6 +253,32 @@ const toTest: {
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", () => {

View File

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