handle sandwiches in word split

This commit is contained in:
adueck 2023-01-26 14:52:42 +05:00
parent 752482b00a
commit 488966e0fd
6 changed files with 21 additions and 12 deletions

4
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.7.1", "version": "5.7.2",
"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.7.1", "version": "5.7.2",
"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.7.1", "version": "5.7.2",
"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

@ -86,6 +86,10 @@ const toTest: {
f: "kawul", f: "kawul",
}], }],
}, },
{
input: { p: "د ... په شان", f: "du ... pu shaan" },
result: [{ p: "د", f: "du" }, { p: "په", f: "pu" }, { p: "شان", f: "shaan" }],
},
]; ];
test("splitPsString should work", () => { test("splitPsString should work", () => {

View File

@ -34,16 +34,21 @@ export function splitPsString(ps: T.PsStringNoFVars): T.PsWord[] {
fIndex++; fIndex++;
} }
while (pIndex < pWords.length && fIndex < fWords.length) { while (pIndex < pWords.length && fIndex < fWords.length) {
if (fWords[fIndex].includes("-")) { if (fWords[fIndex] === "..." && pWords[pIndex] === "...") {
processHyphen();
} else {
psWords.push({
p: pWords[pIndex],
f: fWords[fIndex],
});
pIndex++; pIndex++;
fIndex++; fIndex++;
continue;
} }
if (fWords[fIndex].includes("-")) {
processHyphen();
continue;
}
psWords.push({
p: pWords[pIndex],
f: fWords[fIndex],
});
pIndex++;
fIndex++;
} }
// should have processed all the p an f words // should have processed all the p an f words
if (pIndex !== pWords.length || fIndex !== fWords.length) { if (pIndex !== pWords.length || fIndex !== fWords.length) {