phonetics conversion done
This commit is contained in:
parent
fc97db0dd3
commit
c0cd34c3d6
|
@ -1,46 +1,93 @@
|
|||
import * as T from "../../../types";
|
||||
import classNames from "classnames";
|
||||
import { getEnglishFromRendered } from "../../../lib/src/phrase-building/np-tools";
|
||||
import {
|
||||
getEnglishFromRendered,
|
||||
} from "../../../lib/src/phrase-building/np-tools";
|
||||
import { getEnglishPersonInfo, getEnglishParticipleInflection, getEnglishGenNumInfo } from "../../../lib/src/misc-helpers";
|
||||
getEnglishPersonInfo,
|
||||
getEnglishParticipleInflection,
|
||||
getEnglishGenNumInfo,
|
||||
} from "../../../lib/src/misc-helpers";
|
||||
import { useState } from "react";
|
||||
import { getLength } from "../../../lib/src/p-text-helpers";
|
||||
import { roleIcon } from "../vp-explorer/VPExplorerExplanationModal";
|
||||
import { negativeParticle } from "../../../lib/src/grammar-units";
|
||||
|
||||
function Block({ opts, block, king, script }: {
|
||||
opts: T.TextOptions,
|
||||
block: T.Block,
|
||||
king?: "subject" | "object" | undefined,
|
||||
function Block({
|
||||
opts,
|
||||
block,
|
||||
king,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
block: T.Block;
|
||||
king?: "subject" | "object" | undefined;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
if ("equative" in block.block) {
|
||||
return <EquativeBlock opts={opts} eq={block.block.equative} script={script} />;
|
||||
return (
|
||||
<EquativeBlock opts={opts} eq={block.block.equative} script={script} />
|
||||
);
|
||||
}
|
||||
if (block.block.type === "AP") {
|
||||
const english = getEnglishFromRendered(block.block);
|
||||
return <APBlock opts={opts} english={english} script={script}>{block.block}</APBlock>
|
||||
return (
|
||||
<APBlock opts={opts} english={english} script={script}>
|
||||
{block.block}
|
||||
</APBlock>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "subjectSelection") {
|
||||
const role = king === "subject" ? "king" : king === "object" ? "servant" : undefined;
|
||||
return <SubjectBlock opts={opts} np={block.block.selection} role={role} script={script} />
|
||||
const role =
|
||||
king === "subject" ? "king" : king === "object" ? "servant" : undefined;
|
||||
return (
|
||||
<SubjectBlock
|
||||
opts={opts}
|
||||
np={block.block.selection}
|
||||
role={role}
|
||||
script={script}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "objectSelection") {
|
||||
const role = king === "object" ? "king" : king === "subject" ? "servant" : undefined;
|
||||
return <ObjectBlock opts={opts} obj={block.block.selection} role={role} script={script} />;
|
||||
const role =
|
||||
king === "object" ? "king" : king === "subject" ? "servant" : undefined;
|
||||
return (
|
||||
<ObjectBlock
|
||||
opts={opts}
|
||||
obj={block.block.selection}
|
||||
role={role}
|
||||
script={script}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "predicateSelection") {
|
||||
const english = getEnglishFromRendered(block.block.selection);
|
||||
return <div className="text-center">
|
||||
<div><strong>Predicate</strong></div>
|
||||
{block.block.selection.type === "complement"
|
||||
? <ComplementBlock opts={opts} comp={block.block.selection.selection} script={script} />
|
||||
: <NPBlock opts={opts} english={english} script={script}>{block.block.selection}</NPBlock>}
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div>
|
||||
<strong>Predicate</strong>
|
||||
</div>
|
||||
{block.block.selection.type === "complement" ? (
|
||||
<ComplementBlock
|
||||
opts={opts}
|
||||
comp={block.block.selection.selection}
|
||||
script={script}
|
||||
/>
|
||||
) : (
|
||||
<NPBlock opts={opts} english={english} script={script}>
|
||||
{block.block.selection}
|
||||
</NPBlock>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "negative") {
|
||||
return <NegBlock opts={opts} imperative={block.block.imperative} script={script} />
|
||||
return (
|
||||
<NegBlock
|
||||
opts={opts}
|
||||
imperative={block.block.imperative}
|
||||
script={script}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "PH") {
|
||||
return <PerfHeadBlock opts={opts} ps={block.block.ps} script={script} />;
|
||||
|
@ -49,19 +96,36 @@ function Block({ opts, block, king, script }: {
|
|||
return <VBBlock opts={opts} block={block.block} script={script} />;
|
||||
}
|
||||
if (block.block.type === "complement") {
|
||||
return <ComplementBlock opts={opts} comp={block.block.selection} script={script} />
|
||||
return (
|
||||
<ComplementBlock
|
||||
opts={opts}
|
||||
comp={block.block.selection}
|
||||
script={script}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (block.block.type === "NComp") {
|
||||
return <NCompBlock opts={opts} comp={block.block.comp} script={script} />
|
||||
return <NCompBlock opts={opts} comp={block.block.comp} script={script} />;
|
||||
}
|
||||
return <WeldedBlock opts={opts} welded={block.block} script={script} />
|
||||
return <WeldedBlock opts={opts} welded={block.block} script={script} />;
|
||||
}
|
||||
|
||||
export default Block;
|
||||
|
||||
function Border({ children, extraClassName, padding }: { children: JSX.Element | JSX.Element[] | string, extraClassName?: string, padding?: string }) {
|
||||
return <div
|
||||
className={`block-border d-flex flex-row justify-content-center align-items-center ${extraClassName ? extraClassName : ""}`}
|
||||
function Border({
|
||||
children,
|
||||
extraClassName,
|
||||
padding,
|
||||
}: {
|
||||
children: JSX.Element | JSX.Element[] | string;
|
||||
extraClassName?: string;
|
||||
padding?: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`block-border d-flex flex-row justify-content-center align-items-center ${
|
||||
extraClassName ? extraClassName : ""
|
||||
}`}
|
||||
style={{
|
||||
padding: padding ? padding : "1rem",
|
||||
textAlign: "center",
|
||||
|
@ -70,65 +134,93 @@ function Border({ children, extraClassName, padding }: { children: JSX.Element |
|
|||
>
|
||||
<>{children}</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function VBBlock({ opts, block, script }: {
|
||||
opts: T.TextOptions,
|
||||
script: "p" | "f",
|
||||
block: T.VBBasic | T.VBGenNum | (T.VBBasic & {
|
||||
function VBBlock({
|
||||
opts,
|
||||
block,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
script: "p" | "f";
|
||||
block:
|
||||
| T.VBBasic
|
||||
| T.VBGenNum
|
||||
| (T.VBBasic & {
|
||||
person: T.Person;
|
||||
}),
|
||||
});
|
||||
}) {
|
||||
const [length, setLength] = useState<T.Length>("long");
|
||||
const [version, setVersion] = useState<number>(0);
|
||||
const ps = getLength(block.ps, length);
|
||||
function changeVersion() {
|
||||
setVersion(o => (o + 1) % ps.length);
|
||||
setVersion((o) => (o + 1) % ps.length);
|
||||
}
|
||||
function changeLength() {
|
||||
setLength(o => (
|
||||
setLength((o) =>
|
||||
o === "long"
|
||||
? "short"
|
||||
: o === "short" && "mini" in block.ps
|
||||
? "mini"
|
||||
: "long"
|
||||
));
|
||||
);
|
||||
}
|
||||
const infInfo = "gender" in block
|
||||
const infInfo =
|
||||
"gender" in block
|
||||
? getEnglishGenNumInfo(block.gender, block.number)
|
||||
: "person" in block
|
||||
? getEnglishPersonInfo(block.person, "short")
|
||||
: "";
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div className="d-flex flex-row justify-content-around">
|
||||
{"long" in block.ps && <div className="clickable small mb-1" onClick={changeLength}>{length}</div>}
|
||||
{ps.length > 1 && <div className="clickable small mb-1" onClick={changeVersion}>v. {version + 1}</div>}
|
||||
{"long" in block.ps && (
|
||||
<div className="clickable small mb-1" onClick={changeLength}>
|
||||
{length}
|
||||
</div>
|
||||
)}
|
||||
{ps.length > 1 && (
|
||||
<div className="clickable small mb-1" onClick={changeVersion}>
|
||||
v. {version + 1}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Border>
|
||||
<>
|
||||
{ps[version][script]}
|
||||
</>
|
||||
<>{ps[version][script]}</>
|
||||
</Border>
|
||||
<div>VBlock</div>
|
||||
<SubText>{infInfo}</SubText>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WeldedBlock({ opts, welded, script }: {
|
||||
opts: T.TextOptions,
|
||||
script: "p" | "f",
|
||||
welded: T.Welded,
|
||||
function WeldedBlock({
|
||||
opts,
|
||||
welded,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
script: "p" | "f";
|
||||
welded: T.Welded;
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
<Border padding="0.5rem" extraClassName={script === "p" ? "flex-row-reverse" : ""}>
|
||||
{welded.left.type === "NComp"
|
||||
? <NCompBlock opts={opts} comp={welded.left.comp} script={script} />
|
||||
: welded.left.type === "VB"
|
||||
? <VBBlock opts={opts} block={welded.left} script={script} />
|
||||
: <WeldedBlock opts={opts} welded={welded.left} script={script} />}
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border
|
||||
padding="0.5rem"
|
||||
extraClassName={script === "p" ? "flex-row-reverse" : ""}
|
||||
>
|
||||
{welded.left.type === "NComp" ? (
|
||||
<NCompBlock opts={opts} comp={welded.left.comp} script={script} />
|
||||
) : welded.left.type === "VB" ? (
|
||||
<VBBlock opts={opts} block={welded.left} script={script} />
|
||||
) : (
|
||||
<WeldedBlock opts={opts} welded={welded.left} script={script} />
|
||||
)}
|
||||
<VBBlock opts={opts} block={welded.right} script={script} />
|
||||
</Border>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// function VerbSBlock({ opts, v, script }: {
|
||||
|
@ -192,19 +284,22 @@ function WeldedBlock({ opts, welded, script }: {
|
|||
// </div>
|
||||
// }
|
||||
|
||||
function PerfHeadBlock({ opts, ps, script }: {
|
||||
opts: T.TextOptions,
|
||||
ps: T.PsString,
|
||||
script: "p" | "f",
|
||||
|
||||
function PerfHeadBlock({
|
||||
opts,
|
||||
ps,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
ps: T.PsString;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
<Border>
|
||||
{ps[script]}
|
||||
</Border>
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>{ps[script]}</Border>
|
||||
<div>perf. head</div>
|
||||
<SubText>{'\u00A0'}</SubText>
|
||||
</div>;
|
||||
<SubText>{"\u00A0"}</SubText>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// function ModalAuxBlock({ opts, aux, script }: {
|
||||
|
@ -222,249 +317,389 @@ function PerfHeadBlock({ opts, ps, script }: {
|
|||
// </div>;
|
||||
// }
|
||||
|
||||
function NegBlock({ opts, imperative, script }: {
|
||||
opts: T.TextOptions,
|
||||
imperative: boolean,
|
||||
script: "p" | "f",
|
||||
function NegBlock({
|
||||
opts,
|
||||
imperative,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
imperative: boolean;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>
|
||||
{negativeParticle[imperative ? "imperative" : "nonImperative"][script]}
|
||||
</Border>
|
||||
<div>Neg.</div>
|
||||
<SubText>{imperative ? "don't" : "not"}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EquativeBlock({ opts, eq, script }: {
|
||||
opts: T.TextOptions,
|
||||
eq: T.EquativeRendered,
|
||||
script: "p" | "f",
|
||||
function EquativeBlock({
|
||||
opts,
|
||||
eq,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
eq: T.EquativeRendered;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
const [length, setLength] = useState<T.Length>("long");
|
||||
function changeLength() {
|
||||
setLength(o => (
|
||||
setLength((o) =>
|
||||
o === "long"
|
||||
? "short"
|
||||
: o === "short" && "mini" in eq.ps
|
||||
? "mini"
|
||||
: "long"
|
||||
));
|
||||
);
|
||||
}
|
||||
return <div className="text-center">
|
||||
{"long" in eq.ps && <div className="clickable small mb-1" onClick={changeLength}>{length}</div>}
|
||||
<Border>
|
||||
{getLength(eq.ps, length)[0][script]}
|
||||
</Border>
|
||||
return (
|
||||
<div className="text-center">
|
||||
{"long" in eq.ps && (
|
||||
<div className="clickable small mb-1" onClick={changeLength}>
|
||||
{length}
|
||||
</div>
|
||||
)}
|
||||
<Border>{getLength(eq.ps, length)[0][script]}</Border>
|
||||
<div>Equative</div>
|
||||
<SubText>{getEnglishPersonInfo(eq.person, "short")}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SubjectBlock({ opts, np, role, script }: {
|
||||
opts: T.TextOptions,
|
||||
np: T.Rendered<T.NPSelection>,
|
||||
role: "king" | "servant" | undefined,
|
||||
script: "p" | "f",
|
||||
function SubjectBlock({
|
||||
opts,
|
||||
np,
|
||||
role,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
np: T.Rendered<T.NPSelection>;
|
||||
role: "king" | "servant" | undefined;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
const english = getEnglishFromRendered(np);
|
||||
return <div className="text-center">
|
||||
<div><strong>Subject</strong>{role ? roleIcon[role] : ""}</div>
|
||||
<NPBlock opts={opts} english={english} script={script}>{np}</NPBlock>
|
||||
</div>;
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div>
|
||||
<strong>Subject</strong>
|
||||
{role ? roleIcon[role] : ""}
|
||||
</div>
|
||||
<NPBlock opts={opts} english={english} script={script}>
|
||||
{np}
|
||||
</NPBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ObjectBlock({ opts, obj, role, script }: {
|
||||
opts: T.TextOptions,
|
||||
obj: T.Rendered<T.ObjectSelectionComplete>["selection"],
|
||||
role: "king" | "servant" | undefined,
|
||||
script: "p" | "f",
|
||||
function ObjectBlock({
|
||||
opts,
|
||||
obj,
|
||||
role,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
obj: T.Rendered<T.ObjectSelectionComplete>["selection"];
|
||||
role: "king" | "servant" | undefined;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
if (typeof obj !== "object") {
|
||||
return null;
|
||||
}
|
||||
const english = getEnglishFromRendered(obj);
|
||||
return <div className="text-center">
|
||||
<div><strong>Object</strong>{role ? roleIcon[role] : ""}</div>
|
||||
<NPBlock opts={opts} english={english} script={script}>{obj}</NPBlock>
|
||||
</div>;
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div>
|
||||
<strong>Object</strong>
|
||||
{role ? roleIcon[role] : ""}
|
||||
</div>
|
||||
<NPBlock opts={opts} english={english} script={script}>
|
||||
{obj}
|
||||
</NPBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NCompBlock({ opts, comp, script }: {
|
||||
script: "p" | "f",
|
||||
opts: T.TextOptions,
|
||||
comp: T.Comp,
|
||||
function NCompBlock({
|
||||
opts,
|
||||
comp,
|
||||
script,
|
||||
}: {
|
||||
script: "p" | "f";
|
||||
opts: T.TextOptions;
|
||||
comp: T.Comp;
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
<Border>
|
||||
{comp.ps[script]}
|
||||
</Border>
|
||||
{comp.type === "AdjComp"
|
||||
? <div>adj. <span className="text-muted small">{getEnglishGenNumInfo(comp.gender, comp.number)}</span></div>
|
||||
: <div>TODO</div>}
|
||||
<SubText>
|
||||
todo
|
||||
{/* {adj.e} */}
|
||||
</SubText>
|
||||
</div>;
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>{comp.ps[script]}</Border>
|
||||
{comp.type === "AdjComp" && (
|
||||
<div>
|
||||
<div>
|
||||
adj.{" "}
|
||||
<span className="text-muted small">
|
||||
{getEnglishGenNumInfo(comp.gender, comp.number)}
|
||||
</span>
|
||||
</div>
|
||||
<SubText>{comp.ps.e}</SubText>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ComplementBlock({ opts, comp, script, inside }: {
|
||||
script: "p" | "f",
|
||||
opts: T.TextOptions,
|
||||
comp: T.Rendered<T.ComplementSelection["selection"]> | T.Rendered<T.UnselectedComplementSelection>["selection"],
|
||||
inside?: boolean,
|
||||
function ComplementBlock({
|
||||
opts,
|
||||
comp,
|
||||
script,
|
||||
inside,
|
||||
}: {
|
||||
script: "p" | "f";
|
||||
opts: T.TextOptions;
|
||||
comp:
|
||||
| T.Rendered<T.ComplementSelection["selection"]>
|
||||
| T.Rendered<T.UnselectedComplementSelection>["selection"];
|
||||
inside?: boolean;
|
||||
}) {
|
||||
function AdjectiveBlock({ opts, adj }: {
|
||||
opts: T.TextOptions,
|
||||
adj: T.Rendered<T.AdjectiveSelection>,
|
||||
function AdjectiveBlock({
|
||||
opts,
|
||||
adj,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
adj: T.Rendered<T.AdjectiveSelection>;
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
<Border>
|
||||
{adj.ps[0][script]}
|
||||
</Border>
|
||||
<div>Adj. <span className="text-muted small">({getEnglishParticipleInflection(adj.person, "short")})</span></div>
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>{adj.ps[0][script]}</Border>
|
||||
<div>
|
||||
Adj.{" "}
|
||||
<span className="text-muted small">
|
||||
({getEnglishParticipleInflection(adj.person, "short")})
|
||||
</span>
|
||||
</div>
|
||||
<SubText>{adj.e}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LocAdvBlock({ opts, adv }: {
|
||||
opts: T.TextOptions,
|
||||
adv: T.Rendered<T.LocativeAdverbSelection>,
|
||||
function LocAdvBlock({
|
||||
opts,
|
||||
adv,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
adv: T.Rendered<T.LocativeAdverbSelection>;
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
<Border>
|
||||
{adv.ps[0][script]}
|
||||
</Border>
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>{adv.ps[0][script]}</Border>
|
||||
<div>Loc. Adv.</div>
|
||||
<SubText>{adv.e}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div>Complement</div>
|
||||
{comp.type === "adjective"
|
||||
? <AdjectiveBlock opts={opts} adj={comp} />
|
||||
: comp.type === "loc. adv."
|
||||
? <LocAdvBlock opts={opts} adv={comp} />
|
||||
: comp.type === "noun"
|
||||
? <CompNounBlock opts={opts} noun={comp} script={script} />
|
||||
: comp.type === "unselected"
|
||||
? <div>
|
||||
<Border>
|
||||
____
|
||||
</Border>
|
||||
{!inside && <>
|
||||
{comp.type === "adjective" ? (
|
||||
<AdjectiveBlock opts={opts} adj={comp} />
|
||||
) : comp.type === "loc. adv." ? (
|
||||
<LocAdvBlock opts={opts} adv={comp} />
|
||||
) : comp.type === "noun" ? (
|
||||
<CompNounBlock opts={opts} noun={comp} script={script} />
|
||||
) : comp.type === "unselected" ? (
|
||||
<div>
|
||||
<Border>____</Border>
|
||||
{!inside && (
|
||||
<>
|
||||
<div> </div>
|
||||
<SubText>{comp.e}</SubText>
|
||||
</>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
: <div>
|
||||
) : (
|
||||
<div>
|
||||
<Sandwich opts={opts} sandwich={comp} script={script} />
|
||||
<div>Sandwich</div>
|
||||
<SubText>{comp.e}</SubText>
|
||||
</div>}
|
||||
</div>;
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function APBlock({ opts, children, english, script }: {
|
||||
opts: T.TextOptions,
|
||||
children: T.Rendered<T.APSelection>,
|
||||
english?: string,
|
||||
script: "p" | "f",
|
||||
export function APBlock({
|
||||
opts,
|
||||
children,
|
||||
english,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
children: T.Rendered<T.APSelection>;
|
||||
english?: string;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
const ap = children;
|
||||
if (ap.selection.type === "adverb") {
|
||||
return <div className="text-center">
|
||||
<Border>
|
||||
{ap.selection.ps[0][script]}
|
||||
</Border>
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border>{ap.selection.ps[0][script]}</Border>
|
||||
<div>AP</div>
|
||||
<SubText>{english}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <div>
|
||||
return (
|
||||
<div>
|
||||
<Sandwich opts={opts} sandwich={ap.selection} script={script} />
|
||||
<div>AP</div>
|
||||
<SubText>{english}</SubText>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Sandwich({ opts, sandwich, script }: {
|
||||
opts: T.TextOptions,
|
||||
sandwich: T.Rendered<T.SandwichSelection<T.Sandwich>>,
|
||||
script: "p" | "f",
|
||||
function Sandwich({
|
||||
opts,
|
||||
sandwich,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
sandwich: T.Rendered<T.SandwichSelection<T.Sandwich>>;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div className="text-center">Sandwich 🥪</div>
|
||||
<Border padding="0.75rem 0.5rem 0.25rem 0.5rem">
|
||||
<div className={`d-flex flex-row${script === "p" ? "-reverse" : ""} justify-content-between align-items-end`}>
|
||||
<Possesors opts={opts} script={script}>{sandwich.inside.selection.type !== "pronoun" ? sandwich.inside.selection.possesor : undefined}</Possesors>
|
||||
<div className="mr-2 ml-1 mb-1"><strong>{sandwich.before ? sandwich.before.f : ""}</strong></div>
|
||||
<div>
|
||||
<NPBlock opts={opts} inside script={script}>{sandwich.inside}</NPBlock>
|
||||
<div
|
||||
className={`d-flex flex-row${
|
||||
script === "p" ? "-reverse" : ""
|
||||
} justify-content-between align-items-end`}
|
||||
>
|
||||
<Possesors opts={opts} script={script}>
|
||||
{sandwich.inside.selection.type !== "pronoun"
|
||||
? sandwich.inside.selection.possesor
|
||||
: undefined}
|
||||
</Possesors>
|
||||
<div className="mr-2 ml-1 mb-1">
|
||||
<strong>{sandwich.before ? sandwich.before.f : ""}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<NPBlock opts={opts} inside script={script}>
|
||||
{sandwich.inside}
|
||||
</NPBlock>
|
||||
</div>
|
||||
<div className="ml-2 mr-1 mb-1">
|
||||
<strong>{sandwich.after ? sandwich.after.f : ""}</strong>
|
||||
</div>
|
||||
<div className="ml-2 mr-1 mb-1"><strong>{sandwich.after ? sandwich.after.f : ""}</strong></div>
|
||||
</div>
|
||||
</Border>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CompNounBlock({ opts, noun, script }: {
|
||||
opts: T.TextOptions,
|
||||
noun: T.Rendered<T.NounSelection>,
|
||||
script: "p" | "f",
|
||||
function CompNounBlock({
|
||||
opts,
|
||||
noun,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
noun: T.Rendered<T.NounSelection>;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border
|
||||
extraClassName={`!inside && hasPossesor ? "pt-2" : ""`}
|
||||
padding={"1rem"}
|
||||
>
|
||||
{noun.ps[0][script]}
|
||||
</Border>
|
||||
<div>
|
||||
Comp. Noun
|
||||
</div>
|
||||
<div>Comp. Noun</div>
|
||||
<SubText>{noun.e}</SubText>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function NPBlock({ opts, children, inside, english, script }: {
|
||||
opts: T.TextOptions,
|
||||
children: T.Rendered<T.NPSelection>,
|
||||
inside?: boolean,
|
||||
english?: string,
|
||||
script: "p" | "f",
|
||||
export function NPBlock({
|
||||
opts,
|
||||
children,
|
||||
inside,
|
||||
english,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
children: T.Rendered<T.NPSelection>;
|
||||
inside?: boolean;
|
||||
english?: string;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
const np = children;
|
||||
const hasPossesor = !!(np.selection.type !== "pronoun" && np.selection.possesor && !np.selection.possesor.shrunken);
|
||||
const hasPossesor = !!(
|
||||
np.selection.type !== "pronoun" &&
|
||||
np.selection.possesor &&
|
||||
!np.selection.possesor.shrunken
|
||||
);
|
||||
const elements = [
|
||||
...!inside ? [<Possesors opts={opts} script={script}>{np.selection.type !== "pronoun" ? np.selection.possesor : undefined}</Possesors>] : [],
|
||||
<Adjectives opts={opts} script={script}>{np.selection.adjectives}</Adjectives>,
|
||||
<div className={np.selection.adjectives?.length ? "mx-1" : ""}> {np.selection.ps[0][script]}</div>,
|
||||
...(!inside
|
||||
? [
|
||||
<Possesors opts={opts} script={script}>
|
||||
{np.selection.type !== "pronoun"
|
||||
? np.selection.possesor
|
||||
: undefined}
|
||||
</Possesors>,
|
||||
]
|
||||
: []),
|
||||
<Adjectives opts={opts} script={script}>
|
||||
{np.selection.adjectives}
|
||||
</Adjectives>,
|
||||
<div className={np.selection.adjectives?.length ? "mx-1" : ""}>
|
||||
{" "}
|
||||
{np.selection.ps[0][script]}
|
||||
</div>,
|
||||
];
|
||||
const el = script === "p" ? elements.reverse() : elements;
|
||||
return <div className="text-center">
|
||||
return (
|
||||
<div className="text-center">
|
||||
<Border
|
||||
extraClassName={`!inside && hasPossesor ? "pt-2" : ""`}
|
||||
padding={inside ? "0.3rem" : hasPossesor ? "0.5rem 0.8rem 0.25rem 0.8rem" : "1rem"}
|
||||
padding={
|
||||
inside
|
||||
? "0.3rem"
|
||||
: hasPossesor
|
||||
? "0.5rem 0.8rem 0.25rem 0.8rem"
|
||||
: "1rem"
|
||||
}
|
||||
>
|
||||
{el}
|
||||
</Border>
|
||||
<div className={inside ? "small" : ""}>
|
||||
NP
|
||||
{!inside ? <>
|
||||
{!inside ? (
|
||||
<>
|
||||
{` `}
|
||||
<span className="text-muted small">({getEnglishPersonInfo(np.selection.person, "short")})</span>
|
||||
</> : <></>}
|
||||
<span className="text-muted small">
|
||||
({getEnglishPersonInfo(np.selection.person, "short")})
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
{!inside && <SubText>{english}</SubText>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Possesors({ opts, children, script }: {
|
||||
opts: T.TextOptions,
|
||||
children: { shrunken: boolean, np: T.Rendered<T.NPSelection> } | undefined,
|
||||
script: "p" | "f",
|
||||
function Possesors({
|
||||
opts,
|
||||
children,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
children: { shrunken: boolean; np: T.Rendered<T.NPSelection> } | undefined;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
if (!children) {
|
||||
return null;
|
||||
|
@ -473,62 +708,107 @@ function Possesors({ opts, children, script }: {
|
|||
return null;
|
||||
}
|
||||
const contraction = checkForContraction(children.np, script);
|
||||
return <div className={`d-flex flex-row${script === "p" ? "-reverse" : ""} mr-1 align-items-end`} style={{
|
||||
return (
|
||||
<div
|
||||
className={`d-flex flex-row${
|
||||
script === "p" ? "-reverse" : ""
|
||||
} mr-1 align-items-end`}
|
||||
style={{
|
||||
marginBottom: "0.5rem",
|
||||
borderBottom: "1px solid grey",
|
||||
}}>
|
||||
{children.np.selection.type !== "pronoun" && <Possesors opts={opts} script={script}>{children.np.selection.possesor}</Possesors>}
|
||||
}}
|
||||
>
|
||||
{children.np.selection.type !== "pronoun" && (
|
||||
<Possesors opts={opts} script={script}>
|
||||
{children.np.selection.possesor}
|
||||
</Possesors>
|
||||
)}
|
||||
<div>
|
||||
{contraction && <div className="mb-1">({contraction})</div>}
|
||||
<div className={classNames("d-flex", (script === "f" ? "flex-row" : "flex-row-reverse"), "align-items-center", { "text-muted": contraction })}>
|
||||
<div
|
||||
className={classNames(
|
||||
"d-flex",
|
||||
script === "f" ? "flex-row" : "flex-row-reverse",
|
||||
"align-items-center",
|
||||
{ "text-muted": contraction }
|
||||
)}
|
||||
>
|
||||
<div className="mx-1 pb-2">{script === "p" ? "د" : "du"}</div>
|
||||
<div>
|
||||
<NPBlock script={script} opts={opts} inside>{children.np}</NPBlock>
|
||||
<NPBlock script={script} opts={opts} inside>
|
||||
{children.np}
|
||||
</NPBlock>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Adjectives({ opts, children, script }: {
|
||||
opts: T.TextOptions,
|
||||
children: T.Rendered<T.AdjectiveSelection>[] | undefined,
|
||||
script: "p" | "f",
|
||||
function Adjectives({
|
||||
opts,
|
||||
children,
|
||||
script,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
children: T.Rendered<T.AdjectiveSelection>[] | undefined;
|
||||
script: "p" | "f";
|
||||
}) {
|
||||
if (!children) {
|
||||
return null;
|
||||
}
|
||||
const c = script === "p"
|
||||
? children.reverse()
|
||||
: children;
|
||||
return <em className="mr-1">
|
||||
{c.map(a => a.ps[0][script]).join(" ")}{` `}
|
||||
const c = script === "p" ? children.reverse() : children;
|
||||
return (
|
||||
<em className="mr-1">
|
||||
{c.map((a) => a.ps[0][script]).join(" ")}
|
||||
{` `}
|
||||
</em>
|
||||
);
|
||||
}
|
||||
|
||||
function SubText({ children: e }: { children: string | undefined }) {
|
||||
return <div className="small text-muted text-center" style={{
|
||||
return (
|
||||
<div
|
||||
className="small text-muted text-center"
|
||||
style={{
|
||||
margin: "0 auto",
|
||||
maxWidth: "300px",
|
||||
height: "1rem",
|
||||
}}>{e ? e : ""}</div>;
|
||||
}}
|
||||
>
|
||||
{e ? e : ""}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function checkForContraction(np: T.Rendered<T.NPSelection>, script: "p" | "f"): string | undefined {
|
||||
function checkForContraction(
|
||||
np: T.Rendered<T.NPSelection>,
|
||||
script: "p" | "f"
|
||||
): string | undefined {
|
||||
if (np.selection.type !== "pronoun") return undefined;
|
||||
if (np.selection.person === T.Person.FirstSingMale || np.selection.person === T.Person.FirstSingFemale) {
|
||||
if (
|
||||
np.selection.person === T.Person.FirstSingMale ||
|
||||
np.selection.person === T.Person.FirstSingFemale
|
||||
) {
|
||||
return script === "f" ? "zmaa" : "زما";
|
||||
}
|
||||
if (np.selection.person === T.Person.SecondSingMale || np.selection.person === T.Person.SecondSingFemale) {
|
||||
if (
|
||||
np.selection.person === T.Person.SecondSingMale ||
|
||||
np.selection.person === T.Person.SecondSingFemale
|
||||
) {
|
||||
return script === "f" ? "staa" : "ستا";
|
||||
}
|
||||
if (np.selection.person === T.Person.FirstPlurMale || np.selection.person === T.Person.FirstPlurFemale) {
|
||||
if (
|
||||
np.selection.person === T.Person.FirstPlurMale ||
|
||||
np.selection.person === T.Person.FirstPlurFemale
|
||||
) {
|
||||
return script === "f" ? "zmoonG" : "زمونږ";
|
||||
}
|
||||
if (np.selection.person === T.Person.SecondPlurMale || np.selection.person === T.Person.SecondPlurFemale) {
|
||||
if (
|
||||
np.selection.person === T.Person.SecondPlurMale ||
|
||||
np.selection.person === T.Person.SecondPlurFemale
|
||||
) {
|
||||
return script === "f" ? "staaso" : "ستاسو";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,24 +3,20 @@ import {
|
|||
last,
|
||||
addP,
|
||||
lastNonWhitespace,
|
||||
advanceP,
|
||||
reverseP,
|
||||
overwriteP,
|
||||
advanceForHamza,
|
||||
advanceForHamzaMid,
|
||||
} from "./diacritics-helpers";
|
||||
|
||||
const phonemeSplits: Array<{
|
||||
in: string,
|
||||
out: string[],
|
||||
in: string;
|
||||
out: string[];
|
||||
}> = [
|
||||
{
|
||||
in: "kor",
|
||||
out: ["k", "o", "r"],
|
||||
},
|
||||
{
|
||||
in: "raaghey",
|
||||
out: ["r", "aa", "gh", "ey"],
|
||||
in: "raaghay",
|
||||
out: ["r", "aa", "gh", "ay"],
|
||||
},
|
||||
{
|
||||
in: "ist'imaal",
|
||||
|
@ -35,16 +31,16 @@ const phonemeSplits: Array<{
|
|||
out: ["b", "a"],
|
||||
},
|
||||
{
|
||||
in: "peydáa",
|
||||
out: ["p", "ey", "d", "aa"],
|
||||
in: "paydáa",
|
||||
out: ["p", "ay", "d", "aa"],
|
||||
},
|
||||
{
|
||||
in: "be kaar",
|
||||
out: ["b", "e", "k", "aa", "r"],
|
||||
},
|
||||
{
|
||||
in: "raadzeyy",
|
||||
out: ["r", "aa", "dz", "eyy"],
|
||||
in: "raadzey",
|
||||
out: ["r", "aa", "dz", "ey"],
|
||||
},
|
||||
{
|
||||
in: "badanuy ??",
|
||||
|
@ -68,8 +64,8 @@ phonemeSplits.forEach((s) => {
|
|||
});
|
||||
|
||||
const badPhonetics: Array<{
|
||||
in: string,
|
||||
problem: string,
|
||||
in: string;
|
||||
problem: string;
|
||||
}> = [
|
||||
{
|
||||
in: "acar",
|
||||
|
@ -107,25 +103,31 @@ test("lastNonWhiteSpace should work", () => {
|
|||
});
|
||||
|
||||
test("reverseP should work", () => {
|
||||
expect(reverseP({
|
||||
expect(
|
||||
reverseP({
|
||||
pIn: "کور",
|
||||
pOut: "تور ",
|
||||
})).toEqual({
|
||||
})
|
||||
).toEqual({
|
||||
pIn: " کور",
|
||||
pOut: "تور",
|
||||
});
|
||||
expect(reverseP({
|
||||
expect(
|
||||
reverseP({
|
||||
pIn: "کور",
|
||||
pOut: "تور ... ",
|
||||
})).toEqual({
|
||||
})
|
||||
).toEqual({
|
||||
pIn: " ... کور",
|
||||
pOut: "تور",
|
||||
});
|
||||
expect(reverseP({
|
||||
expect(
|
||||
reverseP({
|
||||
pIn: "کور",
|
||||
pOut: "تور . ",
|
||||
})).toEqual({
|
||||
})
|
||||
).toEqual({
|
||||
pIn: " . کور",
|
||||
pOut: "تور",
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
@ -8,31 +8,62 @@
|
|||
|
||||
import { removeAccents } from "./accent-helpers";
|
||||
|
||||
export type DiacriticsAccumulator = { pIn: string, pOut: string };
|
||||
export type DiacriticsAccumulator = { pIn: string; pOut: string };
|
||||
|
||||
type Consonant = "b" | "p" | "t" | "T" | "s" | "j" | "ch" | "kh" | "ts" | "dz" | "d" | "D" | "r" | "R" | "z" | "jz" | "G" | "sh" | "x" | "gh" | "f" | "q" | "k" | "g" | "l" | "m" | "n" | "N" | "h" | "w" | "y";
|
||||
type Ain = "'"
|
||||
type Consonant =
|
||||
| "b"
|
||||
| "p"
|
||||
| "t"
|
||||
| "T"
|
||||
| "s"
|
||||
| "j"
|
||||
| "ch"
|
||||
| "kh"
|
||||
| "ts"
|
||||
| "dz"
|
||||
| "d"
|
||||
| "D"
|
||||
| "r"
|
||||
| "R"
|
||||
| "z"
|
||||
| "jz"
|
||||
| "G"
|
||||
| "sh"
|
||||
| "x"
|
||||
| "gh"
|
||||
| "f"
|
||||
| "q"
|
||||
| "k"
|
||||
| "g"
|
||||
| "l"
|
||||
| "m"
|
||||
| "n"
|
||||
| "N"
|
||||
| "h"
|
||||
| "w"
|
||||
| "y";
|
||||
type Ain = "'";
|
||||
type JoiningVowel = "-i-" | "-U-" | "-Ul-";
|
||||
type LongVowel = "aa" | "ee" | "e" | "oo" | "o" | "ey" | "uy" | "eyy";
|
||||
type LongVowel = "aa" | "ee" | "e" | "oo" | "o" | "ay" | "uy" | "ey";
|
||||
type ShortVowel = "a" | "i" | "u" | "U";
|
||||
export type Phoneme = Consonant | Ain | LongVowel | ShortVowel | JoiningVowel;
|
||||
|
||||
type PhonemeInfo = {
|
||||
matches?: string[],
|
||||
beginningMatches?: string[],
|
||||
endingMatches?: string[],
|
||||
consonant?: true,
|
||||
diacritic?: string,
|
||||
endingOnly?: true,
|
||||
takesSukunOnEnding?: true,
|
||||
longVowel?: true,
|
||||
canStartWithAynBefore?: true,
|
||||
useEndingDiacritic?: true,
|
||||
ainBlendDiacritic?: string,
|
||||
}
|
||||
matches?: string[];
|
||||
beginningMatches?: string[];
|
||||
endingMatches?: string[];
|
||||
consonant?: true;
|
||||
diacritic?: string;
|
||||
endingOnly?: true;
|
||||
takesSukunOnEnding?: true;
|
||||
longVowel?: true;
|
||||
canStartWithAynBefore?: true;
|
||||
useEndingDiacritic?: true;
|
||||
ainBlendDiacritic?: string;
|
||||
};
|
||||
|
||||
export const zwar = "َ";
|
||||
export const zwarakey = "ٙ";
|
||||
export const zwarakay = "ٙ";
|
||||
export const zer = "ِ";
|
||||
export const pesh = "ُ";
|
||||
export const sukun = "ْ";
|
||||
|
@ -44,128 +75,128 @@ export const fathahan = "ً";
|
|||
|
||||
export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
||||
// Consonants
|
||||
"b": {
|
||||
b: {
|
||||
matches: ["ب"],
|
||||
consonant: true,
|
||||
},
|
||||
"p": {
|
||||
p: {
|
||||
matches: ["پ"],
|
||||
consonant: true,
|
||||
},
|
||||
"t": {
|
||||
t: {
|
||||
matches: ["ت", "ط"],
|
||||
consonant: true,
|
||||
},
|
||||
"T": {
|
||||
T: {
|
||||
matches: ["ټ"],
|
||||
consonant: true,
|
||||
},
|
||||
"s": {
|
||||
s: {
|
||||
matches: ["س", "ص", "ث"],
|
||||
consonant: true,
|
||||
},
|
||||
"j": {
|
||||
j: {
|
||||
matches: ["ج"],
|
||||
consonant: true,
|
||||
},
|
||||
"ch": {
|
||||
ch: {
|
||||
matches: ["چ"],
|
||||
consonant: true,
|
||||
},
|
||||
"kh": {
|
||||
kh: {
|
||||
matches: ["خ"],
|
||||
consonant: true,
|
||||
},
|
||||
"ts": {
|
||||
ts: {
|
||||
matches: ["څ"],
|
||||
consonant: true,
|
||||
},
|
||||
"dz": {
|
||||
dz: {
|
||||
matches: ["ځ"],
|
||||
consonant: true,
|
||||
},
|
||||
"d": {
|
||||
d: {
|
||||
matches: ["د"],
|
||||
consonant: true,
|
||||
},
|
||||
"D": {
|
||||
D: {
|
||||
matches: ["ډ"],
|
||||
consonant: true,
|
||||
},
|
||||
"r": {
|
||||
r: {
|
||||
matches: ["ر"],
|
||||
consonant: true,
|
||||
},
|
||||
"R": {
|
||||
R: {
|
||||
matches: ["ړ"],
|
||||
consonant: true,
|
||||
},
|
||||
"z": {
|
||||
z: {
|
||||
matches: ["ز", "ذ", "ظ", "ض"],
|
||||
consonant: true,
|
||||
},
|
||||
"jz": {
|
||||
jz: {
|
||||
matches: ["ژ"],
|
||||
consonant: true,
|
||||
},
|
||||
"G": {
|
||||
G: {
|
||||
matches: ["ږ"],
|
||||
consonant: true,
|
||||
},
|
||||
"sh": {
|
||||
sh: {
|
||||
matches: ["ش"],
|
||||
consonant: true,
|
||||
},
|
||||
"x": {
|
||||
x: {
|
||||
matches: ["ښ"],
|
||||
consonant: true,
|
||||
},
|
||||
"gh": {
|
||||
gh: {
|
||||
matches: ["غ"],
|
||||
consonant: true,
|
||||
},
|
||||
"f": {
|
||||
f: {
|
||||
matches: ["ف"],
|
||||
consonant: true,
|
||||
},
|
||||
"q": {
|
||||
q: {
|
||||
matches: ["ق"],
|
||||
consonant: true,
|
||||
},
|
||||
"k": {
|
||||
k: {
|
||||
matches: ["ک"],
|
||||
consonant: true,
|
||||
},
|
||||
"g": {
|
||||
g: {
|
||||
matches: ["ګ"],
|
||||
consonant: true,
|
||||
},
|
||||
"l": {
|
||||
l: {
|
||||
matches: ["ل"],
|
||||
consonant: true,
|
||||
},
|
||||
"m": {
|
||||
m: {
|
||||
matches: ["م"],
|
||||
consonant: true,
|
||||
},
|
||||
"n": {
|
||||
n: {
|
||||
matches: ["ن"],
|
||||
consonant: true,
|
||||
},
|
||||
"N": {
|
||||
N: {
|
||||
matches: ["ڼ"],
|
||||
consonant: true,
|
||||
},
|
||||
"h": {
|
||||
h: {
|
||||
matches: ["ه", "ح"],
|
||||
consonant: true,
|
||||
takesSukunOnEnding: true,
|
||||
},
|
||||
"w": {
|
||||
w: {
|
||||
matches: ["و"],
|
||||
consonant: true,
|
||||
},
|
||||
"y": {
|
||||
y: {
|
||||
matches: ["ی"],
|
||||
consonant: true,
|
||||
},
|
||||
|
@ -175,8 +206,7 @@ export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
|||
consonant: true,
|
||||
},
|
||||
// Joining Vowels
|
||||
"-i-": {
|
||||
},
|
||||
"-i-": {},
|
||||
"-U-": {
|
||||
matches: [" و ", "و"],
|
||||
},
|
||||
|
@ -184,14 +214,14 @@ export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
|||
matches: ["ال"],
|
||||
},
|
||||
// Long Vowels
|
||||
"aa": {
|
||||
aa: {
|
||||
matches: ["ا", "أ"],
|
||||
beginningMatches: ["آ", "ا"],
|
||||
endingMatches: ["ا", "یٰ"],
|
||||
longVowel: true,
|
||||
ainBlendDiacritic: zwar,
|
||||
},
|
||||
"ee": {
|
||||
ee: {
|
||||
matches: ["ی"],
|
||||
longVowel: true,
|
||||
endingMatches: ["ي"],
|
||||
|
@ -199,61 +229,61 @@ export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
|||
canStartWithAynBefore: true,
|
||||
ainBlendDiacritic: zer,
|
||||
},
|
||||
"e": {
|
||||
e: {
|
||||
matches: ["ې"],
|
||||
longVowel: true,
|
||||
},
|
||||
"o": {
|
||||
o: {
|
||||
matches: ["و"],
|
||||
longVowel: true,
|
||||
},
|
||||
"oo": {
|
||||
oo: {
|
||||
matches: ["و"],
|
||||
longVowel: true,
|
||||
diacritic: pesh,
|
||||
useEndingDiacritic: true,
|
||||
ainBlendDiacritic: pesh,
|
||||
},
|
||||
"ey": {
|
||||
ay: {
|
||||
matches: ["ی"],
|
||||
longVowel: true,
|
||||
endingMatches: ["ی"],
|
||||
},
|
||||
"uy": {
|
||||
uy: {
|
||||
matches: ["ۍ"],
|
||||
longVowel: true,
|
||||
endingOnly: true,
|
||||
},
|
||||
"eyy": {
|
||||
ey: {
|
||||
matches: ["ئ"],
|
||||
longVowel: true,
|
||||
endingOnly: true,
|
||||
},
|
||||
// Short Vowels
|
||||
"a": {
|
||||
a: {
|
||||
diacritic: zwar,
|
||||
endingMatches: ["ه"],
|
||||
beginningMatches: ["ا", "ع"],
|
||||
// canComeAfterHeyEnding: true,
|
||||
// canComeAfterHayEnding: true,
|
||||
},
|
||||
"u": {
|
||||
diacritic: zwarakey,
|
||||
u: {
|
||||
diacritic: zwarakay,
|
||||
endingMatches: ["ه"],
|
||||
},
|
||||
"i": {
|
||||
i: {
|
||||
diacritic: zer,
|
||||
endingMatches: ["ه"],
|
||||
beginningMatches: ["ا", "ع"],
|
||||
// takesDiacriticBeforeGurdaHeyEnding: true,
|
||||
// takesDiacriticBeforeGurdaHayEnding: true,
|
||||
// canBeWasla: true,
|
||||
},
|
||||
"U": {
|
||||
U: {
|
||||
diacritic: pesh,
|
||||
endingMatches: ["ه"],
|
||||
// takesDiacriticBeforeGurdaHeyEnding: true,
|
||||
// takesDiacriticBeforeGurdaHayEnding: true,
|
||||
beginningMatches: ["ا", "ع"],
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* splits a phonetics string into an array of Phonemes
|
||||
|
@ -264,11 +294,55 @@ export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
|||
* @returns an array of phonemes
|
||||
*/
|
||||
export function splitFIntoPhonemes(fIn: string): Phoneme[] {
|
||||
const singleLetterPhonemes: Phoneme[] = ["a", "i", "u", "o", "e", "U", "b", "p", "t", "T", "s", "j", "d", "D", "r", "R", "z", "G", "x", "f", "q", "k", "g", "l", "m", "n", "N", "h", "w", "y", "'"];
|
||||
const singleLetterPhonemes: Phoneme[] = [
|
||||
"a",
|
||||
"i",
|
||||
"u",
|
||||
"o",
|
||||
"e",
|
||||
"U",
|
||||
"b",
|
||||
"p",
|
||||
"t",
|
||||
"T",
|
||||
"s",
|
||||
"j",
|
||||
"d",
|
||||
"D",
|
||||
"r",
|
||||
"R",
|
||||
"z",
|
||||
"G",
|
||||
"x",
|
||||
"f",
|
||||
"q",
|
||||
"k",
|
||||
"g",
|
||||
"l",
|
||||
"m",
|
||||
"n",
|
||||
"N",
|
||||
"h",
|
||||
"w",
|
||||
"y",
|
||||
"'",
|
||||
];
|
||||
|
||||
const quadrigraphs: Phoneme[] = ["-Ul-"];
|
||||
const trigraphs: Phoneme[] = ["eyy", "-i-", "-U-"];
|
||||
const digraphs: Phoneme[] = ["aa", "ee", "ey", "oo", "kh", "gh", "ts", "dz", "jz", "ch", "sh"];
|
||||
const trigraphs: Phoneme[] = ["ey", "-i-", "-U-"];
|
||||
const digraphs: Phoneme[] = [
|
||||
"aa",
|
||||
"ee",
|
||||
"ay",
|
||||
"oo",
|
||||
"kh",
|
||||
"gh",
|
||||
"ts",
|
||||
"dz",
|
||||
"jz",
|
||||
"ch",
|
||||
"sh",
|
||||
];
|
||||
const endingDigraphs: Phoneme[] = ["uy"];
|
||||
const willIgnore = ["?", " ", "`", ".", "…", ",", "-"];
|
||||
|
||||
|
@ -276,7 +350,7 @@ export const phonemeTable: Record<Phoneme, PhonemeInfo> = {
|
|||
const f = removeAccents(fIn).replace(/ă/g, "a");
|
||||
let index = 0;
|
||||
while (index < f.length) {
|
||||
const isLastTwoLetters = (index === f.length - 2 || f[index + 2] === " ");
|
||||
const isLastTwoLetters = index === f.length - 2 || f[index + 2] === " ";
|
||||
const threeLetterChunk = f.slice(index, index + 3) as Phoneme;
|
||||
const fourLetterChunk = f.slice(index, index + 4) as Phoneme;
|
||||
if (quadrigraphs.includes(fourLetterChunk)) {
|
||||
|
@ -313,10 +387,10 @@ export enum PhonemeStatus {
|
|||
LeadingLongVowel,
|
||||
LeadingConsonantOrShortVowel,
|
||||
DoubleConsonantTashdeed,
|
||||
EndingWithHeyHim,
|
||||
EndingWithHayHim,
|
||||
DirectMatch,
|
||||
DirectMatchAfterSukun,
|
||||
EndingWithHeyHimFromSukun,
|
||||
EndingWithHayHimFromSukun,
|
||||
ShortVowel,
|
||||
PersianSilentWWithAa,
|
||||
ArabicWasla,
|
||||
|
@ -344,11 +418,16 @@ export enum PhonemeStatus {
|
|||
EndingSmallH,
|
||||
}
|
||||
|
||||
export function stateInfo({ state, i, phonemes, phoneme }: {
|
||||
state: DiacriticsAccumulator,
|
||||
i: number,
|
||||
phonemes: Phoneme[],
|
||||
phoneme: Phoneme,
|
||||
export function stateInfo({
|
||||
state,
|
||||
i,
|
||||
phonemes,
|
||||
phoneme,
|
||||
}: {
|
||||
state: DiacriticsAccumulator;
|
||||
i: number;
|
||||
phonemes: Phoneme[];
|
||||
phoneme: Phoneme;
|
||||
}) {
|
||||
const isOutOfWord = (char: string) => !char || char === " ";
|
||||
const prevPLetter = last(state.pOut);
|
||||
|
@ -356,43 +435,86 @@ export function stateInfo({ state, i, phonemes, phoneme }: {
|
|||
const nextPLetter = state.pIn[1];
|
||||
const nextPhoneme = phonemes[i + 1];
|
||||
const previousPhoneme = i > 0 && phonemes[i - 1];
|
||||
const lastThreePLetters = last(state.pOut, 3) + last(state.pOut, 2) + prevPLetter;
|
||||
const isBeginningOfWord = (state.pOut === "" || prevPLetter === " ") || (previousPhoneme === "-Ul-" && prevPLetter === "ل") || (["دَر", "وَر"].includes(lastThreePLetters) || (last(state.pOut, 2) + prevPLetter) === "را");
|
||||
const lastThreePLetters =
|
||||
last(state.pOut, 3) + last(state.pOut, 2) + prevPLetter;
|
||||
const isBeginningOfWord =
|
||||
state.pOut === "" ||
|
||||
prevPLetter === " " ||
|
||||
(previousPhoneme === "-Ul-" && prevPLetter === "ل") ||
|
||||
["دَر", "وَر"].includes(lastThreePLetters) ||
|
||||
last(state.pOut, 2) + prevPLetter === "را";
|
||||
const isEndOfWord = isOutOfWord(nextPLetter);
|
||||
const phonemeInfo = phonemeTable[phoneme];
|
||||
const previousPhonemeInfo = (!isBeginningOfWord && i > 0) && phonemeTable[phonemes[i-1]];
|
||||
const previousPhonemeInfo =
|
||||
!isBeginningOfWord && i > 0 && phonemeTable[phonemes[i - 1]];
|
||||
// const nextPhoneme = (phonemes.length > (i + 1)) && phonemes[i+1];
|
||||
// const nextPhonemeInfo = nextPhoneme ? phonemeTable[nextPhoneme] : undefined;
|
||||
const doubleConsonant = previousPhonemeInfo && (phonemeInfo.consonant && previousPhonemeInfo.consonant);
|
||||
const needsSukun = (doubleConsonant && ((previousPhoneme !== phoneme) || phonemeInfo.matches?.includes(currentPLetter))) // || (isEndOfWord && phonemeInfo.takesSukunOnEnding);
|
||||
const useAinBlendDiacritics = (!isBeginningOfWord && (phonemeInfo.ainBlendDiacritic && currentPLetter === "ع"));
|
||||
const doubleConsonant =
|
||||
previousPhonemeInfo &&
|
||||
phonemeInfo.consonant &&
|
||||
previousPhonemeInfo.consonant;
|
||||
const needsSukun =
|
||||
doubleConsonant &&
|
||||
(previousPhoneme !== phoneme ||
|
||||
phonemeInfo.matches?.includes(currentPLetter)); // || (isEndOfWord && phonemeInfo.takesSukunOnEnding);
|
||||
const useAinBlendDiacritics =
|
||||
!isBeginningOfWord &&
|
||||
phonemeInfo.ainBlendDiacritic &&
|
||||
currentPLetter === "ع";
|
||||
const diacritic = useAinBlendDiacritics
|
||||
? phonemeInfo.ainBlendDiacritic
|
||||
: isEndOfWord
|
||||
? ((!phonemeInfo.longVowel || phonemeInfo.useEndingDiacritic) ? phonemeInfo.diacritic : undefined) : phonemeInfo.diacritic;
|
||||
? !phonemeInfo.longVowel || phonemeInfo.useEndingDiacritic
|
||||
? phonemeInfo.diacritic
|
||||
: undefined
|
||||
: phonemeInfo.diacritic;
|
||||
|
||||
const lastWordEndedW = (char: string) => ((prevPLetter === char && !currentPLetter) || (prevPLetter === " " && last(state.pOut, 2) === char));
|
||||
const lastWordEndedW = (char: string) =>
|
||||
(prevPLetter === char && !currentPLetter) ||
|
||||
(prevPLetter === " " && last(state.pOut, 2) === char);
|
||||
|
||||
function getPhonemeState(): PhonemeStatus {
|
||||
if (isBeginningOfWord && phoneme === "aa" && phonemeInfo.beginningMatches?.includes(currentPLetter)) {
|
||||
if (
|
||||
isBeginningOfWord &&
|
||||
phoneme === "aa" &&
|
||||
phonemeInfo.beginningMatches?.includes(currentPLetter)
|
||||
) {
|
||||
return PhonemeStatus.DirectMatch;
|
||||
}
|
||||
if (isBeginningOfWord && phoneme === "oo" && currentPLetter === "و") {
|
||||
return PhonemeStatus.OoPrefix;
|
||||
}
|
||||
if (isBeginningOfWord && (phonemeInfo.longVowel && !phonemeInfo.endingOnly)) {
|
||||
if (phoneme !== "aa" && currentPLetter !== "ا" && !phonemeInfo.matches?.includes(nextPLetter)) {
|
||||
if (isBeginningOfWord && phonemeInfo.longVowel && !phonemeInfo.endingOnly) {
|
||||
if (
|
||||
phoneme !== "aa" &&
|
||||
currentPLetter !== "ا" &&
|
||||
!phonemeInfo.matches?.includes(nextPLetter)
|
||||
) {
|
||||
throw Error("phonetics error - needs alef prefix");
|
||||
}
|
||||
return PhonemeStatus.LeadingLongVowel;
|
||||
}
|
||||
if (isBeginningOfWord && (phonemeInfo.beginningMatches?.includes(currentPLetter) || phonemeInfo.matches?.includes(currentPLetter))) {
|
||||
if (
|
||||
isBeginningOfWord &&
|
||||
(phonemeInfo.beginningMatches?.includes(currentPLetter) ||
|
||||
phonemeInfo.matches?.includes(currentPLetter))
|
||||
) {
|
||||
return PhonemeStatus.LeadingConsonantOrShortVowel;
|
||||
}
|
||||
if (isBeginningOfWord && phoneme === "aa" && currentPLetter === "ع" && nextPLetter === "ا") {
|
||||
if (
|
||||
isBeginningOfWord &&
|
||||
phoneme === "aa" &&
|
||||
currentPLetter === "ع" &&
|
||||
nextPLetter === "ا"
|
||||
) {
|
||||
return PhonemeStatus.AinWithLongAAtBeginning;
|
||||
}
|
||||
if (currentPLetter === "ا" && nextPLetter === "ع" && phoneme === "aa" && nextPhoneme !== "'") {
|
||||
if (
|
||||
currentPLetter === "ا" &&
|
||||
nextPLetter === "ع" &&
|
||||
phoneme === "aa" &&
|
||||
nextPhoneme !== "'"
|
||||
) {
|
||||
return PhonemeStatus.SilentAinAfterAlef;
|
||||
}
|
||||
// console.log("------");
|
||||
|
@ -400,13 +522,28 @@ export function stateInfo({ state, i, phonemes, phoneme }: {
|
|||
// console.log("state", state);
|
||||
// console.log("prevPLetter is space", prevPLetter === " ");
|
||||
// console.log("------");
|
||||
if (isBeginningOfWord && phoneme === "u" && prevPLetter === " " && lastNonWhitespace(state.pOut) === "د") {
|
||||
return PhonemeStatus.EndOfDuParticle
|
||||
if (
|
||||
isBeginningOfWord &&
|
||||
phoneme === "u" &&
|
||||
prevPLetter === " " &&
|
||||
lastNonWhitespace(state.pOut) === "د"
|
||||
) {
|
||||
return PhonemeStatus.EndOfDuParticle;
|
||||
}
|
||||
if (isBeginningOfWord && phoneme === "-Ul-" && currentPLetter === "ا" && nextPLetter === "ل") {
|
||||
if (
|
||||
isBeginningOfWord &&
|
||||
phoneme === "-Ul-" &&
|
||||
currentPLetter === "ا" &&
|
||||
nextPLetter === "ل"
|
||||
) {
|
||||
return PhonemeStatus.ArabicDefiniteArticleUl;
|
||||
}
|
||||
if (phoneme === "a" && nextPhoneme === "'" && phonemes[i+2] === "a" && currentPLetter === "أ") {
|
||||
if (
|
||||
phoneme === "a" &&
|
||||
nextPhoneme === "'" &&
|
||||
phonemes[i + 2] === "a" &&
|
||||
currentPLetter === "أ"
|
||||
) {
|
||||
return PhonemeStatus.AlefHamzaBeg;
|
||||
}
|
||||
if (phoneme === "a" && previousPhoneme === "U" && currentPLetter === "و") {
|
||||
|
@ -418,16 +555,35 @@ export function stateInfo({ state, i, phonemes, phoneme }: {
|
|||
if (phoneme === "'" && currentPLetter === "و" && nextPLetter === "و") {
|
||||
return PhonemeStatus.GlottalStopBeforeOo;
|
||||
}
|
||||
if (phoneme === "oo" && previousPhoneme === "'" && currentPLetter === "و" && prevPLetter === hamzaAbove) {
|
||||
if (
|
||||
phoneme === "oo" &&
|
||||
previousPhoneme === "'" &&
|
||||
currentPLetter === "و" &&
|
||||
prevPLetter === hamzaAbove
|
||||
) {
|
||||
return PhonemeStatus.OoAfterGlottalStopOo;
|
||||
}
|
||||
if (phoneme === "'" && last(state.pOut, 2) === "ع" && isOutOfWord(last(state.pOut, 3))) {
|
||||
if (
|
||||
phoneme === "'" &&
|
||||
last(state.pOut, 2) === "ع" &&
|
||||
isOutOfWord(last(state.pOut, 3))
|
||||
) {
|
||||
return PhonemeStatus.AinBeginningAfterShortVowel;
|
||||
}
|
||||
if (!isBeginningOfWord && phoneme === "aa" && currentPLetter === "و" && nextPLetter === "ا") {
|
||||
if (
|
||||
!isBeginningOfWord &&
|
||||
phoneme === "aa" &&
|
||||
currentPLetter === "و" &&
|
||||
nextPLetter === "ا"
|
||||
) {
|
||||
return PhonemeStatus.PersianSilentWWithAa;
|
||||
}
|
||||
if (!isBeginningOfWord && phoneme === "i" && currentPLetter === "ا" && nextPLetter === "ل") {
|
||||
if (
|
||||
!isBeginningOfWord &&
|
||||
phoneme === "i" &&
|
||||
currentPLetter === "ا" &&
|
||||
nextPLetter === "ل"
|
||||
) {
|
||||
return PhonemeStatus.ArabicWasla;
|
||||
}
|
||||
if (phoneme === "-i-" && isBeginningOfWord) {
|
||||
|
@ -443,27 +599,47 @@ export function stateInfo({ state, i, phonemes, phoneme }: {
|
|||
if (phonemeInfo.diacritic && !phonemeInfo.longVowel) {
|
||||
return PhonemeStatus.ShortAinVowelMissingComma;
|
||||
}
|
||||
if ((last(state.pOut, 2) === "ا") && isOutOfWord(last(state.pOut, 3))) {
|
||||
if (last(state.pOut, 2) === "ا" && isOutOfWord(last(state.pOut, 3))) {
|
||||
return PhonemeStatus.ShortAinVowelMissingCommaAfterAlefStart;
|
||||
}
|
||||
}
|
||||
if (useAinBlendDiacritics) {
|
||||
return PhonemeStatus.LongAinVowelMissingComma;
|
||||
}
|
||||
if (((!isBeginningOfWord && doubleConsonant) || prevPLetter === " ") && (previousPhoneme === phoneme) && !phonemeInfo.matches?.includes(currentPLetter)) {
|
||||
if (
|
||||
((!isBeginningOfWord && doubleConsonant) || prevPLetter === " ") &&
|
||||
previousPhoneme === phoneme &&
|
||||
!phonemeInfo.matches?.includes(currentPLetter)
|
||||
) {
|
||||
return PhonemeStatus.DoubleConsonantTashdeed;
|
||||
}
|
||||
if (phoneme === "aa" && currentPLetter === "ی" && nextPLetter === daggerAlif) {
|
||||
if (
|
||||
phoneme === "aa" &&
|
||||
currentPLetter === "ی" &&
|
||||
nextPLetter === daggerAlif
|
||||
) {
|
||||
return PhonemeStatus.AlefDaggarEnding;
|
||||
}
|
||||
if (phoneme === "a" && lastWordEndedW("ح")) {
|
||||
return PhonemeStatus.ShortAEndingAfterHeem;
|
||||
}
|
||||
if (isEndOfWord && ((phoneme === "u" && currentPLetter === "ه") || (phoneme === "h" && ["ه", "ح"].includes(currentPLetter)))) {
|
||||
return needsSukun ? PhonemeStatus.EndingWithHeyHimFromSukun : PhonemeStatus.EndingWithHeyHim;
|
||||
if (
|
||||
isEndOfWord &&
|
||||
((phoneme === "u" && currentPLetter === "ه") ||
|
||||
(phoneme === "h" && ["ه", "ح"].includes(currentPLetter)))
|
||||
) {
|
||||
return needsSukun
|
||||
? PhonemeStatus.EndingWithHayHimFromSukun
|
||||
: PhonemeStatus.EndingWithHayHim;
|
||||
}
|
||||
if ((phonemeInfo.matches?.includes(currentPLetter) || (isEndOfWord && phonemeInfo.endingMatches?.includes(currentPLetter)) || (phoneme === "m" && currentPLetter === "ن" && nextPLetter === "ب"))) {
|
||||
return needsSukun ? PhonemeStatus.DirectMatchAfterSukun : PhonemeStatus.DirectMatch;
|
||||
if (
|
||||
phonemeInfo.matches?.includes(currentPLetter) ||
|
||||
(isEndOfWord && phonemeInfo.endingMatches?.includes(currentPLetter)) ||
|
||||
(phoneme === "m" && currentPLetter === "ن" && nextPLetter === "ب")
|
||||
) {
|
||||
return needsSukun
|
||||
? PhonemeStatus.DirectMatchAfterSukun
|
||||
: PhonemeStatus.DirectMatch;
|
||||
}
|
||||
if (phonemeInfo.diacritic && !phonemeInfo.longVowel) {
|
||||
return PhonemeStatus.ShortVowel;
|
||||
|
@ -471,21 +647,30 @@ export function stateInfo({ state, i, phonemes, phoneme }: {
|
|||
if (phoneme === "o" && previousPhoneme === "w" && lastWordEndedW("و")) {
|
||||
return PhonemeStatus.WoEndingO;
|
||||
}
|
||||
if (isEndOfWord && phoneme === "n" && currentPLetter === fathahan && prevPLetter === "ا") {
|
||||
if (
|
||||
isEndOfWord &&
|
||||
phoneme === "n" &&
|
||||
currentPLetter === fathahan &&
|
||||
prevPLetter === "ا"
|
||||
) {
|
||||
return PhonemeStatus.NOnFathatan;
|
||||
}
|
||||
// console.log("errored", "current", phoneme, "next", nextPhoneme);
|
||||
// console.log("bad phoneme is ", phoneme);
|
||||
throw new Error("phonetics error - no status found for phoneme: " + phoneme);
|
||||
throw new Error(
|
||||
"phonetics error - no status found for phoneme: " + phoneme
|
||||
);
|
||||
}
|
||||
|
||||
const phs = getPhonemeState();
|
||||
|
||||
return {
|
||||
phs, phonemeInfo, diacritic, prevPLetter,
|
||||
phs,
|
||||
phonemeInfo,
|
||||
diacritic,
|
||||
prevPLetter,
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the nth last character of a string
|
||||
|
@ -496,7 +681,10 @@ export function last(s: string, n = 1) {
|
|||
return s[s.length - n];
|
||||
}
|
||||
|
||||
export function advanceP(state: DiacriticsAccumulator, n: number = 1): DiacriticsAccumulator {
|
||||
export function advanceP(
|
||||
state: DiacriticsAccumulator,
|
||||
n: number = 1
|
||||
): DiacriticsAccumulator {
|
||||
return {
|
||||
pIn: state.pIn.slice(n),
|
||||
pOut: state.pOut + state.pIn.slice(0, n),
|
||||
|
@ -518,14 +706,18 @@ export function reverseP(state: DiacriticsAccumulator): DiacriticsAccumulator {
|
|||
};
|
||||
}
|
||||
|
||||
export const addP = (toAdd: string | undefined) => (state: DiacriticsAccumulator): DiacriticsAccumulator => {
|
||||
export const addP =
|
||||
(toAdd: string | undefined) =>
|
||||
(state: DiacriticsAccumulator): DiacriticsAccumulator => {
|
||||
return {
|
||||
...state,
|
||||
pOut: toAdd ? (state.pOut + toAdd) : state.pOut,
|
||||
pOut: toAdd ? state.pOut + toAdd : state.pOut,
|
||||
};
|
||||
};
|
||||
|
||||
export const overwriteP = (toWrite: string) => (state: DiacriticsAccumulator): DiacriticsAccumulator => {
|
||||
export const overwriteP =
|
||||
(toWrite: string) =>
|
||||
(state: DiacriticsAccumulator): DiacriticsAccumulator => {
|
||||
return {
|
||||
pIn: state.pIn.slice(1),
|
||||
pOut: state.pOut + toWrite,
|
||||
|
@ -545,7 +737,10 @@ export function lastNonWhitespace(s: string): string {
|
|||
return penultimateChar;
|
||||
}
|
||||
|
||||
export function getCurrentNext(state: DiacriticsAccumulator): { current: string, next: string} {
|
||||
export function getCurrentNext(state: DiacriticsAccumulator): {
|
||||
current: string;
|
||||
next: string;
|
||||
} {
|
||||
return {
|
||||
current: state.pIn[0],
|
||||
next: state.pIn[1],
|
||||
|
@ -557,7 +752,9 @@ export function getCurrentNext(state: DiacriticsAccumulator): { current: string,
|
|||
// return (current === "ع") ? advanceP(state) : state;
|
||||
// }
|
||||
|
||||
export function advanceForHamzaMid(state: DiacriticsAccumulator): DiacriticsAccumulator {
|
||||
export function advanceForHamzaMid(
|
||||
state: DiacriticsAccumulator
|
||||
): DiacriticsAccumulator {
|
||||
const { current, next } = getCurrentNext(state);
|
||||
if (current === "ئ" && next && next !== "ئ") {
|
||||
return advanceP(state);
|
||||
|
@ -565,7 +762,9 @@ export function advanceForHamzaMid(state: DiacriticsAccumulator): DiacriticsAccu
|
|||
return state;
|
||||
}
|
||||
|
||||
export function advanceForHamza(state: DiacriticsAccumulator): DiacriticsAccumulator {
|
||||
export function advanceForHamza(
|
||||
state: DiacriticsAccumulator
|
||||
): DiacriticsAccumulator {
|
||||
const { current, next } = getCurrentNext(state);
|
||||
if (current === "ه" && (!next || next === " ")) {
|
||||
return advanceP(state);
|
||||
|
@ -575,4 +774,3 @@ export function advanceForHamza(state: DiacriticsAccumulator): DiacriticsAccumul
|
|||
// }
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,23 +6,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import {
|
||||
addDiacritics,
|
||||
} from "./diacritics";
|
||||
import {
|
||||
zwar,
|
||||
zwarakey,
|
||||
sukun,
|
||||
tashdeed,
|
||||
} from "./diacritics-helpers";
|
||||
import { addDiacritics } from "./diacritics";
|
||||
import { zwar, zwarakay, sukun, tashdeed } from "./diacritics-helpers";
|
||||
import * as T from "../../types";
|
||||
|
||||
const diacriticsSections: {
|
||||
describe: string,
|
||||
describe: string;
|
||||
tests: {
|
||||
in: T.PsString,
|
||||
out: string | null,
|
||||
}[],
|
||||
in: T.PsString;
|
||||
out: string | null;
|
||||
}[];
|
||||
}[] = [
|
||||
{
|
||||
describe: "regular, native Pashto script/sounds",
|
||||
|
@ -108,14 +101,14 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "شئ",
|
||||
f: "sheyy",
|
||||
f: "shey",
|
||||
},
|
||||
out: "شئ",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کار کوئ چې لاړ شئ",
|
||||
f: "kaar kawéyy che laaR sheyy",
|
||||
f: "kaar kawéy che laaR shey",
|
||||
},
|
||||
out: "کار کَوئ چې لاړ شئ",
|
||||
},
|
||||
|
@ -146,28 +139,28 @@ const diacriticsSections: {
|
|||
p: "کول",
|
||||
f: "kawul",
|
||||
},
|
||||
out: "کَو" + zwarakey + "ل",
|
||||
out: "کَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kiwul",
|
||||
},
|
||||
out: "کِو" + zwarakey + "ل",
|
||||
out: "کِو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kUwul",
|
||||
},
|
||||
out: "کُو" + zwarakey + "ل",
|
||||
out: "کُو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kuwul",
|
||||
},
|
||||
out: "ک" + zwarakey + "و" + zwarakey + "ل",
|
||||
out: "ک" + zwarakay + "و" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -200,7 +193,7 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "سپین",
|
||||
f: "speyn",
|
||||
f: "spayn",
|
||||
},
|
||||
out: "سْپین",
|
||||
},
|
||||
|
@ -272,21 +265,21 @@ const diacriticsSections: {
|
|||
p: "رغېدل",
|
||||
f: "raghedul",
|
||||
},
|
||||
out: "رَغېد" + zwarakey + "ل",
|
||||
out: "رَغېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کارول",
|
||||
f: "kaarawul",
|
||||
},
|
||||
out: "کارَو" + zwarakey + "ل",
|
||||
out: "کارَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "پېښېدل",
|
||||
f: "pexedul",
|
||||
},
|
||||
out: "پېښېد" + zwarakey + "ل",
|
||||
out: "پېښېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -298,7 +291,7 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "سړی",
|
||||
f: "saRey",
|
||||
f: "saRay",
|
||||
},
|
||||
out: "سَړی",
|
||||
},
|
||||
|
@ -335,28 +328,28 @@ const diacriticsSections: {
|
|||
p: "ایستل",
|
||||
f: "eestul",
|
||||
},
|
||||
out: "اِیسْت" + zwarakey + "ل",
|
||||
out: "اِیسْت" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "ایستل",
|
||||
f: "eystul",
|
||||
f: "aystul",
|
||||
},
|
||||
out: "ایسْت" + zwarakey + "ل",
|
||||
out: "ایسْت" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اېسېدل",
|
||||
f: "esedul",
|
||||
},
|
||||
out: "اېسېد" + zwarakey + "ل",
|
||||
out: "اېسېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اوسېدل",
|
||||
f: "osedul",
|
||||
},
|
||||
out: "اوسېد" + zwarakey + "ل",
|
||||
out: "اوسېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -377,7 +370,7 @@ const diacriticsSections: {
|
|||
p: "واردول",
|
||||
f: "waaridawul",
|
||||
},
|
||||
out: "وارِدَو" + zwarakey + "ل",
|
||||
out: "وارِدَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -557,7 +550,7 @@ const diacriticsSections: {
|
|||
p: "توجه کول",
|
||||
f: "tawajU kawul",
|
||||
},
|
||||
out: "تَوَجُه کَو" + zwarakey + "ل",
|
||||
out: "تَوَجُه کَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -597,7 +590,7 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "سختسری",
|
||||
f: "sakht sărey",
|
||||
f: "sakht săray",
|
||||
},
|
||||
out: "سَخْتْسَری",
|
||||
},
|
||||
|
@ -646,7 +639,7 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "وری",
|
||||
f: "waréy",
|
||||
f: "waráy",
|
||||
},
|
||||
out: "وَری",
|
||||
},
|
||||
|
@ -660,19 +653,20 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "امزری",
|
||||
f: "umzaréy",
|
||||
f: "umzaráy",
|
||||
},
|
||||
out: zwarakey + "مْزَری",
|
||||
out: zwarakay + "مْزَری",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
describe: "ې followed by ی - y needs to be written as e`y to be distinguished from ey - ی",
|
||||
describe:
|
||||
"ې followed by ی - y needs to be written as e`y to be distinguished from ay - ی",
|
||||
tests: [
|
||||
{
|
||||
in: {
|
||||
p: "پتېیل",
|
||||
f: "pateyúl",
|
||||
f: "patayúl",
|
||||
},
|
||||
out: null,
|
||||
},
|
||||
|
@ -681,14 +675,14 @@ const diacriticsSections: {
|
|||
p: "پتېیل",
|
||||
f: "pate`yúl",
|
||||
},
|
||||
out: "پَتېی" + zwarakey + "ل",
|
||||
out: "پَتېی" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "درېیم",
|
||||
f: "dre`yum",
|
||||
},
|
||||
out: "دْرېی" + zwarakey + "م",
|
||||
out: "دْرېی" + zwarakay + "م",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -700,7 +694,7 @@ const diacriticsSections: {
|
|||
p: "تر ... پورې",
|
||||
f: "tur ... pore",
|
||||
},
|
||||
out: "ت" + zwarakey + "ر ... پورې",
|
||||
out: "ت" + zwarakay + "ر ... پورې",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -729,7 +723,7 @@ const diacriticsSections: {
|
|||
{
|
||||
in: {
|
||||
p: "سړی و",
|
||||
f: "saRey wo",
|
||||
f: "saRay wo",
|
||||
},
|
||||
out: "سَړی و",
|
||||
},
|
||||
|
@ -811,7 +805,7 @@ const diacriticsSections: {
|
|||
p: "منبع",
|
||||
f: "manb'i",
|
||||
},
|
||||
out: "مَنْبْعِ"
|
||||
out: "مَنْبْعِ",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -825,7 +819,7 @@ const diacriticsSections: {
|
|||
p: "منبع",
|
||||
f: "manbi",
|
||||
},
|
||||
out: "مَنْبِع"
|
||||
out: "مَنْبِع",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -860,7 +854,7 @@ const diacriticsSections: {
|
|||
p: "مربع جذر",
|
||||
f: "mUraba' jazúr",
|
||||
},
|
||||
out: "مُرَبَع جَذ" + zwarakey + "ر",
|
||||
out: "مُرَبَع جَذ" + zwarakay + "ر",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -888,7 +882,7 @@ const diacriticsSections: {
|
|||
p: "راجع کېدل",
|
||||
f: "raaji kedul",
|
||||
},
|
||||
out: "راجِع کېد" + zwarakey + "ل",
|
||||
out: "راجِع کېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -979,7 +973,7 @@ const diacriticsSections: {
|
|||
f: "ijmaa'",
|
||||
},
|
||||
out: "اِجْماع",
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -1064,21 +1058,21 @@ const diacriticsSections: {
|
|||
p: "د",
|
||||
f: "du",
|
||||
},
|
||||
out: "د" + zwarakey,
|
||||
out: "د" + zwarakay,
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "د لاس",
|
||||
f: "du laas",
|
||||
},
|
||||
out: "د" + zwarakey + " لاس",
|
||||
out: "د" + zwarakay + " لاس",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "د ... په شان",
|
||||
f: "du ... pu shaan",
|
||||
},
|
||||
out: "د" + zwarakey + " ... پهٔ شان",
|
||||
out: "د" + zwarakay + " ... پهٔ شان",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -1097,7 +1091,7 @@ const diacriticsSections: {
|
|||
p: "ذبح کول",
|
||||
f: "zabha kawul",
|
||||
},
|
||||
out: "ذَبْحَ کَو" + zwarakey + "ل",
|
||||
out: "ذَبْحَ کَو" + zwarakay + "ل",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -1275,14 +1269,14 @@ const diacriticsSections: {
|
|||
p: "وځم",
|
||||
f: "oodzum",
|
||||
},
|
||||
out: "وُځ" + zwarakey + "م",
|
||||
out: "وُځ" + zwarakay + "م",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "وځم",
|
||||
f: "wUdzum",
|
||||
},
|
||||
out: "وُځ" + zwarakey + "م",
|
||||
out: "وُځ" + zwarakay + "م",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -1316,5 +1310,3 @@ test("ending with left over phonetics will throw an error", () => {
|
|||
addDiacritics({ p: "کار", f: "kaar kawul" });
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
splitFIntoPhonemes,
|
||||
Phoneme,
|
||||
zwar,
|
||||
zwarakey,
|
||||
zwarakay,
|
||||
zer,
|
||||
pesh,
|
||||
sukun,
|
||||
|
@ -35,10 +35,20 @@ import { pipe } from "rambda";
|
|||
/**
|
||||
* Adds diacritics to a given PsString.
|
||||
* Errors if the phonetics and script don't line up.
|
||||
*
|
||||
* IN PROGRESS - This will hopefully get done and replace the messy, unmaintainable phonetics-to-diacritics.ts currently in use
|
||||
*/
|
||||
export function addDiacritics({ p, f }: T.PsString, ignoreCommas?: true): T.PsString {
|
||||
const phonemes: Phoneme[] = splitFIntoPhonemes(!ignoreCommas ? removeFVarients(f) : f);
|
||||
const { pIn, pOut } = phonemes.reduce(processPhoneme, { pOut: "", pIn: p.trim() });
|
||||
export function addDiacritics(
|
||||
{ p, f }: T.PsString,
|
||||
ignoreCommas?: true
|
||||
): T.PsString {
|
||||
const phonemes: Phoneme[] = splitFIntoPhonemes(
|
||||
!ignoreCommas ? removeFVarients(f) : f
|
||||
);
|
||||
const { pIn, pOut } = phonemes.reduce(processPhoneme, {
|
||||
pOut: "",
|
||||
pIn: p.trim(),
|
||||
});
|
||||
if (pIn !== "") {
|
||||
throw new Error("phonetics error - phonetics shorter than pashto script");
|
||||
}
|
||||
|
@ -52,159 +62,80 @@ function processPhoneme(
|
|||
acc: DiacriticsAccumulator,
|
||||
phoneme: Phoneme,
|
||||
i: number,
|
||||
phonemes: Phoneme[],
|
||||
phonemes: Phoneme[]
|
||||
): DiacriticsAccumulator {
|
||||
const state = acc.pIn.slice(0, 5) === " ... "
|
||||
const state =
|
||||
acc.pIn.slice(0, 5) === " ... "
|
||||
? advanceP(acc, 5)
|
||||
: acc.pIn[0] === " "
|
||||
? advanceP(acc)
|
||||
: acc;
|
||||
|
||||
const {
|
||||
phonemeInfo,
|
||||
diacritic,
|
||||
phs,
|
||||
prevPLetter,
|
||||
} = stateInfo({ state, i, phoneme, phonemes });
|
||||
const { phonemeInfo, diacritic, phs, prevPLetter } = stateInfo({
|
||||
state,
|
||||
i,
|
||||
phoneme,
|
||||
phonemes,
|
||||
});
|
||||
|
||||
return (phs === PhonemeStatus.LeadingLongVowel) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(phonemeInfo.diacritic),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.LeadingConsonantOrShortVowel) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(diacritic),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.DoubleConsonantTashdeed) ?
|
||||
pipe(
|
||||
prevPLetter === " " ? reverseP : addP(""),
|
||||
addP(tashdeed)
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.EndingWithHeyHim) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(phoneme === "u" ? hamzaAbove : sukun),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.DirectMatch) ?
|
||||
pipe(
|
||||
addP(diacritic),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.DirectMatchAfterSukun) ?
|
||||
pipe(
|
||||
addP(sukun),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.PersianSilentWWithAa) ?
|
||||
pipe(
|
||||
addP("("),
|
||||
advanceP,
|
||||
addP(")"),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ArabicWasla) ?
|
||||
pipe(
|
||||
addP(zer),
|
||||
overwriteP(wasla),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.Izafe) ?
|
||||
pipe(
|
||||
reverseP,
|
||||
addP(zer),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.EndOfDuParticle) ?
|
||||
pipe(
|
||||
reverseP,
|
||||
addP(zwarakey),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ShortAEndingAfterHeem) ?
|
||||
pipe(
|
||||
prevPLetter === " " ? reverseP : addP(""),
|
||||
addP(zwar),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.EndingWithHeyHimFromSukun) ?
|
||||
pipe(
|
||||
addP(sukun),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.AlefDaggarEnding) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.LongAinVowelMissingComma) ?
|
||||
pipe(
|
||||
addP(diacritic),
|
||||
advanceP,
|
||||
addP(diacritic)
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ShortAinVowelMissingComma) ?
|
||||
pipe(
|
||||
addP(diacritic),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ShortAinVowelMissingCommaAfterAlefStart) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.AinWithLongAAtBeginning) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.AlefWithHamza) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ShortVowel) ?
|
||||
pipe(
|
||||
return phs === PhonemeStatus.LeadingLongVowel
|
||||
? pipe(advanceP, addP(phonemeInfo.diacritic), advanceP)(state)
|
||||
: phs === PhonemeStatus.LeadingConsonantOrShortVowel
|
||||
? pipe(advanceP, addP(diacritic))(state)
|
||||
: phs === PhonemeStatus.DoubleConsonantTashdeed
|
||||
? pipe(prevPLetter === " " ? reverseP : addP(""), addP(tashdeed))(state)
|
||||
: phs === PhonemeStatus.EndingWithHayHim
|
||||
? pipe(advanceP, addP(phoneme === "u" ? hamzaAbove : sukun))(state)
|
||||
: phs === PhonemeStatus.DirectMatch
|
||||
? pipe(addP(diacritic), advanceP)(state)
|
||||
: phs === PhonemeStatus.DirectMatchAfterSukun
|
||||
? pipe(addP(sukun), advanceP)(state)
|
||||
: phs === PhonemeStatus.PersianSilentWWithAa
|
||||
? pipe(addP("("), advanceP, addP(")"), advanceP)(state)
|
||||
: phs === PhonemeStatus.ArabicWasla
|
||||
? pipe(addP(zer), overwriteP(wasla))(state)
|
||||
: phs === PhonemeStatus.Izafe
|
||||
? pipe(reverseP, addP(zer))(state)
|
||||
: phs === PhonemeStatus.EndOfDuParticle
|
||||
? pipe(reverseP, addP(zwarakay))(state)
|
||||
: phs === PhonemeStatus.ShortAEndingAfterHeem
|
||||
? pipe(prevPLetter === " " ? reverseP : addP(""), addP(zwar))(state)
|
||||
: phs === PhonemeStatus.EndingWithHayHimFromSukun
|
||||
? pipe(addP(sukun), advanceP)(state)
|
||||
: phs === PhonemeStatus.AlefDaggarEnding
|
||||
? pipe(advanceP, advanceP)(state)
|
||||
: phs === PhonemeStatus.LongAinVowelMissingComma
|
||||
? pipe(addP(diacritic), advanceP, addP(diacritic))(state)
|
||||
: phs === PhonemeStatus.ShortAinVowelMissingComma
|
||||
? pipe(addP(diacritic), advanceP)(state)
|
||||
: phs === PhonemeStatus.ShortAinVowelMissingCommaAfterAlefStart
|
||||
? pipe(advanceP, advanceP)(state)
|
||||
: phs === PhonemeStatus.AinWithLongAAtBeginning
|
||||
? pipe(advanceP, advanceP)(state)
|
||||
: phs === PhonemeStatus.AlefWithHamza
|
||||
? pipe(advanceP)(state)
|
||||
: phs === PhonemeStatus.ShortVowel
|
||||
? pipe(
|
||||
advanceForHamzaMid,
|
||||
addP(phonemeInfo.diacritic),
|
||||
// TODO THIS?
|
||||
advanceForHamza,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ShortAForAlefBeforeFathatan) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.NOnFathatan) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.HamzaOnWow) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(hamzaAbove),
|
||||
addP(diacritic),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.ArabicDefiniteArticleUl) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(pesh),
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.OoPrefix) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(pesh),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.GlottalStopBeforeOo) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
addP(hamzaAbove),
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.OoAfterGlottalStopOo) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
)(state)
|
||||
: (phs === PhonemeStatus.SilentAinAfterAlef) ?
|
||||
pipe(
|
||||
advanceP,
|
||||
advanceP,
|
||||
advanceForHamza
|
||||
)(state)
|
||||
: phs === PhonemeStatus.ShortAForAlefBeforeFathatan
|
||||
? pipe(advanceP)(state)
|
||||
: phs === PhonemeStatus.NOnFathatan
|
||||
? pipe(advanceP)(state)
|
||||
: phs === PhonemeStatus.HamzaOnWow
|
||||
? pipe(advanceP, addP(hamzaAbove), addP(diacritic))(state)
|
||||
: phs === PhonemeStatus.ArabicDefiniteArticleUl
|
||||
? pipe(advanceP, addP(pesh), advanceP)(state)
|
||||
: phs === PhonemeStatus.OoPrefix
|
||||
? pipe(advanceP, addP(pesh))(state)
|
||||
: phs === PhonemeStatus.GlottalStopBeforeOo
|
||||
? pipe(advanceP, addP(hamzaAbove))(state)
|
||||
: phs === PhonemeStatus.OoAfterGlottalStopOo
|
||||
? pipe(advanceP)(state)
|
||||
: phs === PhonemeStatus.SilentAinAfterAlef
|
||||
? pipe(advanceP, advanceP)(state)
|
||||
: state;
|
||||
}
|
||||
|
|
|
@ -11,19 +11,19 @@ import {
|
|||
splitFIntoPhonemes,
|
||||
} from "./phonetics-to-diacritics";
|
||||
|
||||
const zwarakey = "ٙ";
|
||||
const zwarakay = "ٙ";
|
||||
|
||||
const phonemeSplits: Array<{
|
||||
in: string,
|
||||
out: string[],
|
||||
in: string;
|
||||
out: string[];
|
||||
}> = [
|
||||
{
|
||||
in: "kor",
|
||||
out: ["k", "o", "r"],
|
||||
},
|
||||
{
|
||||
in: "raaghey",
|
||||
out: ["r", "aa", "gh", "ey"],
|
||||
in: "raaghay",
|
||||
out: ["r", "aa", "gh", "ay"],
|
||||
},
|
||||
{
|
||||
in: "hatsa",
|
||||
|
@ -34,16 +34,16 @@ const phonemeSplits: Array<{
|
|||
out: ["b", "a"],
|
||||
},
|
||||
{
|
||||
in: "peydáa",
|
||||
out: ["p", "ey", "d", "áa"],
|
||||
in: "paydáa",
|
||||
out: ["p", "ay", "d", "áa"],
|
||||
},
|
||||
{
|
||||
in: "be kaar",
|
||||
out: ["b", "e", "k", "aa", "r"],
|
||||
},
|
||||
{
|
||||
in: "raadzeyy",
|
||||
out: ["r", "aa", "dz", "eyy"],
|
||||
in: "raadzey",
|
||||
out: ["r", "aa", "dz", "ey"],
|
||||
},
|
||||
{
|
||||
in: "badanuy ??",
|
||||
|
@ -67,8 +67,8 @@ phonemeSplits.forEach((s) => {
|
|||
});
|
||||
|
||||
const toTest: Array<{
|
||||
in: { p: string, f: string },
|
||||
out: string | undefined,
|
||||
in: { p: string; f: string };
|
||||
out: string | undefined;
|
||||
}> = [
|
||||
{
|
||||
in: {
|
||||
|
@ -168,28 +168,28 @@ const toTest: Array<{
|
|||
p: "کول",
|
||||
f: "kawul",
|
||||
},
|
||||
out: "کَو" + zwarakey + "ل",
|
||||
out: "کَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kiwul",
|
||||
},
|
||||
out: "کِو" + zwarakey + "ل",
|
||||
out: "کِو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kUwul",
|
||||
},
|
||||
out: "کُو" + zwarakey + "ل",
|
||||
out: "کُو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کول",
|
||||
f: "kuwul",
|
||||
},
|
||||
out: "ک" + zwarakey + "و" + zwarakey + "ل",
|
||||
out: "ک" + zwarakay + "و" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -222,7 +222,7 @@ const toTest: Array<{
|
|||
{
|
||||
in: {
|
||||
p: "سپین",
|
||||
f: "speyn",
|
||||
f: "spayn",
|
||||
},
|
||||
out: "سْپین",
|
||||
},
|
||||
|
@ -236,7 +236,7 @@ const toTest: Array<{
|
|||
{
|
||||
in: {
|
||||
p: "پېش",
|
||||
f: "peysh",
|
||||
f: "paysh",
|
||||
},
|
||||
out: undefined,
|
||||
},
|
||||
|
@ -245,33 +245,33 @@ const toTest: Array<{
|
|||
p: "رغېدل",
|
||||
f: "raghedul",
|
||||
},
|
||||
out: "رَغېد" + zwarakey + "ل",
|
||||
out: "رَغېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "کارول",
|
||||
f: "kaarawul",
|
||||
},
|
||||
out: "کارَو" + zwarakey + "ل",
|
||||
out: "کارَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "پېښېدل",
|
||||
f: "pexedul",
|
||||
},
|
||||
out: "پېښېد" + zwarakey + "ل",
|
||||
out: "پېښېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "مین",
|
||||
f: "mayín",
|
||||
f: "ma`yín",
|
||||
},
|
||||
out: "مَیِن",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "سړی",
|
||||
f: "saRey",
|
||||
f: "saRay",
|
||||
},
|
||||
out: "سَړی",
|
||||
},
|
||||
|
@ -308,28 +308,28 @@ const toTest: Array<{
|
|||
p: "ایستل",
|
||||
f: "eestul",
|
||||
},
|
||||
out: "اِیسْت" + zwarakey + "ل",
|
||||
out: "اِیسْت" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "ایستل",
|
||||
f: "eystul",
|
||||
f: "aystul",
|
||||
},
|
||||
out: "ایسْت" + zwarakey + "ل",
|
||||
out: "ایسْت" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اېسېدل",
|
||||
f: "esedul",
|
||||
},
|
||||
out: "اېسېد" + zwarakey + "ل",
|
||||
out: "اېسېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اوسېدل",
|
||||
f: "osedul",
|
||||
},
|
||||
out: "اوسېد" + zwarakey + "ل",
|
||||
out: "اوسېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -350,7 +350,7 @@ const toTest: Array<{
|
|||
p: "واردول",
|
||||
f: "waaridawul",
|
||||
},
|
||||
out: "وارِدَو" + zwarakey + "ل",
|
||||
out: "وارِدَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -490,21 +490,21 @@ const toTest: Array<{
|
|||
p: "ازغن تار",
|
||||
f: "azghun taar",
|
||||
},
|
||||
out: "اَزْغ" + zwarakey + "ن" + " تار",
|
||||
out: "اَزْغ" + zwarakay + "ن" + " تار",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اره څکول",
|
||||
f: "ara tskawul",
|
||||
},
|
||||
out: "اَره څْکَو" + zwarakey + "ل",
|
||||
out: "اَره څْکَو" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "اږیل",
|
||||
f: "aGuyúl",
|
||||
},
|
||||
out: "اَږ" + zwarakey + "ی" + zwarakey + "ل",
|
||||
out: "اَږ" + zwarakay + "ی" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -669,7 +669,8 @@ const toTest: Array<{
|
|||
f: "aadam",
|
||||
},
|
||||
out: undefined,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "منع",
|
||||
f: "mán'a",
|
||||
|
@ -698,11 +699,11 @@ const toTest: Array<{
|
|||
},
|
||||
out: "اسان",
|
||||
},
|
||||
// ې followed by ی - y needs to be written as e`y to be distinguished from ey - ی
|
||||
// ې followed by ی - y needs to be written as e`y to be distinguished from ay - ی
|
||||
{
|
||||
in: {
|
||||
p: "پتېیل",
|
||||
f: "pateyúl",
|
||||
f: "patayúl",
|
||||
},
|
||||
out: undefined,
|
||||
},
|
||||
|
@ -711,14 +712,14 @@ const toTest: Array<{
|
|||
p: "پتېیل",
|
||||
f: "pate`yúl",
|
||||
},
|
||||
out: "پَتېی" + zwarakey + "ل",
|
||||
out: "پَتېی" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "درېیم",
|
||||
f: "dre`yum",
|
||||
},
|
||||
out: "دْرېی" + zwarakey + "م",
|
||||
out: "دْرېی" + zwarakay + "م",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -733,7 +734,7 @@ const toTest: Array<{
|
|||
p: "تر ... پورې",
|
||||
f: "tur ... pore",
|
||||
},
|
||||
out: "ت" + zwarakey + "ر ... پورې",
|
||||
out: "ت" + zwarakay + "ر ... پورې",
|
||||
},
|
||||
// joiner و
|
||||
{
|
||||
|
@ -763,21 +764,21 @@ const toTest: Array<{
|
|||
p: "د",
|
||||
f: "du",
|
||||
},
|
||||
out: "د" + zwarakey,
|
||||
out: "د" + zwarakay,
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "د لاس",
|
||||
f: "du laas",
|
||||
},
|
||||
out: "د" + zwarakey + " لاس",
|
||||
out: "د" + zwarakay + " لاس",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "د ... په شان",
|
||||
f: "du ... pu shaan",
|
||||
},
|
||||
out: "د" + zwarakey + " ... پهٔ شان",
|
||||
out: "د" + zwarakay + " ... پهٔ شان",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -798,7 +799,7 @@ const toTest: Array<{
|
|||
p: "ذبح کول",
|
||||
f: "zabha kawul",
|
||||
},
|
||||
out: "ذَبْحَ کَو" + zwarakey + "ل",
|
||||
out: "ذَبْحَ کَو" + zwarakay + "ل",
|
||||
},
|
||||
// require dagger alif on words ending with یٰ
|
||||
{
|
||||
|
@ -864,7 +865,7 @@ const toTest: Array<{
|
|||
p: "طمع لرل",
|
||||
f: "tama larul",
|
||||
},
|
||||
out: "طَمعَ لَر" + zwarakey + "ل",
|
||||
out: "طَمعَ لَر" + zwarakay + "ل",
|
||||
},
|
||||
// Ua ؤ
|
||||
{
|
||||
|
@ -885,7 +886,7 @@ const toTest: Array<{
|
|||
{
|
||||
in: {
|
||||
p: "شئ",
|
||||
f: "sheyy",
|
||||
f: "shey",
|
||||
},
|
||||
out: "شئ",
|
||||
},
|
||||
|
@ -900,7 +901,7 @@ const toTest: Array<{
|
|||
{
|
||||
in: {
|
||||
p: "سړی و",
|
||||
f: "saRey wo",
|
||||
f: "saRay wo",
|
||||
},
|
||||
out: "سَړی و",
|
||||
},
|
||||
|
@ -938,7 +939,7 @@ const toTest: Array<{
|
|||
p: "توجه کول",
|
||||
f: "tawajU kawul",
|
||||
},
|
||||
out: "تَوَجُه کَو" + zwarakey + "ل",
|
||||
out: "تَوَجُه کَو" + zwarakay + "ل",
|
||||
},
|
||||
// With Arabic definate article -Ul- ال
|
||||
{
|
||||
|
@ -975,7 +976,7 @@ const toTest: Array<{
|
|||
p: "راجع کېدل",
|
||||
f: "raaji kedul",
|
||||
},
|
||||
out: "راجعِ کېد" + zwarakey + "ل",
|
||||
out: "راجعِ کېد" + zwarakay + "ل",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -987,7 +988,7 @@ const toTest: Array<{
|
|||
{
|
||||
in: {
|
||||
p: "سختسری",
|
||||
f: "sakht sărey",
|
||||
f: "sakht săray",
|
||||
},
|
||||
out: "سَخْتْسَری",
|
||||
},
|
||||
|
@ -1042,7 +1043,7 @@ const toTest: Array<{
|
|||
p: "مربع جذر",
|
||||
f: "mUraba' jazúr",
|
||||
},
|
||||
out: "مُرَبَع جَذ" + zwarakey + "ر",
|
||||
out: "مُرَبَع جَذ" + zwarakay + "ر",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
|
@ -1101,14 +1102,14 @@ const toTest: Array<{
|
|||
p: "وځم",
|
||||
f: "oodzum",
|
||||
},
|
||||
out: "وځ" + zwarakey + "م",
|
||||
out: "وځ" + zwarakay + "م",
|
||||
},
|
||||
{
|
||||
in: {
|
||||
p: "وځم",
|
||||
f: "wUdzum",
|
||||
},
|
||||
out: "وُځ" + zwarakey + "م",
|
||||
out: "وُځ" + zwarakay + "م",
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
const zwar = "َ";
|
||||
const zwarakey = "ٙ";
|
||||
const zwarakay = "ٙ";
|
||||
const zer = "ِ";
|
||||
const pesh = "ُ";
|
||||
const sukun = "ْ";
|
||||
|
@ -19,8 +19,25 @@ const fathahan = "ً";
|
|||
|
||||
// TODO: THESE OTHER TRIGRAPHS??
|
||||
const quadrigraphs = ["-Ul-"];
|
||||
const trigraphs = ["eyy", "éyy", "-i-", "-U-"]; // , "aay", "áay", "ooy", "óoy"];
|
||||
const digraphs = ["ắ", "aa", "áa", "ee", "ée", "ey", "éy", "oo", "óo", "kh", "gh", "ts", "dz", "jz", "ch", "sh"];
|
||||
const trigraphs = ["ey", "éy", "-i-", "-U-"]; // , "aay", "áay", "ooy", "óoy"];
|
||||
const digraphs = [
|
||||
"ắ",
|
||||
"aa",
|
||||
"áa",
|
||||
"ee",
|
||||
"ée",
|
||||
"ay",
|
||||
"áy",
|
||||
"oo",
|
||||
"óo",
|
||||
"kh",
|
||||
"gh",
|
||||
"ts",
|
||||
"dz",
|
||||
"jz",
|
||||
"ch",
|
||||
"sh",
|
||||
];
|
||||
const endingDigraphs = ["uy", "úy"];
|
||||
const willIgnore = ["?", " ", "`", ".", "…"];
|
||||
|
||||
|
@ -28,7 +45,7 @@ export function splitFIntoPhonemes(f: string): string[] {
|
|||
const result: string[] = [];
|
||||
let index = 0;
|
||||
while (index < f.length) {
|
||||
const isLastTwoLetters = (index === f.length - 2 || f[index + 2] === " ");
|
||||
const isLastTwoLetters = index === f.length - 2 || f[index + 2] === " ";
|
||||
const threeLetterChunk = f.slice(index, index + 3);
|
||||
const fourLetterChunk = f.slice(index, index + 4);
|
||||
if (quadrigraphs.includes(fourLetterChunk)) {
|
||||
|
@ -89,7 +106,12 @@ const phonemeTable = [
|
|||
{ phoneme: "m", possibilities: ["م"], consonant: true },
|
||||
{ phoneme: "n", possibilities: ["ن"], consonant: true },
|
||||
{ phoneme: "N", possibilities: ["ڼ"], consonant: true },
|
||||
{ phoneme: "h", possibilities: ["ه", "ح"], consonant: true, takesSukunOnEnding: true },
|
||||
{
|
||||
phoneme: "h",
|
||||
possibilities: ["ه", "ح"],
|
||||
consonant: true,
|
||||
takesSukunOnEnding: true,
|
||||
},
|
||||
{ phoneme: "w", possibilities: ["و"], consonant: true },
|
||||
{ phoneme: "y", possibilities: ["ی"], consonant: true },
|
||||
|
||||
|
@ -99,33 +121,130 @@ const phonemeTable = [
|
|||
{ phoneme: "-Ul-", possibilities: ["ال"] },
|
||||
|
||||
// vowels
|
||||
{ phoneme: "aa", possibilities: ["ا"], beginning: ["آ", "ا"], endingPossibilities: ["ا", "یٰ"], isLongA: true, canStartWithAynBefore: true },
|
||||
{ phoneme: "áa", possibilities: ["ا"], beginning: ["آ", "ا"], endingPossibilities: ["ا", "یٰ"], isLongA: true, canStartWithAynBefore: true },
|
||||
{ phoneme: "ee", possibilities: ["ی"], addAlefOnBeginning: true, endingPossibilities: ["ي"], diacritic: zer, canStartWithAynBefore: true },
|
||||
{ phoneme: "ée", possibilities: ["ی"], addAlefOnBeginning: true, endingPossibilities: ["ي"], diacritic: zer, canStartWithAynBefore: true },
|
||||
{
|
||||
phoneme: "aa",
|
||||
possibilities: ["ا"],
|
||||
beginning: ["آ", "ا"],
|
||||
endingPossibilities: ["ا", "یٰ"],
|
||||
isLongA: true,
|
||||
canStartWithAynBefore: true,
|
||||
},
|
||||
{
|
||||
phoneme: "áa",
|
||||
possibilities: ["ا"],
|
||||
beginning: ["آ", "ا"],
|
||||
endingPossibilities: ["ا", "یٰ"],
|
||||
isLongA: true,
|
||||
canStartWithAynBefore: true,
|
||||
},
|
||||
{
|
||||
phoneme: "ee",
|
||||
possibilities: ["ی"],
|
||||
addAlefOnBeginning: true,
|
||||
endingPossibilities: ["ي"],
|
||||
diacritic: zer,
|
||||
canStartWithAynBefore: true,
|
||||
},
|
||||
{
|
||||
phoneme: "ée",
|
||||
possibilities: ["ی"],
|
||||
addAlefOnBeginning: true,
|
||||
endingPossibilities: ["ي"],
|
||||
diacritic: zer,
|
||||
canStartWithAynBefore: true,
|
||||
},
|
||||
{ phoneme: "e", possibilities: ["ې"], addAlefOnBeginning: true },
|
||||
{ phoneme: "é", possibilities: ["ې"], addAlefOnBeginning: true },
|
||||
{ phoneme: "o", possibilities: ["و"], addAlefOnBeginning: true },
|
||||
{ phoneme: "ó", possibilities: ["و"], addAlefOnBeginning: true },
|
||||
{ phoneme: "oo", possibilities: ["و"], addAlefOnBeginning: true, alsoCanBePrefix: true, diacritic: pesh },
|
||||
{ phoneme: "óo", possibilities: ["و"], addAlefOnBeginning: true, diacritic: pesh },
|
||||
{ phoneme: "ey", possibilities: ["ی"], addAlefOnBeginning: true, endingPossibilities: ["ی"]},
|
||||
{ phoneme: "éy", possibilities: ["ی"], addAlefOnBeginning: true, endingPossibilities: ["ی"]},
|
||||
{
|
||||
phoneme: "oo",
|
||||
possibilities: ["و"],
|
||||
addAlefOnBeginning: true,
|
||||
alsoCanBePrefix: true,
|
||||
diacritic: pesh,
|
||||
},
|
||||
{
|
||||
phoneme: "óo",
|
||||
possibilities: ["و"],
|
||||
addAlefOnBeginning: true,
|
||||
diacritic: pesh,
|
||||
},
|
||||
{
|
||||
phoneme: "ay",
|
||||
possibilities: ["ی"],
|
||||
addAlefOnBeginning: true,
|
||||
endingPossibilities: ["ی"],
|
||||
},
|
||||
{
|
||||
phoneme: "áy",
|
||||
possibilities: ["ی"],
|
||||
addAlefOnBeginning: true,
|
||||
endingPossibilities: ["ی"],
|
||||
},
|
||||
{ phoneme: "uy", possibilities: ["ۍ"], endingOnly: true },
|
||||
{ phoneme: "úy", possibilities: ["ۍ"], endingOnly: true }, // THIS CAN ONLY COME AT THE END DEAL WITH THIS
|
||||
{ phoneme: "eyy", possibilities: ["ئ"], endingOnly: true },
|
||||
{ phoneme: "éyy", possibilities: ["ئ"], endingOnly: true },
|
||||
{ phoneme: "ey", possibilities: ["ئ"], endingOnly: true },
|
||||
{ phoneme: "éy", possibilities: ["ئ"], endingOnly: true },
|
||||
|
||||
{ phoneme: "a", diacritic: zwar, endingPossibilities: ["ه"], canComeAfterHeyEnding: true, canBeFirstPartOfFathahanEnding: true },
|
||||
{ phoneme: "á", diacritic: zwar, endingPossibilities: ["ه"], canComeAfterHeyEnding: true, canBeFirstPartOfFathahanEnding: true },
|
||||
{
|
||||
phoneme: "a",
|
||||
diacritic: zwar,
|
||||
endingPossibilities: ["ه"],
|
||||
canComeAfterHayEnding: true,
|
||||
canBeFirstPartOfFathahanEnding: true,
|
||||
},
|
||||
{
|
||||
phoneme: "á",
|
||||
diacritic: zwar,
|
||||
endingPossibilities: ["ه"],
|
||||
canComeAfterHayEnding: true,
|
||||
canBeFirstPartOfFathahanEnding: true,
|
||||
},
|
||||
{ phoneme: "ă", diacritic: zwar },
|
||||
{ phoneme: "ắ", diacritic: zwar },
|
||||
{ phoneme: "u", diacritic: zwarakey, endingPossibilities: ["ه"], hamzaOnEnd: true },
|
||||
{ phoneme: "ú", diacritic: zwarakey, endingPossibilities: ["ه"], hamzaOnEnd: true },
|
||||
{ phoneme: "i", diacritic: zer, endingPossibilities: ["ه"], takesDiacriticBeforeGurdaHeyEnding: true, canBeWasla: true, beginning: ["ا", "ع"] },
|
||||
{ phoneme: "í", diacritic: zer, endingPossibilities: ["ه"], takesDiacriticBeforeGurdaHeyEnding: true, canBeWasla: true, beginning: ["ا", "ع"] },
|
||||
{ phoneme: "U", diacritic: pesh, endingPossibilities: ["ه"], takesDiacriticBeforeGurdaHeyEnding: true, beginning: ["ا", "ع"] },
|
||||
{ phoneme: "Ú", diacritic: pesh, endingPossibilities: ["ه"], takesDiacriticBeforeGurdaHeyEnding: true, beginning: ["ا", "ع"] },
|
||||
{
|
||||
phoneme: "u",
|
||||
diacritic: zwarakay,
|
||||
endingPossibilities: ["ه"],
|
||||
hamzaOnEnd: true,
|
||||
},
|
||||
{
|
||||
phoneme: "ú",
|
||||
diacritic: zwarakay,
|
||||
endingPossibilities: ["ه"],
|
||||
hamzaOnEnd: true,
|
||||
},
|
||||
{
|
||||
phoneme: "i",
|
||||
diacritic: zer,
|
||||
endingPossibilities: ["ه"],
|
||||
takesDiacriticBeforeGurdaHayEnding: true,
|
||||
canBeWasla: true,
|
||||
beginning: ["ا", "ع"],
|
||||
},
|
||||
{
|
||||
phoneme: "í",
|
||||
diacritic: zer,
|
||||
endingPossibilities: ["ه"],
|
||||
takesDiacriticBeforeGurdaHayEnding: true,
|
||||
canBeWasla: true,
|
||||
beginning: ["ا", "ع"],
|
||||
},
|
||||
{
|
||||
phoneme: "U",
|
||||
diacritic: pesh,
|
||||
endingPossibilities: ["ه"],
|
||||
takesDiacriticBeforeGurdaHayEnding: true,
|
||||
beginning: ["ا", "ع"],
|
||||
},
|
||||
{
|
||||
phoneme: "Ú",
|
||||
diacritic: pesh,
|
||||
endingPossibilities: ["ه"],
|
||||
takesDiacriticBeforeGurdaHayEnding: true,
|
||||
beginning: ["ا", "ع"],
|
||||
},
|
||||
];
|
||||
|
||||
function isSpace(s: string): boolean {
|
||||
|
@ -142,7 +261,11 @@ interface IDiacriticsErrorMessage {
|
|||
i: number;
|
||||
}
|
||||
|
||||
function possibilityMatches(p: string, pIndex: number, possibilities: string[] | undefined): boolean {
|
||||
function possibilityMatches(
|
||||
p: string,
|
||||
pIndex: number,
|
||||
possibilities: string[] | undefined
|
||||
): boolean {
|
||||
/* istanbul ignore next */
|
||||
if (!possibilities) {
|
||||
return false;
|
||||
|
@ -155,10 +278,15 @@ function possibilityMatches(p: string, pIndex: number, possibilities: string[] |
|
|||
return false;
|
||||
}
|
||||
|
||||
function isPrefixedByDirectionalPronoun(i: number, phonemes: string[]): boolean {
|
||||
function isPrefixedByDirectionalPronoun(
|
||||
i: number,
|
||||
phonemes: string[]
|
||||
): boolean {
|
||||
const potentialPronounFourCharSlice = phonemes.slice(i - 4, i).join("");
|
||||
const potentialPronounThreeCharSlice = phonemes.slice(i - 3, i).join("");
|
||||
if (["wăr-", "war-", "dăr-", "dar-"].includes(potentialPronounFourCharSlice)) {
|
||||
if (
|
||||
["wăr-", "war-", "dăr-", "dar-"].includes(potentialPronounFourCharSlice)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (potentialPronounThreeCharSlice === "raa-") {
|
||||
|
@ -167,7 +295,11 @@ function isPrefixedByDirectionalPronoun(i: number, phonemes: string[]): boolean
|
|||
return false;
|
||||
}
|
||||
|
||||
export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes: boolean = false): string | undefined {
|
||||
export function phoneticsToDiacritics(
|
||||
ps: string,
|
||||
ph: string,
|
||||
forbidOoPrefixes: boolean = false
|
||||
): string | undefined {
|
||||
const phonemes = splitFIntoPhonemes(ph.trim().split(",")[0]);
|
||||
const p = ps.trim();
|
||||
let result = "";
|
||||
|
@ -179,58 +311,72 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
if (phoneme === "-") {
|
||||
return;
|
||||
}
|
||||
const phonemeInfo = phonemeTable.find((element) => element.phoneme === phoneme);
|
||||
const phonemeInfo = phonemeTable.find(
|
||||
(element) => element.phoneme === phoneme
|
||||
);
|
||||
if (!phonemeInfo) {
|
||||
errored.push({ error: "phoneme info not found", phoneme, i });
|
||||
return;
|
||||
}
|
||||
const isDoubleConsonant = (
|
||||
const isDoubleConsonant =
|
||||
phonemeInfo.consonant &&
|
||||
phoneme === phonemes[i - 1] &&
|
||||
// TODO: is this thourough enough to allow double consonants on the ending of the previous word?
|
||||
!(isSpace(p[pIndex - 1]) && phonemeInfo.possibilities.includes(p[pIndex])) // avoid false double consonant ie ازل لیک azalleek
|
||||
) ? true : false;
|
||||
const isBeginning = !isDoubleConsonant && ((i === 0) || isSpace(p[pIndex - 1]) || (phonemes[i - 1] === "-Ul-") || isPrefixedByDirectionalPronoun(i, phonemes));
|
||||
const upcomingAEndingAfterHey = (p[pIndex] === "ح" && isSpace(p[pIndex + 1]) && ["a", "á"].includes(phonemes[i + 1]));
|
||||
? true
|
||||
: false;
|
||||
const isBeginning =
|
||||
!isDoubleConsonant &&
|
||||
(i === 0 ||
|
||||
isSpace(p[pIndex - 1]) ||
|
||||
phonemes[i - 1] === "-Ul-" ||
|
||||
isPrefixedByDirectionalPronoun(i, phonemes));
|
||||
const upcomingAEndingAfterHay =
|
||||
p[pIndex] === "ح" &&
|
||||
isSpace(p[pIndex + 1]) &&
|
||||
["a", "á"].includes(phonemes[i + 1]);
|
||||
|
||||
// TODO: break this into a seperate function -- why can it sometimes be set to undefined?
|
||||
const isEnding = (i === phonemes.length - 1) || ((
|
||||
(phonemeInfo.possibilities && isSpace(p[pIndex + 1])) ||
|
||||
const isEnding =
|
||||
i === phonemes.length - 1 ||
|
||||
(((phonemeInfo.possibilities && isSpace(p[pIndex + 1])) ||
|
||||
(!phonemeInfo.possibilities && isSpace(p[pIndex])) ||
|
||||
(
|
||||
(!phonemeInfo.possibilities && isSpace(p[pIndex + 1])) &&
|
||||
(possibilityMatches(p, pIndex, phonemeInfo.endingPossibilities) || (p[pIndex] === "ع" && phonemes[i + 1] !== "'"))
|
||||
)
|
||||
) && !upcomingAEndingAfterHey
|
||||
&& // makes sure the next letter isn't a double consonant like haqq <-
|
||||
(!phonemeInfo.possibilities &&
|
||||
isSpace(p[pIndex + 1]) &&
|
||||
(possibilityMatches(p, pIndex, phonemeInfo.endingPossibilities) ||
|
||||
(p[pIndex] === "ع" && phonemes[i + 1] !== "'")))) &&
|
||||
!upcomingAEndingAfterHay && // makes sure the next letter isn't a double consonant like haqq <-
|
||||
!(
|
||||
phonemeInfo.consonant && phoneme === phonemes[i + 1] // &&
|
||||
(phonemeInfo.consonant && phoneme === phonemes[i + 1]) // &&
|
||||
// !(isSpace(p[pIndex + 1]) && phonemeInfo.possibilities.includes(p[pIndex]))
|
||||
)
|
||||
) || // can be the trailing double consanant on the end of a word
|
||||
(
|
||||
phonemeInfo.consonant && phoneme === phonemes[i - 1] &&
|
||||
!(isEndSpace(p[pIndex - 1]) && phonemeInfo.possibilities.includes(p[pIndex]))
|
||||
) || // can be یٰ ending
|
||||
(
|
||||
isEndSpace(p[pIndex + 2]) && (p.slice(pIndex, pIndex + 2) === "یٰ")
|
||||
);
|
||||
)) || // can be the trailing double consanant on the end of a word
|
||||
(phonemeInfo.consonant &&
|
||||
phoneme === phonemes[i - 1] &&
|
||||
!(
|
||||
isEndSpace(p[pIndex - 1]) &&
|
||||
phonemeInfo.possibilities.includes(p[pIndex])
|
||||
)) || // can be یٰ ending
|
||||
(isEndSpace(p[pIndex + 2]) && p.slice(pIndex, pIndex + 2) === "یٰ");
|
||||
|
||||
const isUofDu = phoneme === "u" && (
|
||||
p.slice(pIndex - 2, pIndex) === "د " || // د as previous word
|
||||
const isUofDu =
|
||||
phoneme === "u" &&
|
||||
(p.slice(pIndex - 2, pIndex) === "د " || // د as previous word
|
||||
(p[pIndex] === undefined && p[pIndex - 1] === "د") || // د as the whole thing
|
||||
p.slice(pIndex - 6, pIndex) === "د ... " // ... د is as the previous word
|
||||
);
|
||||
p.slice(pIndex - 6, pIndex) === "د ... "); // ... د is as the previous word
|
||||
// TODO: Should p[pIndex - 1] also be in there ??? It messed up قطعه for instance
|
||||
const isEndingAynVowel = isEnding && phonemeInfo.diacritic && [p[pIndex], p[pIndex - 1]].includes("ع") && p[pIndex] !== "ه";
|
||||
const isEndingAynVowel =
|
||||
isEnding &&
|
||||
phonemeInfo.diacritic &&
|
||||
[p[pIndex], p[pIndex - 1]].includes("ع") &&
|
||||
p[pIndex] !== "ه";
|
||||
const isMiddle = !isBeginning && !isEnding;
|
||||
const isSilentWaw = (
|
||||
const isSilentWaw =
|
||||
p[pIndex] === "و" &&
|
||||
p[pIndex - 1] === "خ" &&
|
||||
p[pIndex + 1] === "ا" &&
|
||||
["áa", "aa"].includes(phoneme)
|
||||
);
|
||||
const isAnAEndingAfterHey = isEnding && p[pIndex - 1] === "ح" && phonemeInfo.canComeAfterHeyEnding;
|
||||
["áa", "aa"].includes(phoneme);
|
||||
const isAnAEndingAfterHay =
|
||||
isEnding && p[pIndex - 1] === "ح" && phonemeInfo.canComeAfterHayEnding;
|
||||
if (isDoubleConsonant) {
|
||||
pIndex--;
|
||||
if (isSpace(p[pIndex])) {
|
||||
|
@ -247,14 +393,22 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
pIndex++;
|
||||
}
|
||||
// special check for Arabic wasla
|
||||
if (p.slice(0, 3) === "بال" && phonemes[i - 1] === "b" && phonemeInfo.canBeWasla && phonemes[i + 1] === "l") {
|
||||
if (
|
||||
p.slice(0, 3) === "بال" &&
|
||||
phonemes[i - 1] === "b" &&
|
||||
phonemeInfo.canBeWasla &&
|
||||
phonemes[i + 1] === "l"
|
||||
) {
|
||||
result += phonemeInfo.diacritic + wasla;
|
||||
pIndex++;
|
||||
previousPhonemeWasAConsonant = false;
|
||||
return;
|
||||
}
|
||||
// special check for fathahan ending
|
||||
if (phonemeInfo.canBeFirstPartOfFathahanEnding && p.slice(pIndex, pIndex + 2) === "اً") {
|
||||
if (
|
||||
phonemeInfo.canBeFirstPartOfFathahanEnding &&
|
||||
p.slice(pIndex, pIndex + 2) === "اً"
|
||||
) {
|
||||
result += "ا";
|
||||
pIndex++;
|
||||
return;
|
||||
|
@ -265,7 +419,12 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
return;
|
||||
}
|
||||
// special check for words starting with عا or عی
|
||||
if (isBeginning && phonemeInfo.canStartWithAynBefore && p[pIndex] === "ع" && phonemeInfo.possibilities.includes(p[pIndex + 1])) {
|
||||
if (
|
||||
isBeginning &&
|
||||
phonemeInfo.canStartWithAynBefore &&
|
||||
p[pIndex] === "ع" &&
|
||||
phonemeInfo.possibilities.includes(p[pIndex + 1])
|
||||
) {
|
||||
result += "ع";
|
||||
result += phonemeInfo.diacritic ? phonemeInfo.diacritic : "";
|
||||
result += p[pIndex + 1];
|
||||
|
@ -273,23 +432,45 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
return;
|
||||
}
|
||||
// special check for ؤ Ua
|
||||
if (phoneme === "U" && phonemes[i + 1] === "a" && phonemes[i + 2] !== "a" && p[pIndex] === "و") {
|
||||
if (
|
||||
phoneme === "U" &&
|
||||
phonemes[i + 1] === "a" &&
|
||||
phonemes[i + 2] !== "a" &&
|
||||
p[pIndex] === "و"
|
||||
) {
|
||||
result += "ؤ";
|
||||
pIndex++;
|
||||
return;
|
||||
}
|
||||
if (phoneme === "a" && phonemes[i - 1] === "U" && phonemes[i + 1] !== "a" && result.slice(-2) === "ؤ") {
|
||||
if (
|
||||
phoneme === "a" &&
|
||||
phonemes[i - 1] === "U" &&
|
||||
phonemes[i + 1] !== "a" &&
|
||||
result.slice(-2) === "ؤ"
|
||||
) {
|
||||
previousPhonemeWasAConsonant = false;
|
||||
return;
|
||||
}
|
||||
// special check for و wo
|
||||
if (isBeginning && phoneme === "w" && phonemes[i + 1] === "o" && p[pIndex] === "و" && isEndSpace(p[pIndex + 1])) {
|
||||
if (
|
||||
isBeginning &&
|
||||
phoneme === "w" &&
|
||||
phonemes[i + 1] === "o" &&
|
||||
p[pIndex] === "و" &&
|
||||
isEndSpace(p[pIndex + 1])
|
||||
) {
|
||||
result += "و";
|
||||
pIndex++;
|
||||
return;
|
||||
}
|
||||
// TODO: isEndSpace here is redundant??
|
||||
if (isEnding && phoneme === "o" && phonemes[i - 1] === "w" && p[pIndex - 1] === "و" && isEndSpace(p[pIndex])) {
|
||||
if (
|
||||
isEnding &&
|
||||
phoneme === "o" &&
|
||||
phonemes[i - 1] === "w" &&
|
||||
p[pIndex - 1] === "و" &&
|
||||
isEndSpace(p[pIndex])
|
||||
) {
|
||||
pIndex++;
|
||||
return;
|
||||
}
|
||||
|
@ -300,38 +481,67 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
return;
|
||||
}
|
||||
// special check for for أ in the middle of the word
|
||||
if (!isBeginning && p[pIndex] === "أ" && phoneme === "a" && phonemes[i + 1] === "'" && phonemes[i + 2] === "a") {
|
||||
if (
|
||||
!isBeginning &&
|
||||
p[pIndex] === "أ" &&
|
||||
phoneme === "a" &&
|
||||
phonemes[i + 1] === "'" &&
|
||||
phonemes[i + 2] === "a"
|
||||
) {
|
||||
result += "أ";
|
||||
pIndex++;
|
||||
return;
|
||||
}
|
||||
if (p[pIndex - 1] === "أ" && phonemes[i - 1] === "a" && phoneme === "'" && phonemes[i + 1] === "a") {
|
||||
if (
|
||||
p[pIndex - 1] === "أ" &&
|
||||
phonemes[i - 1] === "a" &&
|
||||
phoneme === "'" &&
|
||||
phonemes[i + 1] === "a"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (p[pIndex - 1] === "أ" && phonemes[i - 2] === "a" && phonemes[i - 1] === "'" && phoneme === "a") {
|
||||
if (
|
||||
p[pIndex - 1] === "أ" &&
|
||||
phonemes[i - 2] === "a" &&
|
||||
phonemes[i - 1] === "'" &&
|
||||
phoneme === "a"
|
||||
) {
|
||||
previousPhonemeWasAConsonant = false;
|
||||
return;
|
||||
}
|
||||
// special check for وو 'oo
|
||||
if (!isBeginning && p[pIndex] === "و" && p[pIndex + 1] === "و" && phoneme === "'" && phonemes[i + 1] === "oo") {
|
||||
if (
|
||||
!isBeginning &&
|
||||
p[pIndex] === "و" &&
|
||||
p[pIndex + 1] === "و" &&
|
||||
phoneme === "'" &&
|
||||
phonemes[i + 1] === "oo"
|
||||
) {
|
||||
result += "وُو";
|
||||
pIndex += 2;
|
||||
return;
|
||||
}
|
||||
if (p[pIndex - 2] === "و" && p[pIndex - 1] === "و" && phonemes[i - 1] === "'" && phoneme === "oo") {
|
||||
if (
|
||||
p[pIndex - 2] === "و" &&
|
||||
p[pIndex - 1] === "و" &&
|
||||
phonemes[i - 1] === "'" &&
|
||||
phoneme === "oo"
|
||||
) {
|
||||
previousPhonemeWasAConsonant = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const prevLetterWasBeginningAyn = (
|
||||
const prevLetterWasBeginningAyn =
|
||||
p[pIndex - 1] === "ع" &&
|
||||
// isEndSpace(p[pIndex]) && // This breaks it
|
||||
phoneme === "'"
|
||||
);
|
||||
phoneme === "'";
|
||||
// check if the phoneme lines up in the Pashto word
|
||||
if (isBeginning && !isUofDu && phonemeInfo.addAlefOnBeginning) {
|
||||
// TODO: Maybe a little bad because it doesn't loop through possibilities
|
||||
if ((!phonemeInfo.alsoCanBePrefix || forbidOoPrefixes) && p.slice(pIndex, pIndex + 2) !== "ا" + phonemeInfo.possibilities[0]) {
|
||||
if (
|
||||
(!phonemeInfo.alsoCanBePrefix || forbidOoPrefixes) &&
|
||||
p.slice(pIndex, pIndex + 2) !== "ا" + phonemeInfo.possibilities[0]
|
||||
) {
|
||||
errored.push({ error: "didn't start with an aleph", phoneme, i });
|
||||
return;
|
||||
}
|
||||
|
@ -348,18 +558,18 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
pIndex++;
|
||||
return;
|
||||
} else if (
|
||||
(isEnding && phonemeInfo.endingPossibilities) &&
|
||||
isEnding &&
|
||||
phonemeInfo.endingPossibilities &&
|
||||
!isUofDu &&
|
||||
(
|
||||
!possibilityMatches(p, pIndex, phonemeInfo.endingPossibilities) &&
|
||||
!isEndingAynVowel && // allowing short vowels on the end of words ending with ع
|
||||
!isAnAEndingAfterHey
|
||||
)
|
||||
!isAnAEndingAfterHay
|
||||
) {
|
||||
errored.push({ error: "bad ending", phoneme, i });
|
||||
return;
|
||||
} else if (
|
||||
(isEnding && !phonemeInfo.endingPossibilities) &&
|
||||
isEnding &&
|
||||
!phonemeInfo.endingPossibilities &&
|
||||
phonemeInfo.possibilities &&
|
||||
!phonemeInfo.possibilities.includes(p[pIndex])
|
||||
) {
|
||||
|
@ -367,14 +577,17 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
errored.push({ error: "bad ending 2", phoneme, i });
|
||||
return;
|
||||
} else if (
|
||||
(phonemeInfo.possibilities && !isEnding) &&
|
||||
(
|
||||
!(phonemeInfo.possibilities.includes(p[pIndex])) &&
|
||||
!(p[pIndex] === "ن" && (p[pIndex + 1] === "ب" && phoneme === "m")) && // && // exception case with نب === mb
|
||||
phonemeInfo.possibilities &&
|
||||
!isEnding &&
|
||||
!phonemeInfo.possibilities.includes(p[pIndex]) &&
|
||||
!(p[pIndex] === "ن" && p[pIndex + 1] === "ب" && phoneme === "m") && // && // exception case with نب === mb
|
||||
!prevLetterWasBeginningAyn // exception case with words starting with ع like i'zzat
|
||||
)
|
||||
) {
|
||||
errored.push({ error: "improper coressponding letter in middle of word", phoneme, i });
|
||||
errored.push({
|
||||
error: "improper coressponding letter in middle of word",
|
||||
phoneme,
|
||||
i,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// console.log(phoneme, pIndex, p[pIndex], isEnding);
|
||||
|
@ -382,7 +595,12 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
// OK, it lines up with the Pashto word, we're good
|
||||
// Now continue building the result string
|
||||
// deal with starting with short vowels and alef
|
||||
if (!isUofDu && isBeginning && !phonemeInfo.possibilities && !phonemeInfo.isIzafe) {
|
||||
if (
|
||||
!isUofDu &&
|
||||
isBeginning &&
|
||||
!phonemeInfo.possibilities &&
|
||||
!phonemeInfo.isIzafe
|
||||
) {
|
||||
// TODO: WHY IS THIS HERE
|
||||
if (!["ا", "ع"].includes(p[pIndex])) {
|
||||
errored.push({ error: "bad beginning 2", phoneme, i });
|
||||
|
@ -392,22 +610,30 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
pIndex++;
|
||||
}
|
||||
// if the phoneme carries a diacritic insert it (before the letter if it's coming)
|
||||
const isOoPrefix = (phonemeInfo.alsoCanBePrefix && isBeginning && (p[pIndex - 1] !== "ا"));
|
||||
const isOoPrefix =
|
||||
phonemeInfo.alsoCanBePrefix && isBeginning && p[pIndex - 1] !== "ا";
|
||||
if (phonemeInfo.diacritic && !isEnding && !isOoPrefix) {
|
||||
// using this hack to remove the space and put it after the zwarakey we're going to add after د
|
||||
// using this hack to remove the space and put it after the zwarakay we're going to add after د
|
||||
if (isUofDu && result.slice(-5) === " ... ") {
|
||||
result = result.slice(0, -5) + zwarakey + " ... ";
|
||||
result = result.slice(0, -5) + zwarakay + " ... ";
|
||||
} else if (isUofDu && result.slice(-1) === " ") {
|
||||
result = result.slice(0, -1) + zwarakey + " ";
|
||||
result = result.slice(0, -1) + zwarakay + " ";
|
||||
} else {
|
||||
result += phonemeInfo.diacritic;
|
||||
}
|
||||
}
|
||||
// TODO: The middle stuff might be unneccessary/unhelpful
|
||||
const isACommaWithoutAyn = (phoneme === "'" && (p[pIndex] !== "ع" && !(isMiddle && p[pIndex] === "ئ")));
|
||||
const isACommaWithoutAyn =
|
||||
phoneme === "'" && p[pIndex] !== "ع" && !(isMiddle && p[pIndex] === "ئ");
|
||||
// if the previous phoneme was a consonant insert a sukun
|
||||
// console.log("Will I go into the adding thing?");
|
||||
if (!isBeginning && previousPhonemeWasAConsonant && phonemeInfo.consonant && phonemes[i - 1] !== "'" && p[pIndex] !== "ع") {
|
||||
if (
|
||||
!isBeginning &&
|
||||
previousPhonemeWasAConsonant &&
|
||||
phonemeInfo.consonant &&
|
||||
phonemes[i - 1] !== "'" &&
|
||||
p[pIndex] !== "ع"
|
||||
) {
|
||||
result += isDoubleConsonant ? tashdeed : sukun;
|
||||
}
|
||||
if (isEnding && isDoubleConsonant) {
|
||||
|
@ -417,30 +643,38 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
}
|
||||
}
|
||||
// if there's a pashto letter for the phoneme, insert it
|
||||
if (!isEndingAynVowel && !isACommaWithoutAyn && (phonemeInfo.possibilities || isEnding)) {
|
||||
if (
|
||||
!isEndingAynVowel &&
|
||||
!isACommaWithoutAyn &&
|
||||
(phonemeInfo.possibilities || isEnding)
|
||||
) {
|
||||
// need the isSpace check to prevent weird behaviour with izafe
|
||||
if (!isUofDu) {
|
||||
if (isAnAEndingAfterHey) {
|
||||
if (isAnAEndingAfterHay) {
|
||||
result += zwar;
|
||||
if (p[pIndex] === " ") {
|
||||
result += " ";
|
||||
}
|
||||
} else {
|
||||
result += (isDoubleConsonant || isSpace(p[pIndex])) ? "" : p[pIndex];
|
||||
result += isDoubleConsonant || isSpace(p[pIndex]) ? "" : p[pIndex];
|
||||
}
|
||||
}
|
||||
pIndex++;
|
||||
}
|
||||
if (isEnding) {
|
||||
if (isUofDu) {
|
||||
result += zwarakey;
|
||||
result += zwarakay;
|
||||
} else if (phonemeInfo.hamzaOnEnd) {
|
||||
result += hamzaAbove;
|
||||
} else if (phonemeInfo.takesSukunOnEnding) {
|
||||
result += sukun;
|
||||
} else if (p[pIndex] === daggerAlif) {
|
||||
result += daggerAlif;
|
||||
} else if (isEndSpace(p[pIndex]) && p[pIndex - 1] === "ه" && phonemeInfo.takesDiacriticBeforeGurdaHeyEnding) {
|
||||
} else if (
|
||||
isEndSpace(p[pIndex]) &&
|
||||
p[pIndex - 1] === "ه" &&
|
||||
phonemeInfo.takesDiacriticBeforeGurdaHayEnding
|
||||
) {
|
||||
result = result.slice(0, -1) + phonemeInfo.diacritic + "ه";
|
||||
}
|
||||
}
|
||||
|
@ -456,13 +690,20 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
}
|
||||
return;
|
||||
}
|
||||
previousPhonemeWasAConsonant = (!isEnding && phonemeInfo.consonant) ? true : false;
|
||||
previousPhonemeWasAConsonant =
|
||||
!isEnding && phonemeInfo.consonant ? true : false;
|
||||
// ignore the ع or ئ if there's not a ' in the phonetics
|
||||
const nextPhonemeInfo = phonemeTable.find((element) => phonemes[i + 1] === element.phoneme);
|
||||
const nextPhonemeInfo = phonemeTable.find(
|
||||
(element) => phonemes[i + 1] === element.phoneme
|
||||
);
|
||||
if (
|
||||
["ع", "ئ"].includes(p[pIndex]) &&
|
||||
![phonemes[i + 1], phonemes[i + 2]].includes("'") &&
|
||||
!(nextPhonemeInfo && nextPhonemeInfo.diacritic && isEndSpace(p[pIndex + 1])) && // don't skip the ع on the end if there's another short letter coming after it
|
||||
!(
|
||||
nextPhonemeInfo &&
|
||||
nextPhonemeInfo.diacritic &&
|
||||
isEndSpace(p[pIndex + 1])
|
||||
) && // don't skip the ع on the end if there's another short letter coming after it
|
||||
!(p[pIndex] === "ئ" && isEndSpace(p[pIndex + 1])) && // don't skip ئ on the end
|
||||
!phonemeInfo.isIzafe
|
||||
) {
|
||||
|
@ -476,7 +717,11 @@ export function phoneticsToDiacritics(ps: string, ph: string, forbidOoPrefixes:
|
|||
return;
|
||||
}
|
||||
// if we've arrived at a space in the Pashto, move along before the next iteration
|
||||
if (isSpace(p[pIndex]) && phonemes[i + 1] !== "-i-" && !upcomingAEndingAfterHey) {
|
||||
if (
|
||||
isSpace(p[pIndex]) &&
|
||||
phonemes[i + 1] !== "-i-" &&
|
||||
!upcomingAEndingAfterHay
|
||||
) {
|
||||
result += " ";
|
||||
pIndex++;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ export const sandwiches: T.Sandwich[] = [
|
|||
{
|
||||
type: "sandwich",
|
||||
before: { p: "د", f: "du" },
|
||||
after: { p: "په حیث", f: "pu heys" },
|
||||
after: { p: "په حیث", f: "pu hays" },
|
||||
e: "as",
|
||||
},
|
||||
{
|
||||
|
|
|
@ -105,14 +105,14 @@ export const replacerInfo: IReplacerInfoItem[] = [
|
|||
ipa: "ɪ́",
|
||||
},
|
||||
{
|
||||
char: "ey",
|
||||
char: "ay",
|
||||
alalc: "ay",
|
||||
ipa: "ai",
|
||||
ipa: "ay",
|
||||
},
|
||||
{
|
||||
char: "éy",
|
||||
char: "áy",
|
||||
alalc: "áy",
|
||||
ipa: "ái",
|
||||
ipa: "áj",
|
||||
},
|
||||
{
|
||||
char: "ee",
|
||||
|
@ -140,9 +140,9 @@ export const replacerInfo: IReplacerInfoItem[] = [
|
|||
ipa: "u:j",
|
||||
},
|
||||
{
|
||||
char: "eyy",
|
||||
alalc: "ạy",
|
||||
ipa: "ɛ̝j",
|
||||
char: "ey",
|
||||
alalc: "ey",
|
||||
ipa: "ej",
|
||||
},
|
||||
{
|
||||
char: "e",
|
||||
|
@ -351,4 +351,5 @@ export const replacerInfo: IReplacerInfoItem[] = [
|
|||
];
|
||||
|
||||
// tslint:disable-next-line
|
||||
export const replacerRegex = /aay|áay|aa|áa|a|á|U|Ú|u|ú|ooy|o{1,2}|óo|ó|ey|éy|e{1,2}|ée|é|uy|úy|i|í|w|y|q|g|ts|sh|s|dz|z|t|T|d|D|r|R|n|N|f|b|p|x|kh|q|k|gh|g|G|j|ch|l|l|m|h/g;
|
||||
export const replacerRegex =
|
||||
/aay|áay|aa|áa|a|á|U|Ú|u|ú|ooy|o{1,2}|óo|ó|ay|áy|e{1,2}|ée|é|ey|éy|uy|úy|i|í|w|y|q|g|ts|sh|s|dz|z|t|T|d|D|r|R|n|N|f|b|p|x|kh|q|k|gh|g|G|j|ch|l|l|m|h/g;
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import {
|
||||
translatePhonetics,
|
||||
} from "./translate-phonetics";
|
||||
import { translatePhonetics } from "./translate-phonetics";
|
||||
|
||||
const dialects = ["southern", "standard", "peshawer"];
|
||||
const systems = ["ipa", "alalc"];
|
||||
|
@ -54,11 +52,11 @@ const translations = [
|
|||
},
|
||||
},
|
||||
{
|
||||
original: "saRey",
|
||||
original: "saRay",
|
||||
ipa: {
|
||||
southern: "saɻai",
|
||||
standard: "saɻai",
|
||||
peshawer: "saɻai",
|
||||
southern: "saɻaj",
|
||||
standard: "saɻaj",
|
||||
peshawer: "saɻaj",
|
||||
},
|
||||
alalc: {
|
||||
southern: "saṛay",
|
||||
|
@ -72,10 +70,8 @@ translations.forEach((t) => {
|
|||
systems.forEach((system) => {
|
||||
// check each dialect with given system
|
||||
dialects.forEach((dialect) => {
|
||||
test(
|
||||
// @ts-ignore
|
||||
`${t.original} should be translated to ${t.ipa[dialect]} using ${system} with ${dialect} dialect`,
|
||||
() => {
|
||||
test(// @ts-ignore
|
||||
`${t.original} should be translated to ${t.ipa[dialect]} using ${system} with ${dialect} dialect`, () => {
|
||||
const translated = translatePhonetics(t.original, {
|
||||
// @ts-ignore
|
||||
system,
|
||||
|
@ -84,8 +80,7 @@ translations.forEach((t) => {
|
|||
});
|
||||
// @ts-ignore
|
||||
expect(translated).toBe(t[system][dialect]);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,16 +8,21 @@
|
|||
|
||||
import { standardizeEntry, validateEntry } from "./validate-entry";
|
||||
import * as T from "../../types";
|
||||
import { standardizePhonetics } from "./standardize-pashto";
|
||||
|
||||
const toTest: {
|
||||
input: any,
|
||||
output: T.DictionaryEntryError | { ok: true } | { checkComplement: true },
|
||||
input: any;
|
||||
output: T.DictionaryEntryError | { ok: true } | { checkComplement: true };
|
||||
}[] = [
|
||||
{
|
||||
input: { ts: undefined },
|
||||
output: {
|
||||
errors: ["missing ts", "missing i", "missing p", "missing f", "missing e"],
|
||||
errors: [
|
||||
"missing ts",
|
||||
"missing i",
|
||||
"missing p",
|
||||
"missing f",
|
||||
"missing e",
|
||||
],
|
||||
p: "",
|
||||
f: "",
|
||||
e: "",
|
||||
|
@ -37,7 +42,14 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":293,"ts":1527821299,"p":"اخطار","f":"ixtáar","e":"warning, reprimand, admonishment","c":"n. m."},
|
||||
input: {
|
||||
i: 293,
|
||||
ts: 1527821299,
|
||||
p: "اخطار",
|
||||
f: "ixtáar",
|
||||
e: "warning, reprimand, admonishment",
|
||||
c: "n. m.",
|
||||
},
|
||||
output: {
|
||||
errors: ["script and phonetics do not match for p and f"],
|
||||
p: "اخطار",
|
||||
|
@ -48,7 +60,17 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2433,"ts":1527815197,"p":"پښتون","f":"puxtoon","e":"Pashtun","c":"n. m. unisex / adj. irreg.","infap":"پښتانه","infaf":"puxtaanu","infbf":"puxtan"},
|
||||
input: {
|
||||
i: 2433,
|
||||
ts: 1527815197,
|
||||
p: "پښتون",
|
||||
f: "puxtoon",
|
||||
e: "Pashtun",
|
||||
c: "n. m. unisex / adj. irreg.",
|
||||
infap: "پښتانه",
|
||||
infaf: "puxtaanu",
|
||||
infbf: "puxtan",
|
||||
},
|
||||
output: {
|
||||
errors: ["missing infbp"],
|
||||
p: "پښتون",
|
||||
|
@ -59,7 +81,17 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2433,"ts":1527815197,"p":"پښتون","f":"puxtoon","e":"Pashtun","c":"n. m. unisex / adj. irreg.","infap":"پښتانه","infaf":"puxtaanu","infbp":"پښتن"},
|
||||
input: {
|
||||
i: 2433,
|
||||
ts: 1527815197,
|
||||
p: "پښتون",
|
||||
f: "puxtoon",
|
||||
e: "Pashtun",
|
||||
c: "n. m. unisex / adj. irreg.",
|
||||
infap: "پښتانه",
|
||||
infaf: "puxtaanu",
|
||||
infbp: "پښتن",
|
||||
},
|
||||
output: {
|
||||
errors: ["missing infbf"],
|
||||
p: "پښتون",
|
||||
|
@ -70,9 +102,22 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2433,"ts":1527815197,"p":"پښتون","f":"puxtoon","e":"Pashtun","c":"n. m. unisex / adj. irreg.","infap":"پښتانه","infaf":"puktaanu","infbp":"پښتن"},
|
||||
input: {
|
||||
i: 2433,
|
||||
ts: 1527815197,
|
||||
p: "پښتون",
|
||||
f: "puxtoon",
|
||||
e: "Pashtun",
|
||||
c: "n. m. unisex / adj. irreg.",
|
||||
infap: "پښتانه",
|
||||
infaf: "puktaanu",
|
||||
infbp: "پښتن",
|
||||
},
|
||||
output: {
|
||||
errors: ["script and phonetics do not match for infap and infaf", "missing infbf"],
|
||||
errors: [
|
||||
"script and phonetics do not match for infap and infaf",
|
||||
"missing infbf",
|
||||
],
|
||||
p: "پښتون",
|
||||
f: "puxtoon",
|
||||
e: "Pashtun",
|
||||
|
@ -81,7 +126,19 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":5000,"ts":1527819674,"p":"څملاستل","f":"tsumlaastúl","e":"to lie down","l":1596485996977,"separationAtP":2,"c":"v. intrans. seperable","psp":"څمل","psf":"tsaml","noOo":true},
|
||||
input: {
|
||||
i: 5000,
|
||||
ts: 1527819674,
|
||||
p: "څملاستل",
|
||||
f: "tsumlaastúl",
|
||||
e: "to lie down",
|
||||
l: 1596485996977,
|
||||
separationAtP: 2,
|
||||
c: "v. intrans. seperable",
|
||||
psp: "څمل",
|
||||
psf: "tsaml",
|
||||
noOo: true,
|
||||
},
|
||||
output: {
|
||||
errors: ["missing separationAtF"],
|
||||
p: "څملاستل",
|
||||
|
@ -92,9 +149,24 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":5000,"ts":1527819674,"p":"څملاستل","f":"sumlaastúl","e":"to lie down","l":1596485996977,"separationAtP":2,"c":"v. intrans. seperable","psp":"څمل","psf":"tsaml","noOo":true},
|
||||
input: {
|
||||
i: 5000,
|
||||
ts: 1527819674,
|
||||
p: "څملاستل",
|
||||
f: "sumlaastúl",
|
||||
e: "to lie down",
|
||||
l: 1596485996977,
|
||||
separationAtP: 2,
|
||||
c: "v. intrans. seperable",
|
||||
psp: "څمل",
|
||||
psf: "tsaml",
|
||||
noOo: true,
|
||||
},
|
||||
output: {
|
||||
errors: ["script and phonetics do not match for p and f", "missing separationAtF"],
|
||||
errors: [
|
||||
"script and phonetics do not match for p and f",
|
||||
"missing separationAtF",
|
||||
],
|
||||
p: "څملاستل",
|
||||
f: "sumlaastúl",
|
||||
e: "to lie down",
|
||||
|
@ -103,7 +175,19 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":5000,"ts":1527819674,"p":"څملاستل","f":"tsumlaastúl","e":"to lie down","l":1596485996977,"separationAtF":4,"c":"v. intrans. seperable","psp":"څمل","psf":"tsaml","noOo":true},
|
||||
input: {
|
||||
i: 5000,
|
||||
ts: 1527819674,
|
||||
p: "څملاستل",
|
||||
f: "tsumlaastúl",
|
||||
e: "to lie down",
|
||||
l: 1596485996977,
|
||||
separationAtF: 4,
|
||||
c: "v. intrans. seperable",
|
||||
psp: "څمل",
|
||||
psf: "tsaml",
|
||||
noOo: true,
|
||||
},
|
||||
output: {
|
||||
errors: ["missing separationAtP"],
|
||||
p: "څملاستل",
|
||||
|
@ -114,7 +198,14 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2222,"ts":1571859113828,"p":"پخول","f":"pakhawul","e":"to cook, prepare, to cause to ripen, mature","c":"v. stat. comp. trans."},
|
||||
input: {
|
||||
i: 2222,
|
||||
ts: 1571859113828,
|
||||
p: "پخول",
|
||||
f: "pakhawul",
|
||||
e: "to cook, prepare, to cause to ripen, mature",
|
||||
c: "v. stat. comp. trans.",
|
||||
},
|
||||
output: {
|
||||
errors: ["missing complement for compound verb"],
|
||||
p: "پخول",
|
||||
|
@ -125,21 +216,50 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2222,"ts":1571859113828,"p":"پخول","f":"pakhawul","e":"to cook, prepare, to cause to ripen, mature","l":1574867531681,"c":"v. stat. comp. trans."},
|
||||
input: {
|
||||
i: 2222,
|
||||
ts: 1571859113828,
|
||||
p: "پخول",
|
||||
f: "pakhawul",
|
||||
e: "to cook, prepare, to cause to ripen, mature",
|
||||
l: 1574867531681,
|
||||
c: "v. stat. comp. trans.",
|
||||
},
|
||||
output: {
|
||||
checkComplement: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {"i":2231,"ts":1527812013,"p":"پراخ","f":"praakh, paráakh","e":"wide, broad, spacious, vast","c":"adj."},
|
||||
input: {
|
||||
i: 2231,
|
||||
ts: 1527812013,
|
||||
p: "پراخ",
|
||||
f: "praakh, paráakh",
|
||||
e: "wide, broad, spacious, vast",
|
||||
c: "adj.",
|
||||
},
|
||||
output: { ok: true },
|
||||
},
|
||||
{
|
||||
input: {"i":0,"ts":1527812013,"p":"پراخ","f":"praakh, paráakh","e":"wide, broad, spacious, vast","c":"adj."},
|
||||
input: {
|
||||
i: 0,
|
||||
ts: 1527812013,
|
||||
p: "پراخ",
|
||||
f: "praakh, paráakh",
|
||||
e: "wide, broad, spacious, vast",
|
||||
c: "adj.",
|
||||
},
|
||||
output: { ok: true },
|
||||
},
|
||||
{
|
||||
input: {"i":12,"ts":1575058859661,"p":"آبدار","f":"aawdáar","e":"watery, damp, humid, juicy","c":"adj."},
|
||||
input: {
|
||||
i: 12,
|
||||
ts: 1575058859661,
|
||||
p: "آبدار",
|
||||
f: "aawdáar",
|
||||
e: "watery, damp, humid, juicy",
|
||||
c: "adj.",
|
||||
},
|
||||
output: {
|
||||
errors: ["script and phonetics do not match for p and f"],
|
||||
p: "آبدار",
|
||||
|
@ -150,37 +270,84 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"ts":1591033069786,"i":7717,"p":"ستړی کول","f":"stuRey kawul","g":"stuReykedul","e":"to get tired, fatigued","c":"v. stat. comp. intrans.","l":1527815306,"ec":"get","ep":"tired"},
|
||||
input: {
|
||||
ts: 1591033069786,
|
||||
i: 7717,
|
||||
p: "ستړی کول",
|
||||
f: "stuRay kawul",
|
||||
g: "stuRaykedul",
|
||||
e: "to get tired, fatigued",
|
||||
c: "v. stat. comp. intrans.",
|
||||
l: 1527815306,
|
||||
ec: "get",
|
||||
ep: "tired",
|
||||
},
|
||||
output: {
|
||||
errors: ["wrong ending for intrans. stat. comp"],
|
||||
p: "ستړی کول",
|
||||
f: "stuRey kawul",
|
||||
f: "stuRay kawul",
|
||||
e: "to get tired, fatigued",
|
||||
ts: 1591033069786,
|
||||
erroneousFields: ["p", "f"],
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {"ts":1591033078746,"i":7716,"p":"ستړی کېدل","f":"stuRey kedul","g":"stuReykawul","e":"to make tired, wear out","c":"v. stat. comp. trans.","l":1527815306,"ec":"make","ep":"tired"},
|
||||
input: {
|
||||
ts: 1591033078746,
|
||||
i: 7716,
|
||||
p: "ستړی کېدل",
|
||||
f: "stuRay kedul",
|
||||
g: "stuRaykawul",
|
||||
e: "to make tired, wear out",
|
||||
c: "v. stat. comp. trans.",
|
||||
l: 1527815306,
|
||||
ec: "make",
|
||||
ep: "tired",
|
||||
},
|
||||
output: {
|
||||
errors: ["wrong ending for trans. stat. comp"],
|
||||
p: "ستړی کېدل",
|
||||
f: "stuRey kedul",
|
||||
f: "stuRay kedul",
|
||||
e: "to make tired, wear out",
|
||||
ts: 1591033078746,
|
||||
erroneousFields: ["p", "f"],
|
||||
},
|
||||
},
|
||||
{
|
||||
input: {"i":12,"ts":1575058859661,"p":"آبدار","f":"aawdáar","e":"watery, damp, humid, juicy","c":"adj.","diacExcept":true},
|
||||
input: {
|
||||
i: 12,
|
||||
ts: 1575058859661,
|
||||
p: "آبدار",
|
||||
f: "aawdáar",
|
||||
e: "watery, damp, humid, juicy",
|
||||
c: "adj.",
|
||||
diacExcept: true,
|
||||
},
|
||||
output: { ok: true },
|
||||
},
|
||||
{
|
||||
input: {"i":12,"ts":1575058859661,"p":"آبدار","f":"aawdáar","e":"watery, damp, humid, juicy","c":"adj.","diacExcept":true},
|
||||
input: {
|
||||
i: 12,
|
||||
ts: 1575058859661,
|
||||
p: "آبدار",
|
||||
f: "aawdáar",
|
||||
e: "watery, damp, humid, juicy",
|
||||
c: "adj.",
|
||||
diacExcept: true,
|
||||
},
|
||||
output: { ok: true },
|
||||
},
|
||||
{
|
||||
input: {"ts":1527812488,"i":1934,"p":"بې چاره","f":"bechaara","g":"bechaara","e":"poor thing, pitiful","r":3,"c":"adj."},
|
||||
input: {
|
||||
ts: 1527812488,
|
||||
i: 1934,
|
||||
p: "بې چاره",
|
||||
f: "bechaara",
|
||||
g: "bechaara",
|
||||
e: "poor thing, pitiful",
|
||||
r: 3,
|
||||
c: "adj.",
|
||||
},
|
||||
output: {
|
||||
errors: ["spacing discrepency between p and f"],
|
||||
p: "بې چاره",
|
||||
|
@ -191,7 +358,16 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"ts":1527812488,"i":1934,"p":"بېچاره","f":"be chaara","g":"bechaara","e":"poor thing, pitiful","r":3,"c":"adj."},
|
||||
input: {
|
||||
ts: 1527812488,
|
||||
i: 1934,
|
||||
p: "بېچاره",
|
||||
f: "be chaara",
|
||||
g: "bechaara",
|
||||
e: "poor thing, pitiful",
|
||||
r: 3,
|
||||
c: "adj.",
|
||||
},
|
||||
output: {
|
||||
errors: ["spacing discrepency between p and f"],
|
||||
p: "بېچاره",
|
||||
|
@ -202,11 +378,31 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"ts":1527812488,"i":1934,"p":"بې چاره","f":"be chaara","g":"bechaara","e":"poor thing, pitiful","r":3,"c":"adj."},
|
||||
output: { ok: true }
|
||||
input: {
|
||||
ts: 1527812488,
|
||||
i: 1934,
|
||||
p: "بې چاره",
|
||||
f: "be chaara",
|
||||
g: "bechaara",
|
||||
e: "poor thing, pitiful",
|
||||
r: 3,
|
||||
c: "adj.",
|
||||
},
|
||||
output: { ok: true },
|
||||
},
|
||||
{
|
||||
input: {"ts":1527814265,"i":12969,"p":"مکتب","f":"maktab","g":"maktab","e":"school","r":4,"c":"n. m.","app":"مکاتب","apf":"ma kaatib"},
|
||||
input: {
|
||||
ts: 1527814265,
|
||||
i: 12969,
|
||||
p: "مکتب",
|
||||
f: "maktab",
|
||||
g: "maktab",
|
||||
e: "school",
|
||||
r: 4,
|
||||
c: "n. m.",
|
||||
app: "مکاتب",
|
||||
apf: "ma kaatib",
|
||||
},
|
||||
output: {
|
||||
errors: ["spacing discrepency between app and apf"],
|
||||
p: "مکتب",
|
||||
|
@ -217,9 +413,23 @@ const toTest: {
|
|||
},
|
||||
},
|
||||
{
|
||||
input: {"ts":1527815870,"i":183,"p":"اثر","f":"asar","g":"asar","e":"influence, impression, tracks, affect","r":4,"c":"n. m.","app":"اثرات, آثار","apf":"asráat"},
|
||||
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"],
|
||||
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",
|
||||
|
@ -236,6 +446,23 @@ test("validateEntry should work", () => {
|
|||
});
|
||||
|
||||
test("standardizeEntry", () => {
|
||||
expect(standardizeEntry({"i":195,"ts":1527822036,"p":"اجتماعي","f":"ijtimaa‘ee, 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."});
|
||||
expect(
|
||||
standardizeEntry({
|
||||
i: 195,
|
||||
ts: 1527822036,
|
||||
p: "اجتماعي",
|
||||
f: "ijtimaa‘ee, 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.",
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue