Compare commits
No commits in common. "c5a238ab05c06eb448878ed87235254760aa6737" and "e40b3832760aa8228c4a73ce853616934c28a1b4" have entirely different histories.
c5a238ab05
...
e40b383276
|
@ -30,7 +30,6 @@ jobs:
|
|||
yarn install-r
|
||||
yarn build-library
|
||||
yarn test --silent
|
||||
yarn check-all-inflections
|
||||
cp .npmrc src/lib
|
||||
cp .npmrc src/components
|
||||
cd src/lib
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "pashto-inflector",
|
||||
"version": "7.5.1",
|
||||
"version": "7.4.1",
|
||||
"author": "lingdocs.com",
|
||||
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
|
||||
"homepage": "https://verbs.lingdocs.com",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@lingdocs/ps-react",
|
||||
"version": "7.5.1",
|
||||
"version": "7.4.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lingdocs/ps-react",
|
||||
"version": "7.5.1",
|
||||
"version": "7.4.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@formkit/auto-animate": "^1.0.0-beta.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lingdocs/ps-react",
|
||||
"version": "7.5.1",
|
||||
"version": "7.4.1",
|
||||
"description": "Pashto inflector library module with React components",
|
||||
"main": "dist/components/library.js",
|
||||
"module": "dist/components/library.js",
|
||||
|
|
|
@ -3,150 +3,105 @@ import * as T from "../../types";
|
|||
import AdjectivePicker from "./np-picker/AdjectivePicker";
|
||||
import LocativeAdverbPicker from "./ep-explorer/eq-comp-picker/LocativeAdverbPicker";
|
||||
import SandwichPicker from "./np-picker/SandwichPicker";
|
||||
const compTypes: T.ComplementType[] = [
|
||||
"adjective",
|
||||
"loc. adv.",
|
||||
"sandwich",
|
||||
"comp. noun",
|
||||
];
|
||||
const compTypes: T.ComplementType[] = ["adjective", "loc. adv.", "sandwich", "comp. noun"];
|
||||
|
||||
function selectionTypeToCompType(
|
||||
s: Exclude<T.ComplementType, "comp. noun"> | "noun"
|
||||
): T.ComplementType {
|
||||
if (s === "noun") return "comp. noun";
|
||||
return s;
|
||||
function selectionTypeToCompType(s: Exclude<T.ComplementType, "comp. noun"> | "noun"): T.ComplementType {
|
||||
if (s === "noun") return "comp. noun";
|
||||
return s;
|
||||
}
|
||||
|
||||
function ComplementPicker(props: {
|
||||
phraseIsComplete: boolean;
|
||||
onChange: (comp: T.ComplementSelection | undefined) => void;
|
||||
comp: T.ComplementSelection | undefined;
|
||||
opts: T.TextOptions;
|
||||
cantClear?: boolean;
|
||||
heading?: JSX.Element | string;
|
||||
entryFeeder: T.EntryFeeder;
|
||||
negative: boolean;
|
||||
phraseIsComplete: boolean,
|
||||
onChange: (comp: T.ComplementSelection | undefined) => void,
|
||||
comp: T.ComplementSelection | undefined,
|
||||
opts: T.TextOptions,
|
||||
cantClear?: boolean,
|
||||
heading?: JSX.Element | string,
|
||||
entryFeeder: T.EntryFeeder,
|
||||
}) {
|
||||
const [compType, setCompType] = useState<T.ComplementType | undefined>(
|
||||
props.comp ? selectionTypeToCompType(props.comp.selection.type) : undefined
|
||||
);
|
||||
useEffect(() => {
|
||||
setCompType(
|
||||
props.comp
|
||||
const [compType, setCompType] = useState<T.ComplementType | undefined>(props.comp
|
||||
? selectionTypeToCompType(props.comp.selection.type)
|
||||
: undefined
|
||||
);
|
||||
}, [props.comp]);
|
||||
function handleClear() {
|
||||
setCompType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
function handleCompTypeChange(ctp: T.ComplementType) {
|
||||
props.onChange(undefined);
|
||||
setCompType(ctp);
|
||||
}
|
||||
function handleSandwichExit() {
|
||||
setCompType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
const clearButton =
|
||||
compType && !props.cantClear ? (
|
||||
<button className="btn btn-sm btn-light mb-2" onClick={handleClear}>
|
||||
X
|
||||
</button>
|
||||
) : (
|
||||
<div></div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div>
|
||||
{typeof props.heading === "string" ? (
|
||||
<div className="h5 text-center">{props.heading}</div>
|
||||
) : (
|
||||
props.heading
|
||||
)}
|
||||
</div>
|
||||
<div>{clearButton}</div>
|
||||
</div>
|
||||
{!compType && (
|
||||
<div className="text-center">
|
||||
<div className="h6 mr-3">Choose Complement</div>
|
||||
{compTypes.map((cpt) => (
|
||||
<div key={cpt} className="mb-2">
|
||||
<button
|
||||
key={cpt}
|
||||
type="button"
|
||||
className="mr-2 btn btn-sm btn-outline-secondary"
|
||||
onClick={() => handleCompTypeChange(cpt)}
|
||||
>
|
||||
{cpt}
|
||||
</button>
|
||||
: undefined);
|
||||
useEffect(() => {
|
||||
setCompType(props.comp
|
||||
? selectionTypeToCompType(props.comp.selection.type)
|
||||
: undefined);
|
||||
}, [props.comp]);
|
||||
function handleClear() {
|
||||
setCompType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
function handleCompTypeChange(ctp: T.ComplementType) {
|
||||
props.onChange(undefined);
|
||||
setCompType(ctp);
|
||||
}
|
||||
function handleSandwichExit() {
|
||||
setCompType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
const clearButton = (compType && !props.cantClear)
|
||||
? <button className="btn btn-sm btn-light mb-2" onClick={handleClear}>X</button>
|
||||
: <div></div>;
|
||||
return <>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div>
|
||||
{typeof props.heading === "string"
|
||||
? <div className="h5 text-center">{props.heading}</div>
|
||||
: props.heading}
|
||||
</div>
|
||||
<div>
|
||||
{clearButton}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ minWidth: "9rem" }}>
|
||||
{compType === "adjective" ? (
|
||||
<AdjectivePicker
|
||||
entryFeeder={props.entryFeeder}
|
||||
adjective={
|
||||
props.comp?.selection.type === "adjective"
|
||||
? props.comp.selection
|
||||
: undefined
|
||||
}
|
||||
opts={props.opts}
|
||||
onChange={(a) =>
|
||||
props.onChange(
|
||||
a ? { type: "complement", selection: a } : undefined
|
||||
)
|
||||
}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
negative={props.negative}
|
||||
/>
|
||||
) : compType === "loc. adv." ? (
|
||||
<LocativeAdverbPicker
|
||||
entryFeeder={props.entryFeeder.locativeAdverbs}
|
||||
adjective={
|
||||
props.comp?.selection.type === "loc. adv."
|
||||
? props.comp.selection
|
||||
: undefined
|
||||
}
|
||||
opts={props.opts}
|
||||
onChange={(a) =>
|
||||
props.onChange(
|
||||
a ? { type: "complement", selection: a } : undefined
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : compType === "sandwich" ? (
|
||||
<SandwichPicker
|
||||
onChange={(a) =>
|
||||
props.onChange(
|
||||
a ? { type: "complement", selection: a } : undefined
|
||||
)
|
||||
}
|
||||
opts={props.opts}
|
||||
sandwich={
|
||||
props.comp?.selection.type === "sandwich"
|
||||
? props.comp.selection
|
||||
: undefined
|
||||
}
|
||||
entryFeeder={props.entryFeeder}
|
||||
onExit={handleSandwichExit}
|
||||
// TODO: get phraseIsComplete working here
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
negative={props.negative}
|
||||
/>
|
||||
) : compType === "comp. noun" ? (
|
||||
<div style={{ maxWidth: "9rem" }}>
|
||||
Sorry, can't choose complement nouns yet 🚧
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
{!compType && <div className="text-center">
|
||||
<div className="h6 mr-3">
|
||||
Choose Complement
|
||||
</div>
|
||||
{compTypes.map((cpt) => <div key={cpt} className="mb-2">
|
||||
<button
|
||||
key={cpt}
|
||||
type="button"
|
||||
className="mr-2 btn btn-sm btn-outline-secondary"
|
||||
onClick={() => handleCompTypeChange(cpt)}
|
||||
>
|
||||
{cpt}
|
||||
</button>
|
||||
</div>)}
|
||||
</div>}
|
||||
<div style={{ minWidth: "9rem" }}>
|
||||
{compType === "adjective" ?
|
||||
<AdjectivePicker
|
||||
entryFeeder={props.entryFeeder}
|
||||
adjective={props.comp?.selection.type === "adjective" ? props.comp.selection : undefined}
|
||||
opts={props.opts}
|
||||
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
/>
|
||||
: compType === "loc. adv."
|
||||
? <LocativeAdverbPicker
|
||||
entryFeeder={props.entryFeeder.locativeAdverbs}
|
||||
adjective={props.comp?.selection.type === "loc. adv." ? props.comp.selection : undefined}
|
||||
opts={props.opts}
|
||||
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
|
||||
/>
|
||||
: compType === "sandwich"
|
||||
? <SandwichPicker
|
||||
onChange={(a) => props.onChange(a ? { type: "complement", selection: a } : undefined)}
|
||||
opts={props.opts}
|
||||
sandwich={props.comp?.selection.type === "sandwich" ? props.comp.selection : undefined}
|
||||
entryFeeder={props.entryFeeder}
|
||||
onExit={handleSandwichExit}
|
||||
// TODO: get phraseIsComplete working here
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
/>
|
||||
: compType === "comp. noun"
|
||||
? <div style={{ maxWidth: "9rem" }}>
|
||||
Sorry, can't choose complement nouns yet 🚧
|
||||
</div>
|
||||
: null}
|
||||
</div>
|
||||
</>;
|
||||
}
|
||||
|
||||
export default ComplementPicker;
|
||||
export default ComplementPicker;
|
|
@ -3,259 +3,183 @@ import { StyleHTMLAttributes } from "react";
|
|||
import Select, { StylesConfig } from "react-select";
|
||||
import AsyncSelect from "react-select/async";
|
||||
import {
|
||||
makeSelectOption,
|
||||
makeVerbSelectOption,
|
||||
makeSelectOption,
|
||||
makeVerbSelectOption,
|
||||
} from "./np-picker/picker-tools";
|
||||
|
||||
export const customStyles: StylesConfig = {
|
||||
menuPortal: (base: any) => ({
|
||||
...base,
|
||||
zIndex: 99999,
|
||||
}),
|
||||
menu: (base: any) => ({
|
||||
...base,
|
||||
zIndex: 999999,
|
||||
}),
|
||||
option: (provided: any, state: any) => ({
|
||||
...provided,
|
||||
padding: "10px 5px",
|
||||
color: "#121418",
|
||||
}),
|
||||
input: (base: any) => ({
|
||||
...base,
|
||||
padding: 0,
|
||||
}),
|
||||
};
|
||||
|
||||
function EntrySelect<E extends T.DictionaryEntry | T.VerbEntry>(props: {
|
||||
entryFeeder: T.EntryFeederSingleType<E>;
|
||||
value: E | undefined;
|
||||
onChange: (value: E | undefined) => void;
|
||||
name: string | undefined;
|
||||
isVerbSelect?: boolean;
|
||||
opts: T.TextOptions;
|
||||
style?: StyleHTMLAttributes<HTMLDivElement>;
|
||||
placeholder?: string;
|
||||
}) {
|
||||
const divStyle = props.style || { width: "13rem" };
|
||||
const placeholder =
|
||||
"placeholder" in props
|
||||
? props.placeholder
|
||||
: "search" in props.entryFeeder
|
||||
? "Search Pashto"
|
||||
: "Search…";
|
||||
function makeOption(e: E | T.DictionaryEntry) {
|
||||
if ("entry" in e) {
|
||||
return (props.isVerbSelect ? makeVerbSelectOption : makeSelectOption)(
|
||||
e,
|
||||
props.opts
|
||||
);
|
||||
}
|
||||
return makeSelectOption(e, props.opts);
|
||||
}
|
||||
const value = props.value ? makeOption(props.value) : undefined;
|
||||
if ("search" in props.entryFeeder) {
|
||||
const search = props.entryFeeder.search;
|
||||
const getByTs = props.entryFeeder.getByTs;
|
||||
const options = (searchString: string) =>
|
||||
new Promise<{ value: string; label: string | JSX.Element }[]>(
|
||||
(resolve) => {
|
||||
resolve(search(searchString).map(makeOption));
|
||||
}
|
||||
);
|
||||
const onChange = (
|
||||
v: { label: string | JSX.Element; value: string } | null
|
||||
) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
const s = getByTs(parseInt(v.value));
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
};
|
||||
return (
|
||||
<div style={divStyle}>
|
||||
<AsyncSelect
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
className="mb-2"
|
||||
value={value}
|
||||
// @ts-ignore
|
||||
onChange={onChange}
|
||||
defaultOptions={[]}
|
||||
loadOptions={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const entries = props.entryFeeder;
|
||||
const options = entries
|
||||
.sort((a, b) => {
|
||||
if ("entry" in a) {
|
||||
return a.entry.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS");
|
||||
}
|
||||
return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS");
|
||||
})
|
||||
.map(makeOption);
|
||||
const onChange = (
|
||||
v: { label: string | JSX.Element; value: string } | null
|
||||
) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
const s = entries.find((e) =>
|
||||
"entry" in e
|
||||
? e.entry.ts.toString() === v.value
|
||||
: e.ts.toString() === v.value
|
||||
);
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
};
|
||||
return (
|
||||
<div style={divStyle}>
|
||||
<Select
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
value={value || null}
|
||||
// @ts-ignore - sadly gets messed up when using customStyles
|
||||
onChange={onChange}
|
||||
className="mb-2"
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
menuPortal: (base: any) => ({
|
||||
...base,
|
||||
zIndex: 99999,
|
||||
}),
|
||||
menu: (base: any) => ({
|
||||
...base,
|
||||
zIndex: 999999,
|
||||
}),
|
||||
option: (provided: any, state: any) => ({
|
||||
...provided,
|
||||
padding: "10px 5px",
|
||||
color: "#121418",
|
||||
}),
|
||||
input: (base: any) => ({
|
||||
...base,
|
||||
padding: 0,
|
||||
}),
|
||||
}
|
||||
|
||||
export function DeterminerSelect(props: {
|
||||
determiners: Readonly<T.Determiner[]>;
|
||||
value: T.Determiner[];
|
||||
onChange: (value: T.Determiner[] | undefined) => void;
|
||||
name: string | undefined;
|
||||
opts: T.TextOptions;
|
||||
function EntrySelect<E extends T.DictionaryEntry | T.VerbEntry>(props: {
|
||||
entryFeeder: T.EntryFeederSingleType<E>,
|
||||
value: E | undefined,
|
||||
onChange: (value: E | undefined) => void,
|
||||
name: string | undefined,
|
||||
isVerbSelect?: boolean,
|
||||
opts: T.TextOptions,
|
||||
style?: StyleHTMLAttributes<HTMLDivElement>,
|
||||
placeholder?: string,
|
||||
}) {
|
||||
const placeholder = "Select determiner…";
|
||||
const value = props.value ? props.value.map(makeDeterminerOption) : undefined;
|
||||
const options = props.determiners.map(makeDeterminerOption);
|
||||
const onChange = (
|
||||
v: { label: string | JSX.Element; value: string }[] | null
|
||||
) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
const divStyle = props.style || { width: "13rem" };
|
||||
const placeholder = "placeholder" in props
|
||||
? props.placeholder
|
||||
: "search" in props.entryFeeder
|
||||
? "Search Pashto"
|
||||
: "Search…";
|
||||
function makeOption(e: E | T.DictionaryEntry) {
|
||||
if ("entry" in e) {
|
||||
return (props.isVerbSelect ? makeVerbSelectOption : makeSelectOption)(e, props.opts);
|
||||
}
|
||||
return makeSelectOption(e, props.opts);
|
||||
}
|
||||
const dets: T.Determiner[] = v.map(
|
||||
({ value }) => JSON.parse(value) as T.Determiner
|
||||
);
|
||||
props.onChange(dets);
|
||||
};
|
||||
return (
|
||||
<Select
|
||||
name={props.name}
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
value={value}
|
||||
isMulti
|
||||
// @ts-ignore - gets messed up when using customStyles
|
||||
onChange={onChange}
|
||||
className="mb-2"
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
);
|
||||
const value = props.value ? makeOption(props.value) : undefined;
|
||||
if ("search" in props.entryFeeder) {
|
||||
const search = props.entryFeeder.search;
|
||||
const getByTs = props.entryFeeder.getByTs;
|
||||
const options = (searchString: string) =>
|
||||
new Promise<{ value: string, label: string | JSX.Element }[]>(resolve => {
|
||||
resolve(search(searchString).map(makeOption));
|
||||
});
|
||||
const onChange = (v: { label: string | JSX.Element, value: string } | null) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
const s = getByTs(parseInt(v.value));
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
}
|
||||
return <div style={divStyle}>
|
||||
<AsyncSelect
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
className="mb-2"
|
||||
value={value}
|
||||
// @ts-ignore
|
||||
onChange={onChange}
|
||||
defaultOptions={[]}
|
||||
loadOptions={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>;
|
||||
}
|
||||
const entries = props.entryFeeder;
|
||||
const options = entries
|
||||
.sort((a, b) => {
|
||||
if ("entry" in a) {
|
||||
return a.entry.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS")
|
||||
}
|
||||
return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS");
|
||||
})
|
||||
.map(makeOption);
|
||||
const onChange = (v: { label: string | JSX.Element, value: string } | null) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
const s = entries.find(e => (
|
||||
("entry" in e)
|
||||
? e.entry.ts.toString() === v.value
|
||||
: e.ts.toString() === v.value
|
||||
));
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
}
|
||||
return <div style={divStyle}>
|
||||
<Select
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
value={value || null}
|
||||
// @ts-ignore - gets messed up when using customStyles
|
||||
onChange={onChange}
|
||||
className="mb-2"
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export function SandwichSelect<E extends T.Sandwich>(props: {
|
||||
sandwiches: E[];
|
||||
value: E | undefined;
|
||||
onChange: (value: E | undefined) => void;
|
||||
name: string | undefined;
|
||||
opts: T.TextOptions;
|
||||
style?: StyleHTMLAttributes<HTMLDivElement>;
|
||||
sandwiches: E[],
|
||||
value: E | undefined,
|
||||
onChange: (value: E | undefined) => void,
|
||||
name: string | undefined,
|
||||
opts: T.TextOptions,
|
||||
style?: StyleHTMLAttributes<HTMLDivElement>,
|
||||
}) {
|
||||
const divStyle = props.style || { width: "13rem" };
|
||||
const placeholder = "Select Sandwich…";
|
||||
const value = props.value ? makeSandwichOption(props.value) : undefined;
|
||||
const options = props.sandwiches
|
||||
// .sort((a, b) => {
|
||||
// if ("entry" in a) {
|
||||
// return a.before.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS")
|
||||
// }
|
||||
// return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS");
|
||||
// })
|
||||
.map(makeSandwichOption);
|
||||
const onChange = (
|
||||
v: { label: string | JSX.Element; value: string } | null
|
||||
) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
const divStyle = props.style || { width: "13rem" };
|
||||
const placeholder = "Select Sandwich…";
|
||||
const value = props.value ? makeSandwichOption(props.value) : undefined;
|
||||
const options = props.sandwiches
|
||||
// .sort((a, b) => {
|
||||
// if ("entry" in a) {
|
||||
// return a.before.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS")
|
||||
// }
|
||||
// return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS");
|
||||
// })
|
||||
.map(makeSandwichOption);
|
||||
const onChange = (v: { label: string | JSX.Element, value: string } | null) => {
|
||||
if (!v) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
const s = props.sandwiches.find(e => {
|
||||
const sValue = JSON.parse(v.value) as T.Sandwich;
|
||||
if (sValue.type !== "sandwich") throw new Error("error converting selected sandwich value to a sandwich");
|
||||
return sandwichSideEq(e.before, sValue.before)
|
||||
&& sandwichSideEq(e.after, sValue.after)
|
||||
&& (e.e === sValue.e);
|
||||
});
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
}
|
||||
const s = props.sandwiches.find((e) => {
|
||||
const sValue = JSON.parse(v.value) as T.Sandwich;
|
||||
if (sValue.type !== "sandwich")
|
||||
throw new Error(
|
||||
"error converting selected sandwich value to a sandwich"
|
||||
);
|
||||
return (
|
||||
sandwichSideEq(e.before, sValue.before) &&
|
||||
sandwichSideEq(e.after, sValue.after) &&
|
||||
e.e === sValue.e
|
||||
);
|
||||
});
|
||||
if (!s) return;
|
||||
props.onChange(s);
|
||||
};
|
||||
return (
|
||||
<div style={divStyle}>
|
||||
<div>Sandwich Base</div>
|
||||
<Select
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
value={value}
|
||||
// @ts-ignore - gets messed up when using customStyles
|
||||
onChange={onChange}
|
||||
className="mb-2"
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
return <div style={divStyle}>
|
||||
<div>Sandwich Base</div>
|
||||
<Select
|
||||
styles={customStyles}
|
||||
isSearchable={true}
|
||||
value={value}
|
||||
// @ts-ignore - gets messed up when using customStyles
|
||||
onChange={onChange}
|
||||
className="mb-2"
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function sandwichSideEq(
|
||||
s1: T.PsString | undefined,
|
||||
s2: T.PsString | undefined
|
||||
): boolean {
|
||||
if (s1 === undefined && s2 === undefined) {
|
||||
return true;
|
||||
}
|
||||
if (typeof s1 === "object" && typeof s2 === "object" && s1.p === s2.p) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
function sandwichSideEq(s1: T.PsString | undefined, s2: T.PsString | undefined): boolean {
|
||||
if (s1 === undefined && s2 === undefined) {
|
||||
return true
|
||||
}
|
||||
if (typeof s1 === "object" && typeof s2 === "object" && s1.p === s2.p) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeDeterminerOption(d: T.Determiner): {
|
||||
label: string;
|
||||
value: string;
|
||||
} {
|
||||
return {
|
||||
label: `${d.p} - ${d.f}`,
|
||||
value: JSON.stringify(d),
|
||||
};
|
||||
function makeSandwichOption(s: T.Sandwich): { label: string, value: string } {
|
||||
return {
|
||||
label: `${s.before ? s.before.p : ""} ... ${s.after ? s.after.p : ""} (${s.e})`,
|
||||
value: JSON.stringify(s),
|
||||
};
|
||||
}
|
||||
|
||||
function makeSandwichOption(s: T.Sandwich): { label: string; value: string } {
|
||||
return {
|
||||
label: `${s.before ? s.before.p : ""} ... ${s.after ? s.after.p : ""} (${
|
||||
s.e
|
||||
})`,
|
||||
value: JSON.stringify(s),
|
||||
};
|
||||
}
|
||||
|
||||
export default EntrySelect;
|
||||
export default EntrySelect;
|
|
@ -2,116 +2,93 @@ import { useState, useEffect } from "react";
|
|||
import * as T from "../../../types";
|
||||
import SandwichPicker from "../np-picker/SandwichPicker";
|
||||
import AdverbPicker from "./AdverbPicker";
|
||||
type APType = "adverb" | "sandwich";
|
||||
type APType = "adverb" | "sandwich";
|
||||
const types: APType[] = ["adverb", "sandwich"];
|
||||
|
||||
function APPicker(props: {
|
||||
phraseIsComplete: boolean;
|
||||
onChange: (comp: T.APSelection | undefined) => void;
|
||||
AP: T.APSelection | undefined;
|
||||
opts: T.TextOptions;
|
||||
cantClear?: boolean;
|
||||
heading?: JSX.Element | string;
|
||||
entryFeeder: T.EntryFeeder;
|
||||
onRemove: () => void;
|
||||
negative: boolean;
|
||||
phraseIsComplete: boolean,
|
||||
onChange: (comp: T.APSelection | undefined) => void,
|
||||
AP: T.APSelection | undefined,
|
||||
opts: T.TextOptions,
|
||||
cantClear?: boolean,
|
||||
heading?: JSX.Element | string,
|
||||
entryFeeder: T.EntryFeeder,
|
||||
onRemove: () => void,
|
||||
}) {
|
||||
const [type, setType] = useState<APType | undefined>(
|
||||
props.AP ? props.AP.selection.type : undefined
|
||||
);
|
||||
useEffect(() => {
|
||||
setType(props.AP ? props.AP.selection.type : undefined);
|
||||
}, [props.AP]);
|
||||
function handleClear() {
|
||||
setType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
function handleCompTypeChange(ctp: APType) {
|
||||
props.onChange(undefined);
|
||||
setType(ctp);
|
||||
}
|
||||
function handleSandwichExit() {
|
||||
setType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
const clearButton =
|
||||
type && !props.cantClear ? (
|
||||
<button className="btn btn-sm btn-light mb-2" onClick={handleClear}>
|
||||
X
|
||||
</button>
|
||||
) : !props.cantClear ? (
|
||||
<div>
|
||||
<div className="clickable" onClick={props.onRemove}>
|
||||
<i className="fas fa-trash" />
|
||||
const [type, setType] = useState<APType | undefined>(props.AP
|
||||
? props.AP.selection.type
|
||||
: undefined);
|
||||
useEffect(() => {
|
||||
setType(props.AP
|
||||
? props.AP.selection.type
|
||||
: undefined);
|
||||
}, [props.AP]);
|
||||
function handleClear() {
|
||||
setType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
function handleCompTypeChange(ctp: APType) {
|
||||
props.onChange(undefined);
|
||||
setType(ctp);
|
||||
}
|
||||
function handleSandwichExit() {
|
||||
setType(undefined);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
const clearButton = (type && !props.cantClear)
|
||||
? <button className="btn btn-sm btn-light mb-2" onClick={handleClear}>X</button>
|
||||
: (!props.cantClear)
|
||||
? <div>
|
||||
<div className="clickable" onClick={props.onRemove}><i className="fas fa-trash" /></div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div></div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div>
|
||||
{typeof props.heading === "string" ? (
|
||||
<div className="h5 text-center">{props.heading}</div>
|
||||
) : (
|
||||
props.heading
|
||||
)}
|
||||
</div>
|
||||
<div>{clearButton}</div>
|
||||
</div>
|
||||
{!type && (
|
||||
<div className="text-center">
|
||||
<div className="h6 mr-3">Choose AP</div>
|
||||
{types.map((apt) => (
|
||||
<div key={apt} className="mb-2">
|
||||
<button
|
||||
key={apt}
|
||||
type="button"
|
||||
className="mr-2 btn btn-sm btn-outline-secondary"
|
||||
onClick={() => handleCompTypeChange(apt)}
|
||||
>
|
||||
{apt}
|
||||
</button>
|
||||
: <div></div>;
|
||||
return <>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div>
|
||||
{typeof props.heading === "string"
|
||||
? <div className="h5 text-center">{props.heading}</div>
|
||||
: props.heading}
|
||||
</div>
|
||||
<div>
|
||||
{clearButton}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ minWidth: "9rem" }}>
|
||||
{type === "adverb" ? (
|
||||
<AdverbPicker
|
||||
entryFeeder={props.entryFeeder.adverbs}
|
||||
adjective={
|
||||
props.AP?.selection.type === "adverb"
|
||||
? props.AP.selection
|
||||
: undefined
|
||||
}
|
||||
opts={props.opts}
|
||||
onChange={(a) =>
|
||||
props.onChange(a ? { type: "AP", selection: a } : undefined)
|
||||
}
|
||||
/>
|
||||
) : type === "sandwich" ? (
|
||||
<SandwichPicker
|
||||
onChange={(a) =>
|
||||
props.onChange(a ? { type: "AP", selection: a } : undefined)
|
||||
}
|
||||
opts={props.opts}
|
||||
sandwich={
|
||||
props.AP?.selection.type === "sandwich"
|
||||
? props.AP.selection
|
||||
: undefined
|
||||
}
|
||||
entryFeeder={props.entryFeeder}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
onExit={handleSandwichExit}
|
||||
negative={props.negative}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
{!type && <div className="text-center">
|
||||
<div className="h6 mr-3">
|
||||
Choose AP
|
||||
</div>
|
||||
{types.map((apt) => <div key={apt} className="mb-2">
|
||||
<button
|
||||
key={apt}
|
||||
type="button"
|
||||
className="mr-2 btn btn-sm btn-outline-secondary"
|
||||
onClick={() => handleCompTypeChange(apt)}
|
||||
>
|
||||
{apt}
|
||||
</button>
|
||||
</div>)}
|
||||
</div>}
|
||||
<div style={{ minWidth: "9rem" }}>
|
||||
{type === "adverb" ?
|
||||
<AdverbPicker
|
||||
entryFeeder={props.entryFeeder.adverbs}
|
||||
adjective={props.AP?.selection.type === "adverb" ? props.AP.selection : undefined}
|
||||
opts={props.opts}
|
||||
onChange={(a) => props.onChange(a ? { type: "AP", selection: a } : undefined)}
|
||||
/>
|
||||
: type === "sandwich" ?
|
||||
<SandwichPicker
|
||||
onChange={(a) => props.onChange(a ? { type: "AP", selection: a } : undefined)}
|
||||
opts={props.opts}
|
||||
sandwich={props.AP?.selection.type === "sandwich" ? props.AP.selection : undefined}
|
||||
entryFeeder={props.entryFeeder}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
onExit={handleSandwichExit}
|
||||
/>
|
||||
: null}
|
||||
</div>
|
||||
</>;
|
||||
}
|
||||
|
||||
export default APPicker;
|
||||
export default APPicker;
|
|
@ -600,29 +600,23 @@ function Sandwich({
|
|||
);
|
||||
}
|
||||
|
||||
function Determiners({
|
||||
function Demonstrative({
|
||||
opts,
|
||||
script,
|
||||
children,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
script: "p" | "f";
|
||||
children: T.Rendered<T.DeterminersSelection> | undefined;
|
||||
children: T.Rendered<T.DemonstrativeSelection> | undefined;
|
||||
}) {
|
||||
if (!children || children.determiners.length === 0) {
|
||||
if (!children) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="text-center">
|
||||
<div className={`d-flex flex-row${script === "p" ? "-reverse" : ""}`}>
|
||||
{children.determiners.map((d) => (
|
||||
<div className="mx-1">
|
||||
<Border padding={"1rem"}>{d.ps[0][script]}</Border>
|
||||
<div>{"demonstrative" in d.determiner ? "DEM" : "DET"}</div>
|
||||
<SubText>{d.e}</SubText>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Border padding={"1rem"}>{children.ps[script]}</Border>
|
||||
<div>DEM</div>
|
||||
<SubText>{children.e}</SubText>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -669,8 +663,8 @@ export function NPBlock({
|
|||
np.selection.possesor &&
|
||||
!np.selection.possesor.shrunken
|
||||
);
|
||||
const detsWithoutNoun =
|
||||
np.selection.determiners && !np.selection.determiners.withNoun;
|
||||
const demWithoutNoun =
|
||||
np.selection.demonstrative && !np.selection.demonstrative.withNoun;
|
||||
const elements = [
|
||||
...(!inside
|
||||
? [
|
||||
|
@ -681,12 +675,12 @@ export function NPBlock({
|
|||
</Possesors>,
|
||||
]
|
||||
: []),
|
||||
<Determiners opts={opts} script={script}>
|
||||
{np.selection.determiners}
|
||||
</Determiners>,
|
||||
<Demonstrative opts={opts} script={script}>
|
||||
{np.selection.demonstrative ? np.selection.demonstrative : undefined}
|
||||
</Demonstrative>,
|
||||
<div
|
||||
style={{
|
||||
opacity: detsWithoutNoun ? 0.5 : 1,
|
||||
opacity: demWithoutNoun ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
<Adjectives opts={opts} script={script}>
|
||||
|
@ -695,7 +689,7 @@ export function NPBlock({
|
|||
</div>,
|
||||
<div
|
||||
style={{
|
||||
opacity: detsWithoutNoun ? 0.5 : 1,
|
||||
opacity: demWithoutNoun ? 0.5 : 1,
|
||||
}}
|
||||
className={np.selection.adjectives?.length ? "mx-1" : ""}
|
||||
>
|
||||
|
|
|
@ -3,169 +3,109 @@ import NPPicker from "../np-picker/NPPicker";
|
|||
import EquativePicker from "./EquativePicker";
|
||||
import ButtonSelect from "../ButtonSelect";
|
||||
import ComplementPicker from "../ComplementPicker";
|
||||
import epsReducer, {
|
||||
EpsReducerAction,
|
||||
} from "../../../lib/src/phrase-building/eps-reducer";
|
||||
import { useEffect, useRef } from "react";
|
||||
import epsReducer, { EpsReducerAction } from "../../../lib/src/phrase-building/eps-reducer";
|
||||
import {
|
||||
useEffect,
|
||||
useRef,
|
||||
} from "react";
|
||||
import { completeEPSelection } from "../../../lib/src/phrase-building/render-ep";
|
||||
import APPicker from "../../src/ap-picker/APPicker";
|
||||
import autoAnimate from "@formkit/auto-animate";
|
||||
|
||||
function EPPicker({
|
||||
opts,
|
||||
eps,
|
||||
onChange,
|
||||
entryFeeder,
|
||||
}: {
|
||||
opts: T.TextOptions;
|
||||
eps: T.EPSelectionState;
|
||||
onChange: (eps: T.EPSelectionState) => void;
|
||||
entryFeeder: T.EntryFeeder;
|
||||
function EPPicker({ opts, eps, onChange, entryFeeder }: {
|
||||
opts: T.TextOptions,
|
||||
eps: T.EPSelectionState,
|
||||
onChange: (eps: T.EPSelectionState) => void,
|
||||
entryFeeder: T.EntryFeeder,
|
||||
}) {
|
||||
const parent = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
parent.current && autoAnimate(parent.current);
|
||||
}, [parent]);
|
||||
function adjustEps(action: EpsReducerAction) {
|
||||
onChange(epsReducer(eps, action));
|
||||
}
|
||||
const phraseIsComplete = !!completeEPSelection(eps);
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className="clickable h5"
|
||||
onClick={() => adjustEps({ type: "insert new AP" })}
|
||||
>
|
||||
+ AP
|
||||
</div>
|
||||
<div
|
||||
ref={parent}
|
||||
className="d-flex flex-row justify-content-around flex-wrap"
|
||||
style={{ marginLeft: "-0.5rem", marginRight: "-0.5rem" }}
|
||||
>
|
||||
{eps.blocks.map(({ block, key }, i) => (
|
||||
<div className="my-2 card block-card p-1 mx-1" key={key}>
|
||||
<div
|
||||
className="d-flex flex-row justify-content-between mb-1"
|
||||
style={{ height: "1rem" }}
|
||||
>
|
||||
{i > 0 ? (
|
||||
<div
|
||||
className="small clickable ml-1"
|
||||
onClick={() =>
|
||||
adjustEps({
|
||||
type: "shift block",
|
||||
payload: { index: i, direction: "back" },
|
||||
})
|
||||
}
|
||||
>
|
||||
<i className="fas fa-chevron-left" />
|
||||
const parent = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
parent.current && autoAnimate(parent.current);
|
||||
}, [parent]);
|
||||
function adjustEps(action: EpsReducerAction) {
|
||||
onChange(epsReducer(eps, action));
|
||||
}
|
||||
const phraseIsComplete = !!completeEPSelection(eps);
|
||||
return <div>
|
||||
<div className="clickable h5" onClick={() => adjustEps({ type: "insert new AP" })}>+ AP</div>
|
||||
<div ref={parent} className="d-flex flex-row justify-content-around flex-wrap" style={{ marginLeft: "-0.5rem", marginRight: "-0.5rem" }}>
|
||||
{eps.blocks.map(({ block, key }, i) => (
|
||||
<div className="my-2 card block-card p-1 mx-1" key={key}>
|
||||
<div className="d-flex flex-row justify-content-between mb-1" style={{ height: "1rem" }}>
|
||||
{i > 0 ? <div
|
||||
className="small clickable ml-1"
|
||||
onClick={() => adjustEps({ type: "shift block", payload: { index: i, direction: "back" }})}
|
||||
>
|
||||
<i className="fas fa-chevron-left" />
|
||||
</div> : <div/>}
|
||||
{i < eps.blocks.length - 1 ? <div
|
||||
className="small clickable mr-1"
|
||||
onClick={() => adjustEps({ type: "shift block", payload: { index: i, direction: "forward" }})}
|
||||
>
|
||||
<i className="fas fa-chevron-right" />
|
||||
</div> : <div/>}
|
||||
</div>
|
||||
{block && block.type === "subjectSelection"
|
||||
? <NPPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
heading={<div className="h5 text-center">Subject</div>}
|
||||
entryFeeder={entryFeeder}
|
||||
np={block.selection}
|
||||
counterPart={undefined}
|
||||
role="subject"
|
||||
onChange={payload => adjustEps({ type: "set subject", payload })}
|
||||
opts={opts}
|
||||
/>
|
||||
: <APPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
heading="AP"
|
||||
entryFeeder={entryFeeder}
|
||||
AP={block}
|
||||
opts={opts}
|
||||
onChange={AP => adjustEps({ type: "set AP", payload: { index: i, AP } })}
|
||||
onRemove={() => adjustEps({ type: "remove AP", payload: i })}
|
||||
/>}
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
{i < eps.blocks.length - 1 ? (
|
||||
<div
|
||||
className="small clickable mr-1"
|
||||
onClick={() =>
|
||||
adjustEps({
|
||||
type: "shift block",
|
||||
payload: { index: i, direction: "forward" },
|
||||
})
|
||||
}
|
||||
>
|
||||
<i className="fas fa-chevron-right" />
|
||||
))}
|
||||
<div className="my-2 card block-card p-1">
|
||||
<div className="h5 text-center">Predicate</div>
|
||||
<div className="mb-2 text-center">
|
||||
<ButtonSelect
|
||||
small
|
||||
options={[
|
||||
{ value: "NP", label: "NP" },
|
||||
{ value: "Complement", label: "Complement" },
|
||||
]}
|
||||
value={eps.predicate.type}
|
||||
handleChange={payload => adjustEps({ type: "set predicate type", payload })}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
{eps.predicate.type === "NP" ? <NPPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
entryFeeder={entryFeeder}
|
||||
np={eps.predicate.type === "NP" ? eps.predicate.NP : undefined}
|
||||
counterPart={undefined}
|
||||
role="subject"
|
||||
onChange={payload => adjustEps({ type: "set predicate NP", payload })}
|
||||
opts={opts}
|
||||
/> : <ComplementPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
comp={eps.predicate.type === "Complement" ? eps.predicate.Complement : undefined}
|
||||
onChange={payload => adjustEps({ type: "set predicate complement", payload })}
|
||||
opts={opts}
|
||||
entryFeeder={entryFeeder}
|
||||
/>}
|
||||
</div>
|
||||
<div className="my-2">
|
||||
<div className="h5 text-center clickable">Equative</div>
|
||||
<EquativePicker
|
||||
equative={eps.equative}
|
||||
onChange={payload => adjustEps({ type: "set equative", payload })}
|
||||
hideNegative={false}
|
||||
/>
|
||||
</div>
|
||||
{block && block.type === "subjectSelection" ? (
|
||||
<NPPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
heading={<div className="h5 text-center">Subject</div>}
|
||||
entryFeeder={entryFeeder}
|
||||
np={block.selection}
|
||||
counterPart={undefined}
|
||||
role="subject"
|
||||
onChange={(payload) =>
|
||||
adjustEps({ type: "set subject", payload })
|
||||
}
|
||||
opts={opts}
|
||||
negative={eps.equative.negative}
|
||||
/>
|
||||
) : (
|
||||
<APPicker
|
||||
negative={eps.equative.negative}
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
heading="AP"
|
||||
entryFeeder={entryFeeder}
|
||||
AP={block}
|
||||
opts={opts}
|
||||
onChange={(AP) =>
|
||||
adjustEps({ type: "set AP", payload: { index: i, AP } })
|
||||
}
|
||||
onRemove={() => adjustEps({ type: "remove AP", payload: i })}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div className="my-2 card block-card p-1">
|
||||
<div className="h5 text-center">Predicate</div>
|
||||
<div className="mb-2 text-center">
|
||||
<ButtonSelect
|
||||
small
|
||||
options={[
|
||||
{ value: "NP", label: "NP" },
|
||||
{ value: "Complement", label: "Complement" },
|
||||
]}
|
||||
value={eps.predicate.type}
|
||||
handleChange={(payload) =>
|
||||
adjustEps({ type: "set predicate type", payload })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{eps.predicate.type === "NP" ? (
|
||||
<NPPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
entryFeeder={entryFeeder}
|
||||
np={eps.predicate.type === "NP" ? eps.predicate.NP : undefined}
|
||||
counterPart={undefined}
|
||||
role="subject"
|
||||
onChange={(payload) =>
|
||||
adjustEps({ type: "set predicate NP", payload })
|
||||
}
|
||||
opts={opts}
|
||||
negative={eps.equative.negative}
|
||||
/>
|
||||
) : (
|
||||
<ComplementPicker
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
comp={
|
||||
eps.predicate.type === "Complement"
|
||||
? eps.predicate.Complement
|
||||
: undefined
|
||||
}
|
||||
onChange={(payload) =>
|
||||
adjustEps({ type: "set predicate complement", payload })
|
||||
}
|
||||
opts={opts}
|
||||
entryFeeder={entryFeeder}
|
||||
negative={eps.equative.negative}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="my-2">
|
||||
<div className="h5 text-center clickable">Equative</div>
|
||||
<EquativePicker
|
||||
equative={eps.equative}
|
||||
onChange={(payload) => adjustEps({ type: "set equative", payload })}
|
||||
hideNegative={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>;
|
||||
}
|
||||
|
||||
export default EPPicker;
|
||||
export default EPPicker;
|
|
@ -8,7 +8,6 @@ function AdjectiveManager(props: {
|
|||
opts: T.TextOptions;
|
||||
onChange: (adjs: T.AdjectiveSelection[]) => void;
|
||||
phraseIsComplete: boolean;
|
||||
negative: boolean;
|
||||
}) {
|
||||
const [adding, setAdding] = useState<boolean>(false);
|
||||
function handleChange(i: number) {
|
||||
|
@ -49,7 +48,6 @@ function AdjectiveManager(props: {
|
|||
entryFeeder={props.entryFeeder}
|
||||
opts={props.opts}
|
||||
onChange={handleAddNew}
|
||||
negative={props.negative}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
@ -72,7 +70,6 @@ function AdjectiveManager(props: {
|
|||
</div>
|
||||
</div>
|
||||
<AdjectivePicker
|
||||
negative={props.negative}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
noTitle
|
||||
key={`adj${i}`}
|
||||
|
|
|
@ -5,74 +5,64 @@ import EntrySelect from "../EntrySelect";
|
|||
import SandwichPicker from "./SandwichPicker";
|
||||
|
||||
function AdjectivePicker(props: {
|
||||
entryFeeder: T.EntryFeeder;
|
||||
adjective: T.AdjectiveSelection | undefined;
|
||||
onChange: (p: T.AdjectiveSelection | undefined) => void;
|
||||
opts: T.TextOptions;
|
||||
noTitle?: boolean;
|
||||
phraseIsComplete: boolean;
|
||||
negative: boolean;
|
||||
entryFeeder: T.EntryFeeder,
|
||||
adjective: T.AdjectiveSelection | undefined,
|
||||
onChange: (p: T.AdjectiveSelection | undefined) => void,
|
||||
opts: T.TextOptions,
|
||||
noTitle?: boolean,
|
||||
phraseIsComplete: boolean,
|
||||
}) {
|
||||
const [addingSandwich, setAddingSandwich] = useState<boolean>(false);
|
||||
function onEntrySelect(entry: T.AdjectiveEntry | undefined) {
|
||||
if (!entry) {
|
||||
return props.onChange(undefined);
|
||||
const [addingSandwich, setAddingSandwich] = useState<boolean>(false);
|
||||
function onEntrySelect(entry: T.AdjectiveEntry | undefined) {
|
||||
if (!entry) {
|
||||
return props.onChange(undefined);
|
||||
}
|
||||
props.onChange(makeAdjectiveSelection(entry));
|
||||
}
|
||||
props.onChange(makeAdjectiveSelection(entry));
|
||||
}
|
||||
function handleSandwichChange(
|
||||
s: T.SandwichSelection<T.Sandwich> | undefined
|
||||
) {
|
||||
if (!props.adjective) return;
|
||||
props.onChange({
|
||||
...props.adjective,
|
||||
sandwich: s,
|
||||
});
|
||||
if (!s) {
|
||||
setAddingSandwich(false);
|
||||
function handleSandwichChange(s: T.SandwichSelection<T.Sandwich> | undefined) {
|
||||
if (!props.adjective) return;
|
||||
props.onChange({
|
||||
...props.adjective,
|
||||
sandwich: s,
|
||||
});
|
||||
if (!s) {
|
||||
setAddingSandwich(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
function handleSandwichExit() {
|
||||
setAddingSandwich(false);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
return (
|
||||
<div style={{ maxWidth: "225px", minWidth: "125px" }}>
|
||||
{(props.adjective?.sandwich || addingSandwich) && (
|
||||
<SandwichPicker
|
||||
negative={props.negative}
|
||||
onChange={handleSandwichChange}
|
||||
opts={props.opts}
|
||||
sandwich={props.adjective?.sandwich}
|
||||
entryFeeder={props.entryFeeder}
|
||||
onExit={handleSandwichExit}
|
||||
// TODO: not allowing shrinking any possesisives on sandwiches for now - need to work with the blocks and their special behaviour
|
||||
phraseIsComplete={false}
|
||||
/>
|
||||
)}
|
||||
<div className="d-flex flex-row justify-content-between align-items-baseline">
|
||||
{!props.noTitle && (
|
||||
<div>
|
||||
<div className="h6">Adjective</div>
|
||||
</div>
|
||||
)}
|
||||
{/* not ready for sandwiches on adjectives */}
|
||||
{/* {(!addingSandwich && props.adjective && !props.adjective?.sandwich)
|
||||
function handleSandwichExit() {
|
||||
setAddingSandwich(false);
|
||||
props.onChange(undefined);
|
||||
}
|
||||
return <div style={{ maxWidth: "225px", minWidth: "125px" }}>
|
||||
{(props.adjective?.sandwich || addingSandwich) && <SandwichPicker
|
||||
onChange={handleSandwichChange}
|
||||
opts={props.opts}
|
||||
sandwich={props.adjective?.sandwich}
|
||||
entryFeeder={props.entryFeeder}
|
||||
onExit={handleSandwichExit}
|
||||
// TODO: not allowing shrinking any possesisives on sandwiches for now - need to work with the blocks and their special behaviour
|
||||
phraseIsComplete={false}
|
||||
/>}
|
||||
<div className="d-flex flex-row justify-content-between align-items-baseline">
|
||||
{!props.noTitle && <div>
|
||||
<div className="h6">Adjective</div>
|
||||
</div>}
|
||||
{/* not ready for sandwiches on adjectives */}
|
||||
{/* {(!addingSandwich && props.adjective && !props.adjective?.sandwich)
|
||||
? <div className="clickable" onClick={() => setAddingSandwich(true)}>+ Sandwich</div>
|
||||
: <div></div>} */}
|
||||
<div />
|
||||
</div>
|
||||
<div className="mt-1">
|
||||
<EntrySelect
|
||||
value={props.adjective?.entry}
|
||||
entryFeeder={props.entryFeeder.adjectives}
|
||||
onChange={onEntrySelect}
|
||||
name="Adjective"
|
||||
opts={props.opts}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
<div />
|
||||
</div>
|
||||
<div className="mt-1">
|
||||
<EntrySelect
|
||||
value={props.adjective?.entry}
|
||||
entryFeeder={props.entryFeeder.adjectives}
|
||||
onChange={onEntrySelect}
|
||||
name="Adjective"
|
||||
opts={props.opts}
|
||||
/>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
export default AdjectivePicker;
|
||||
export default AdjectivePicker;
|
|
@ -1,52 +1,38 @@
|
|||
import * as T from "../../../types";
|
||||
import { DeterminerSelect } from "../EntrySelect";
|
||||
import classNames from "classnames";
|
||||
|
||||
export default function DeterminersPicker({
|
||||
determiners,
|
||||
export default function DemonstrativePicker({
|
||||
demonstrative,
|
||||
onChange,
|
||||
opts,
|
||||
negative,
|
||||
}: {
|
||||
determiners: T.NounSelection["determiners"];
|
||||
onChange: (dem: T.NounSelection["determiners"]) => void;
|
||||
opts: T.TextOptions;
|
||||
negative: boolean;
|
||||
demonstrative: T.NounSelection["demonstrative"];
|
||||
onChange: (dem: T.NounSelection["demonstrative"]) => void;
|
||||
}) {
|
||||
const hasDemonstrative =
|
||||
determiners &&
|
||||
determiners.determiners.some((d) => "demonstrative" in d.determiner);
|
||||
function allowed(d: T.Determiner): boolean {
|
||||
if (d.p === "هیڅ" && !negative) {
|
||||
return false;
|
||||
function handleDChange(d: "daa" | "hagha" | "dagha") {
|
||||
if (!demonstrative) {
|
||||
onChange({
|
||||
type: "demonstrative",
|
||||
demonstrative: d,
|
||||
withNoun: true,
|
||||
});
|
||||
} else {
|
||||
onChange({
|
||||
...demonstrative,
|
||||
demonstrative: d,
|
||||
});
|
||||
}
|
||||
if (hasDemonstrative && "demonstrative" in d) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function handleWithNounChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
if (determiners) {
|
||||
if (demonstrative) {
|
||||
onChange({
|
||||
...determiners,
|
||||
...demonstrative,
|
||||
withNoun: e.target.checked,
|
||||
});
|
||||
}
|
||||
}
|
||||
function handleDeterminerChange(value: T.Determiner[] | undefined) {
|
||||
onChange({
|
||||
type: "determiners",
|
||||
withNoun: determiners ? determiners.withNoun : true,
|
||||
determiners: value
|
||||
? value.map((d) => ({
|
||||
type: "determiner",
|
||||
determiner: d,
|
||||
}))
|
||||
: [],
|
||||
});
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
{/* <div className="d-flex flex-row justify-content-around py-1">
|
||||
<div className="d-flex flex-row justify-content-around py-1">
|
||||
<div>
|
||||
<button
|
||||
className={classNames("btn", "btn-outline-secondary", {
|
||||
|
@ -76,30 +62,21 @@ export default function DeterminersPicker({
|
|||
>
|
||||
هغه
|
||||
</button>
|
||||
</div>
|
||||
</div> */}
|
||||
<DeterminerSelect
|
||||
determiners={T.determiners.filter(allowed)}
|
||||
value={
|
||||
determiners ? determiners.determiners.map((x) => x.determiner) : []
|
||||
}
|
||||
onChange={handleDeterminerChange}
|
||||
name="determiner"
|
||||
opts={opts}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="form-check"
|
||||
style={{
|
||||
opacity: determiners ? 1 : 0.5,
|
||||
opacity: demonstrative ? 1 : 0.5,
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="form-check-input"
|
||||
type="checkbox"
|
||||
checked={determiners?.withNoun}
|
||||
checked={demonstrative?.withNoun}
|
||||
onChange={handleWithNounChange}
|
||||
id="withNoun"
|
||||
disabled={!hasDemonstrative}
|
||||
disabled={!demonstrative}
|
||||
/>
|
||||
<label className="form-check-label text-muted" htmlFor="withNoun">
|
||||
with noun
|
|
@ -7,7 +7,7 @@ import InlinePs from "../InlinePs";
|
|||
import EntrySelect from "../EntrySelect";
|
||||
import AdjectiveManager from "./AdjectiveManager";
|
||||
import { useState } from "react";
|
||||
import DeterminersPicker from "./DeterminersPicker";
|
||||
import DemonstrativePicker from "./DemonstrativePicker";
|
||||
|
||||
// const filterOptions = [
|
||||
// {
|
||||
|
@ -62,9 +62,9 @@ function NPNounPicker(props: {
|
|||
onChange: (p: T.NounSelection | undefined) => void;
|
||||
opts: T.TextOptions;
|
||||
phraseIsComplete: boolean;
|
||||
negative: boolean;
|
||||
}) {
|
||||
const [addingDeterminers, setAddingDeterminers] = useState<boolean>(false);
|
||||
const [addingDemonstrative, setAddingDemonstrative] =
|
||||
useState<boolean>(false);
|
||||
// const [patternFilter, setPatternFilter] = useState<FilterPattern | undefined>(undefined);
|
||||
// const [showFilter, setShowFilter] = useState<boolean>(false)
|
||||
// const nounsFiltered = props.nouns
|
||||
|
@ -88,13 +88,13 @@ function NPNounPicker(props: {
|
|||
});
|
||||
}
|
||||
}
|
||||
function handleDeterminersChange(
|
||||
determiners: undefined | T.NounSelection["determiners"]
|
||||
function handleDemonstrativeChange(
|
||||
demonstrative: undefined | T.NounSelection["demonstrative"]
|
||||
) {
|
||||
if (props.noun) {
|
||||
props.onChange({
|
||||
...props.noun,
|
||||
determiners,
|
||||
demonstrative,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -105,34 +105,32 @@ function NPNounPicker(props: {
|
|||
minWidth: "125px",
|
||||
}}
|
||||
>
|
||||
{!addingDeterminers && !props.noun?.determiners ? (
|
||||
{!addingDemonstrative && !props.noun?.demonstrative ? (
|
||||
<div>
|
||||
<span
|
||||
className="clickable text-muted"
|
||||
onClick={() => setAddingDeterminers(true)}
|
||||
onClick={() => setAddingDemonstrative(true)}
|
||||
>
|
||||
+ Determiners
|
||||
+ Demonstrative
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="d-flex flex-row justify-content-between mb-1">
|
||||
<div>{!props.noun?.determiners ? "Add" : ""} Determiners</div>
|
||||
<div>{!props.noun?.demonstrative ? "Add" : ""} Demonstrative</div>
|
||||
<div
|
||||
className="clickable"
|
||||
onClick={() => {
|
||||
handleDeterminersChange(undefined);
|
||||
setAddingDeterminers(false);
|
||||
handleDemonstrativeChange(undefined);
|
||||
setAddingDemonstrative(false);
|
||||
}}
|
||||
>
|
||||
<i className="fas fa-trash" />
|
||||
</div>
|
||||
</div>
|
||||
<DeterminersPicker
|
||||
determiners={props.noun?.determiners}
|
||||
onChange={handleDeterminersChange}
|
||||
opts={props.opts}
|
||||
negative={props.negative}
|
||||
<DemonstrativePicker
|
||||
demonstrative={props.noun?.demonstrative}
|
||||
onChange={handleDemonstrativeChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
@ -153,14 +151,13 @@ function NPNounPicker(props: {
|
|||
<div
|
||||
style={{
|
||||
opacity:
|
||||
props.noun?.determiners && !props.noun.determiners.withNoun
|
||||
props.noun?.demonstrative && !props.noun.demonstrative.withNoun
|
||||
? 0.5
|
||||
: 1,
|
||||
}}
|
||||
>
|
||||
{props.noun && (
|
||||
<AdjectiveManager
|
||||
negative={props.negative}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
adjectives={props.noun?.adjectives}
|
||||
entryFeeder={props.entryFeeder}
|
||||
|
|
|
@ -25,7 +25,6 @@ function NPPicker(props: {
|
|||
phraseIsComplete: boolean;
|
||||
isShrunk?: boolean;
|
||||
isRemoved?: boolean;
|
||||
negative: boolean;
|
||||
}) {
|
||||
if (
|
||||
props.is2ndPersonPicker &&
|
||||
|
@ -224,7 +223,6 @@ function NPPicker(props: {
|
|||
role="possesor"
|
||||
opts={props.opts}
|
||||
entryFeeder={props.entryFeeder}
|
||||
negative={props.negative}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
@ -252,7 +250,6 @@ function NPPicker(props: {
|
|||
<NounPicker
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
entryFeeder={props.entryFeeder}
|
||||
negative={props.negative}
|
||||
noun={
|
||||
props.np && props.np.selection.type === "noun"
|
||||
? props.np.selection
|
||||
|
|
|
@ -5,82 +5,74 @@ import { useEffect, useState } from "react";
|
|||
import NPPicker from "./NPPicker";
|
||||
|
||||
function SandwichPicker(props: {
|
||||
opts: T.TextOptions;
|
||||
onChange: (s: T.SandwichSelection<T.Sandwich> | undefined) => void;
|
||||
sandwich: T.SandwichSelection<T.Sandwich> | undefined;
|
||||
entryFeeder: T.EntryFeeder;
|
||||
phraseIsComplete: boolean;
|
||||
onExit: () => void;
|
||||
negative: boolean;
|
||||
opts: T.TextOptions,
|
||||
onChange: (s: T.SandwichSelection<T.Sandwich> | undefined) => void,
|
||||
sandwich: T.SandwichSelection<T.Sandwich> | undefined;
|
||||
entryFeeder: T.EntryFeeder,
|
||||
phraseIsComplete: boolean,
|
||||
onExit: () => void,
|
||||
}) {
|
||||
const [sandwichBase, setSandwichBase] = useState<T.Sandwich | undefined>(
|
||||
props.sandwich
|
||||
);
|
||||
useEffect(() => {
|
||||
setSandwichBase(props.sandwich);
|
||||
}, [props.sandwich]);
|
||||
function handleNounChange(n: T.NPSelection | undefined) {
|
||||
if (!n) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
const [sandwichBase, setSandwichBase] = useState<T.Sandwich | undefined>(props.sandwich);
|
||||
useEffect(() => {
|
||||
setSandwichBase(props.sandwich);
|
||||
}, [props.sandwich]);
|
||||
function handleNounChange(n: T.NPSelection | undefined) {
|
||||
if (!n) {
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
if (!sandwichBase) return;
|
||||
props.onChange({
|
||||
...sandwichBase,
|
||||
inside: n,
|
||||
});
|
||||
}
|
||||
if (!sandwichBase) return;
|
||||
props.onChange({
|
||||
...sandwichBase,
|
||||
inside: n,
|
||||
});
|
||||
}
|
||||
function handleSandwichChange(s: T.Sandwich | undefined) {
|
||||
if (!s) {
|
||||
setSandwichBase(undefined);
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
function handleSandwichChange(s: T.Sandwich | undefined) {
|
||||
if (!s) {
|
||||
setSandwichBase(undefined);
|
||||
props.onChange(undefined);
|
||||
return;
|
||||
}
|
||||
setSandwichBase(s);
|
||||
if (!props.sandwich) return;
|
||||
props.onChange({
|
||||
...props.sandwich,
|
||||
...s,
|
||||
});
|
||||
}
|
||||
setSandwichBase(s);
|
||||
if (!props.sandwich) return;
|
||||
props.onChange({
|
||||
...props.sandwich,
|
||||
...s,
|
||||
});
|
||||
}
|
||||
function handleExit() {
|
||||
props.onExit();
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div className="text-center">🥪 Sandwich</div>
|
||||
<div className="clickable" onClick={handleExit}>
|
||||
<i className="fas fa-trash" />
|
||||
function handleExit() {
|
||||
props.onExit();
|
||||
}
|
||||
return <div>
|
||||
<div className="d-flex flex-row justify-content-between">
|
||||
<div></div>
|
||||
<div className="text-center">🥪 Sandwich</div>
|
||||
<div className="clickable" onClick={handleExit}>
|
||||
<i className="fas fa-trash" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ border: "1px #6C757D solid", padding: "3px" }}>
|
||||
{sandwichBase && (
|
||||
<div className="mb-2" style={{ margin: "0 auto" }}>
|
||||
<div style={{ border: "1px #6C757D solid", padding: "3px" }}>
|
||||
{sandwichBase && <div className="mb-2" style={{ margin: "0 auto" }}>
|
||||
<NPPicker
|
||||
onChange={handleNounChange}
|
||||
np={props.sandwich ? props.sandwich.inside : undefined}
|
||||
counterPart={undefined}
|
||||
opts={props.opts}
|
||||
role="object"
|
||||
cantClear={true}
|
||||
entryFeeder={props.entryFeeder}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
negative={props.negative}
|
||||
onChange={handleNounChange}
|
||||
np={props.sandwich ? props.sandwich.inside : undefined}
|
||||
counterPart={undefined}
|
||||
opts={props.opts}
|
||||
role="object"
|
||||
cantClear={true}
|
||||
entryFeeder={props.entryFeeder}
|
||||
phraseIsComplete={props.phraseIsComplete}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>}
|
||||
<SandwichSelect
|
||||
name="sandwich"
|
||||
opts={props.opts}
|
||||
sandwiches={sandwiches}
|
||||
value={sandwichBase}
|
||||
onChange={handleSandwichChange}
|
||||
name="sandwich"
|
||||
opts={props.opts}
|
||||
sandwiches={sandwiches}
|
||||
value={sandwichBase}
|
||||
onChange={handleSandwichChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
export default SandwichPicker;
|
||||
export default SandwichPicker;
|
|
@ -44,7 +44,7 @@ function VPExplorer(props: {
|
|||
props.loaded
|
||||
? props.loaded
|
||||
: (savedVps) => makeVPSelectionState(props.verb, savedVps),
|
||||
"vpsState17",
|
||||
"vpsState16",
|
||||
flashMessage
|
||||
);
|
||||
const [mode, setMode] = useStickyState<"charts" | "phrases" | "quiz">(
|
||||
|
|
|
@ -163,7 +163,6 @@ function VPPicker({
|
|||
</div>
|
||||
{!block || block.type === "AP" ? (
|
||||
<APPicker
|
||||
negative={vps.verb.negative}
|
||||
phraseIsComplete={phraseIsComplete}
|
||||
heading="AP"
|
||||
entryFeeder={entryFeeder}
|
||||
|
@ -239,7 +238,6 @@ function VPPicker({
|
|||
opts={opts}
|
||||
isShrunk={servantIsShrunk && roles.servant === "subject"}
|
||||
isRemoved={roles.king === "subject" && VPS?.form.removeKing}
|
||||
negative={VPS?.verb.negative || false}
|
||||
/>
|
||||
) : vps.verb &&
|
||||
block?.type === "objectSelection" &&
|
||||
|
@ -352,7 +350,6 @@ function VPPicker({
|
|||
isRemoved={
|
||||
roles.king === "object" && VPS?.form.removeKing
|
||||
}
|
||||
negative={VPS?.verb.negative || false}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
@ -375,7 +372,6 @@ function VPPicker({
|
|||
}
|
||||
opts={opts}
|
||||
entryFeeder={entryFeeder}
|
||||
negative={vps.verb.negative}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lingdocs/inflect",
|
||||
"version": "7.5.1",
|
||||
"version": "7.4.1",
|
||||
"description": "Pashto inflector library",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/lib/library.d.ts",
|
||||
|
|
|
@ -48,7 +48,7 @@ type Plurals =
|
|||
// const endingInHayOrAynRegex = /[^ا][هع]$/;
|
||||
|
||||
export function getInfsAndVocative(
|
||||
entryR: T.DictionaryEntryNoFVars | T.Determiner,
|
||||
entryR: T.DictionaryEntryNoFVars,
|
||||
plurals: Plurals
|
||||
):
|
||||
| {
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
personNumber,
|
||||
personToGenNum,
|
||||
} from "../misc-helpers";
|
||||
import { monoidPsString } from "../fp-ps";
|
||||
import { applySingleOrLengthOpts, fmapSingleOrLengthOpts } from "../fp-ps";
|
||||
import {
|
||||
concatPsString,
|
||||
|
@ -449,7 +448,7 @@ function ensure3rdPast(
|
|||
}
|
||||
const abruptEnder = ["د", "ت", "ړ"].includes(rs[0].p.slice(-1));
|
||||
// short endings like ورسېد
|
||||
const ends = abruptEnder ? [monoidPsString.empty, ...ending] : ending;
|
||||
const ends = abruptEnder ? [{ p: "", f: "" }, ...ending] : ending;
|
||||
return verbEndingConcat(rs, ends);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export function inflectWord(word: T.DictionaryEntry): T.InflectorOutput {
|
|||
// If it's a noun/adj, inflect accordingly
|
||||
// TODO: What about n. f. / adj. that end in ي ??
|
||||
const w = removeFVarients(word);
|
||||
if (word.c?.includes("doub.")) {
|
||||
if (w.c?.includes("doub.")) {
|
||||
const words = splitDoubleWord(w);
|
||||
// TODO: Make this work for non-unisex double words
|
||||
// Right now this an extremely bad and complex way to do this
|
||||
|
|
|
@ -420,123 +420,3 @@ function arrayMove<X>(ar: X[], old_index: number, new_index: number): X[] {
|
|||
arr.splice(new_i, 0, arr.splice(old_index, 1)[0]);
|
||||
return arr;
|
||||
}
|
||||
|
||||
// TODO: This takes 8 helper functions to recursively go down and check all determiners
|
||||
// - is this what LENSES would help with?
|
||||
export function removeHeetsDet<B extends T.VPSBlock[] | T.EPSBlock[]>(
|
||||
blocks: B
|
||||
): B {
|
||||
return blocks.map<T.VPSBlock | T.EPSBlock>((x) => ({
|
||||
key: x.key,
|
||||
block: removeHeetsDetFromBlock(x.block),
|
||||
})) as B;
|
||||
}
|
||||
|
||||
// TODO: Could use lenses for this
|
||||
function removeHeetsDetFromBlock<
|
||||
B extends T.VPSBlock["block"] | T.EPSBlock["block"]
|
||||
>(block: B): B {
|
||||
if (!block) {
|
||||
return block;
|
||||
}
|
||||
if (block.type === "AP") {
|
||||
return removeHeetsDetFromAP(block) as B;
|
||||
}
|
||||
if (block.type === "complement") {
|
||||
return removeHeetsFromComp(block) as B;
|
||||
}
|
||||
return {
|
||||
...block,
|
||||
selection:
|
||||
typeof block.selection === "object"
|
||||
? removeHeetsFromNP(block.selection)
|
||||
: block.selection,
|
||||
};
|
||||
}
|
||||
|
||||
function removeHeetsDetFromAP(ap: T.APSelection): T.APSelection {
|
||||
if (ap.selection.type === "adverb") {
|
||||
return ap;
|
||||
}
|
||||
return {
|
||||
...ap,
|
||||
selection: removeHeetsFromSandwich(ap.selection),
|
||||
};
|
||||
}
|
||||
|
||||
function removeHeetsFromSandwich(
|
||||
sand: T.SandwichSelection<T.Sandwich>
|
||||
): T.SandwichSelection<T.Sandwich> {
|
||||
return {
|
||||
...sand,
|
||||
inside: removeHeetsFromNP(sand.inside),
|
||||
};
|
||||
}
|
||||
|
||||
function removeHeetsFromAdjective(
|
||||
adj: T.AdjectiveSelection
|
||||
): T.AdjectiveSelection {
|
||||
return {
|
||||
...adj,
|
||||
sandwich: adj.sandwich ? removeHeetsFromSandwich(adj.sandwich) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function removeHeetsFromComp(
|
||||
comp: T.ComplementSelection
|
||||
): T.ComplementSelection {
|
||||
if (comp.selection.type === "adjective") {
|
||||
return {
|
||||
...comp,
|
||||
selection: removeHeetsFromAdjective(comp.selection),
|
||||
};
|
||||
}
|
||||
if (comp.selection.type === "noun") {
|
||||
return {
|
||||
...comp,
|
||||
selection: removeHeetsFromNoun(comp.selection),
|
||||
};
|
||||
}
|
||||
if (comp.selection.type === "sandwich") {
|
||||
return {
|
||||
...comp,
|
||||
selection: removeHeetsFromSandwich(comp.selection),
|
||||
};
|
||||
}
|
||||
// should be only a loc. adv. left
|
||||
return comp;
|
||||
}
|
||||
|
||||
function removeHeetsFromNoun(n: T.NounSelection): T.NounSelection {
|
||||
return {
|
||||
...n,
|
||||
adjectives: n.adjectives.map(removeHeetsFromAdjective),
|
||||
...(n.determiners
|
||||
? {
|
||||
determiners: removeHeetsFromDets(n.determiners),
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function removeHeetsFromNP(np: T.NPSelection): T.NPSelection {
|
||||
if (np.selection.type === "noun") {
|
||||
return {
|
||||
...np,
|
||||
selection: removeHeetsFromNoun(np.selection),
|
||||
};
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
function removeHeetsFromDets(
|
||||
dets: T.DeterminersSelection | undefined
|
||||
): T.DeterminersSelection | undefined {
|
||||
if (!dets) {
|
||||
return dets;
|
||||
}
|
||||
return {
|
||||
...dets,
|
||||
determiners: dets.determiners.filter((d) => d.determiner.p !== "هیڅ"),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
specifyEquativeLength,
|
||||
} from "./blocks-utils";
|
||||
import { blank, kidsBlank } from "../misc-helpers";
|
||||
import { monoidPsString, monoidPsStringWVars } from "../fp-ps";
|
||||
import { monoidPsStringWVars } from "../fp-ps";
|
||||
import { concatAll } from "fp-ts/lib/Monoid";
|
||||
|
||||
type BlankoutOptions = {
|
||||
|
@ -275,7 +275,7 @@ function applyBlankOut(
|
|||
return kidsBlank;
|
||||
}
|
||||
if (blankOut?.negative && "block" in x && x.block.type === "negative") {
|
||||
return monoidPsString.empty;
|
||||
return { p: "", f: "" };
|
||||
}
|
||||
return x;
|
||||
});
|
||||
|
@ -314,7 +314,7 @@ function getPsFromPiece(
|
|||
}
|
||||
if (piece.block.type === "objectSelection") {
|
||||
if (typeof piece.block.selection !== "object") {
|
||||
return [monoidPsString.empty];
|
||||
return [{ p: "", f: "" }];
|
||||
}
|
||||
return getPashtoFromRendered(piece.block.selection, subjectPerson);
|
||||
}
|
||||
|
|
|
@ -1,257 +1,216 @@
|
|||
import * as T from "../../../types";
|
||||
import { personGender, personNumber } from "../misc-helpers";
|
||||
import {
|
||||
personGender,
|
||||
personNumber,
|
||||
} from "../misc-helpers";
|
||||
import { isUnisexNounEntry } from "../type-predicates";
|
||||
import { checkForMiniPronounsError } from "./compile";
|
||||
import {
|
||||
adjustSubjectSelection,
|
||||
getSubjectSelection,
|
||||
insertNewAP,
|
||||
removeAP,
|
||||
removeHeetsDet,
|
||||
setAP,
|
||||
shiftBlock,
|
||||
} from "./blocks-utils";
|
||||
import { adjustSubjectSelection, getSubjectSelection, insertNewAP, removeAP, setAP, shiftBlock } from "./blocks-utils";
|
||||
|
||||
export type EpsReducerAction =
|
||||
| {
|
||||
type: "set predicate type";
|
||||
payload: "NP" | "Complement";
|
||||
}
|
||||
| {
|
||||
type: "set subject";
|
||||
payload: T.NPSelection | undefined;
|
||||
}
|
||||
| {
|
||||
type: "set predicate NP";
|
||||
payload: T.NPSelection | undefined;
|
||||
}
|
||||
| {
|
||||
type: "set predicate complement";
|
||||
payload: T.ComplementSelection | undefined;
|
||||
}
|
||||
| {
|
||||
type: "set omitSubject";
|
||||
payload: "true" | "false";
|
||||
}
|
||||
| {
|
||||
type: "set equative";
|
||||
payload: T.EquativeSelection;
|
||||
}
|
||||
| {
|
||||
type: "insert new AP";
|
||||
}
|
||||
| {
|
||||
type: "set AP";
|
||||
payload: {
|
||||
index: number;
|
||||
AP: T.APSelection | undefined;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: "remove AP";
|
||||
payload: number;
|
||||
}
|
||||
| {
|
||||
type: "shift block";
|
||||
payload: {
|
||||
index: number;
|
||||
direction: "back" | "forward";
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: "load EPS";
|
||||
payload: T.EPSelectionState;
|
||||
};
|
||||
|
||||
export default function epsReducer(
|
||||
eps: T.EPSelectionState,
|
||||
action: EpsReducerAction,
|
||||
sendAlert?: (msg: string) => void
|
||||
): T.EPSelectionState {
|
||||
if (action.type === "set predicate type") {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
type: action.payload,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (action.type === "set subject") {
|
||||
const subject = action.payload;
|
||||
if (!subject) {
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
};
|
||||
}
|
||||
if (
|
||||
subject.selection.type === "pronoun" &&
|
||||
eps.predicate.type === "NP" &&
|
||||
eps.predicate.NP?.selection.type === "noun" &&
|
||||
isUnisexNounEntry(eps.predicate.NP.selection.entry)
|
||||
) {
|
||||
const predicate = eps.predicate.NP.selection;
|
||||
const adjusted = {
|
||||
...predicate,
|
||||
...(predicate.numberCanChange
|
||||
? {
|
||||
number: personNumber(subject.selection.person),
|
||||
}
|
||||
: {}),
|
||||
...(predicate.genderCanChange
|
||||
? {
|
||||
gender: personGender(subject.selection.person),
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: {
|
||||
type: "NP",
|
||||
selection: adjusted,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
};
|
||||
return subject ? ensureMiniPronounsOk(eps, n, sendAlert) : n;
|
||||
}
|
||||
if (action.type === "set predicate NP") {
|
||||
const selection = action.payload;
|
||||
if (!selection) {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
}
|
||||
const subject = getSubjectSelection(eps.blocks).selection;
|
||||
if (
|
||||
subject?.selection.type === "pronoun" &&
|
||||
selection.selection.type === "noun" &&
|
||||
isUnisexNounEntry(selection.selection.entry)
|
||||
) {
|
||||
const { gender, number } = selection.selection;
|
||||
const pronoun = subject.selection.person;
|
||||
const newPronoun = movePersonNumber(
|
||||
movePersonGender(pronoun, gender),
|
||||
number
|
||||
);
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, {
|
||||
type: "NP",
|
||||
selection: {
|
||||
...subject.selection,
|
||||
person: newPronoun,
|
||||
},
|
||||
}),
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
}
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
return selection ? ensureMiniPronounsOk(eps, n, sendAlert) : n;
|
||||
}
|
||||
if (action.type === "set predicate complement") {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
Complement: action.payload,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (action.type === "set omitSubject") {
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
omitSubject: action.payload === "true",
|
||||
};
|
||||
return ensureMiniPronounsOk(eps, n, sendAlert);
|
||||
}
|
||||
if (action.type === "set equative") {
|
||||
return {
|
||||
...eps,
|
||||
blocks: !action.payload.negative
|
||||
? removeHeetsDet(eps.blocks)
|
||||
: eps.blocks,
|
||||
equative: action.payload,
|
||||
};
|
||||
}
|
||||
if (action.type === "insert new AP") {
|
||||
return {
|
||||
...eps,
|
||||
blocks: insertNewAP(eps.blocks),
|
||||
};
|
||||
}
|
||||
if (action.type === "set AP") {
|
||||
const { index, AP } = action.payload;
|
||||
return {
|
||||
...eps,
|
||||
blocks: setAP(eps.blocks, index, AP),
|
||||
};
|
||||
}
|
||||
if (action.type === "remove AP") {
|
||||
return {
|
||||
...eps,
|
||||
blocks: removeAP(eps.blocks, action.payload),
|
||||
};
|
||||
}
|
||||
if (action.type === "shift block") {
|
||||
const { index, direction } = action.payload;
|
||||
return {
|
||||
...eps,
|
||||
blocks: shiftBlock(eps.blocks, index, direction),
|
||||
};
|
||||
}
|
||||
if (action.type === "load EPS") {
|
||||
return action.payload;
|
||||
}
|
||||
throw new Error("unknown epsReducer action");
|
||||
export type EpsReducerAction = {
|
||||
type: "set predicate type",
|
||||
payload: "NP" | "Complement",
|
||||
} | {
|
||||
type: "set subject",
|
||||
payload: T.NPSelection | undefined,
|
||||
} | {
|
||||
type: "set predicate NP",
|
||||
payload: T.NPSelection | undefined,
|
||||
} | {
|
||||
type: "set predicate complement",
|
||||
payload: T.ComplementSelection | undefined,
|
||||
} | {
|
||||
type: "set omitSubject",
|
||||
payload: "true" | "false",
|
||||
} | {
|
||||
type: "set equative",
|
||||
payload: T.EquativeSelection,
|
||||
} | {
|
||||
type: "insert new AP",
|
||||
} | {
|
||||
type: "set AP",
|
||||
payload: {
|
||||
index: number,
|
||||
AP: T.APSelection | undefined,
|
||||
},
|
||||
} | {
|
||||
type: "remove AP",
|
||||
payload: number,
|
||||
} | {
|
||||
type: "shift block",
|
||||
payload: {
|
||||
index: number,
|
||||
direction: "back" | "forward",
|
||||
},
|
||||
} | {
|
||||
type: "load EPS",
|
||||
payload: T.EPSelectionState,
|
||||
}
|
||||
|
||||
function ensureMiniPronounsOk(
|
||||
old: T.EPSelectionState,
|
||||
eps: T.EPSelectionState,
|
||||
sendAlert?: (msg: string) => void
|
||||
): T.EPSelectionState {
|
||||
const error = checkForMiniPronounsError(eps);
|
||||
if (error) {
|
||||
if (sendAlert) sendAlert(error);
|
||||
return old;
|
||||
}
|
||||
return eps;
|
||||
export default function epsReducer(eps: T.EPSelectionState, action: EpsReducerAction, sendAlert?: (msg: string) => void): T.EPSelectionState {
|
||||
if (action.type === "set predicate type") {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
type: action.payload,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (action.type === "set subject") {
|
||||
const subject = action.payload;
|
||||
if (!subject) {
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
};
|
||||
}
|
||||
if (subject.selection.type === "pronoun" && eps.predicate.type === "NP" && eps.predicate.NP?.selection.type === "noun" && isUnisexNounEntry(eps.predicate.NP.selection.entry)) {
|
||||
const predicate = eps.predicate.NP.selection;
|
||||
const adjusted = {
|
||||
...predicate,
|
||||
...predicate.numberCanChange ? {
|
||||
number: personNumber(subject.selection.person),
|
||||
} : {},
|
||||
...predicate.genderCanChange ? {
|
||||
gender: personGender(subject.selection.person),
|
||||
} : {},
|
||||
}
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: {
|
||||
type: "NP",
|
||||
selection: adjusted,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, subject),
|
||||
};
|
||||
return subject ? ensureMiniPronounsOk(eps, n, sendAlert) : n;
|
||||
}
|
||||
if (action.type === "set predicate NP") {
|
||||
const selection = action.payload;
|
||||
if (!selection) {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
}
|
||||
const subject = getSubjectSelection(eps.blocks).selection;
|
||||
if (subject?.selection.type === "pronoun" && selection.selection.type === "noun" && isUnisexNounEntry(selection.selection.entry)) {
|
||||
const { gender, number } = selection.selection;
|
||||
const pronoun = subject.selection.person;
|
||||
const newPronoun = movePersonNumber(movePersonGender(pronoun, gender), number);
|
||||
return {
|
||||
...eps,
|
||||
blocks: adjustSubjectSelection(eps.blocks, {
|
||||
type: "NP",
|
||||
selection: {
|
||||
...subject.selection,
|
||||
person: newPronoun,
|
||||
},
|
||||
}),
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
}
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
NP: selection,
|
||||
},
|
||||
};
|
||||
return selection ? ensureMiniPronounsOk(eps, n, sendAlert) : n;
|
||||
}
|
||||
if (action.type === "set predicate complement") {
|
||||
return {
|
||||
...eps,
|
||||
predicate: {
|
||||
...eps.predicate,
|
||||
Complement: action.payload,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (action.type === "set omitSubject") {
|
||||
const n: T.EPSelectionState = {
|
||||
...eps,
|
||||
omitSubject: action.payload === "true",
|
||||
};
|
||||
return ensureMiniPronounsOk(eps, n, sendAlert);
|
||||
}
|
||||
if (action.type === "set equative") {
|
||||
return {
|
||||
...eps,
|
||||
equative: action.payload,
|
||||
}
|
||||
}
|
||||
if (action.type === "insert new AP") {
|
||||
return {
|
||||
...eps,
|
||||
blocks: insertNewAP(eps.blocks),
|
||||
};
|
||||
}
|
||||
if (action.type === "set AP") {
|
||||
const { index, AP } = action.payload;
|
||||
return {
|
||||
...eps,
|
||||
blocks: setAP(eps.blocks, index, AP),
|
||||
};
|
||||
}
|
||||
if (action.type === "remove AP") {
|
||||
return {
|
||||
...eps,
|
||||
blocks: removeAP(eps.blocks, action.payload),
|
||||
};
|
||||
}
|
||||
if (action.type === "shift block") {
|
||||
const { index, direction } = action.payload;
|
||||
return {
|
||||
...eps,
|
||||
blocks: shiftBlock(eps.blocks, index, direction),
|
||||
};
|
||||
}
|
||||
if (action.type === "load EPS") {
|
||||
return action.payload;
|
||||
}
|
||||
throw new Error("unknown epsReducer action");
|
||||
}
|
||||
|
||||
function ensureMiniPronounsOk(old: T.EPSelectionState, eps: T.EPSelectionState, sendAlert?: (msg: string) => void): T.EPSelectionState {
|
||||
const error = checkForMiniPronounsError(eps);
|
||||
if (error) {
|
||||
if (sendAlert) sendAlert(error);
|
||||
return old;
|
||||
}
|
||||
return eps;
|
||||
}
|
||||
|
||||
function movePersonGender(p: T.Person, gender: T.Gender): T.Person {
|
||||
const pGender = personGender(p);
|
||||
if (gender === pGender) {
|
||||
return p;
|
||||
}
|
||||
return gender === "masc" ? p - 1 : p + 1;
|
||||
const pGender = personGender(p);
|
||||
if (gender === pGender) {
|
||||
return p;
|
||||
}
|
||||
return (gender === "masc") ? (p - 1) : (p + 1);
|
||||
}
|
||||
|
||||
function movePersonNumber(p: T.Person, number: T.NounNumber): T.Person {
|
||||
const pNumber = personNumber(p);
|
||||
if (pNumber === number) {
|
||||
return p;
|
||||
}
|
||||
return number === "plural" ? p + 6 : p - 6;
|
||||
}
|
||||
const pNumber = personNumber(p);
|
||||
if (pNumber === number) {
|
||||
return p;
|
||||
}
|
||||
return (number === "plural")
|
||||
? (p + 6)
|
||||
: (p - 6);
|
||||
}
|
|
@ -81,6 +81,6 @@ export function makeNounSelection(
|
|||
possesor: !complementType ? old?.possesor : undefined,
|
||||
dynamicComplement: complementType === "dynamic",
|
||||
genStativeComplement: complementType === "generative stative",
|
||||
determiners: old?.determiners,
|
||||
demonstrative: old?.demonstrative,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@ import { isFirstPerson, isSecondPerson } from "../misc-helpers";
|
|||
import * as T from "../../../types";
|
||||
import { concatPsString } from "../p-text-helpers";
|
||||
import { flattenLengths } from "./compile";
|
||||
import { monoidPsStringWVars } from "../fp-ps";
|
||||
import { concatAll } from "fp-ts/lib/Monoid";
|
||||
|
||||
function getBaseWDetsAndAdjs({
|
||||
function getBaseAndAdjectives({
|
||||
selection,
|
||||
}: T.Rendered<
|
||||
T.NPSelection | T.ComplementSelection | T.APSelection
|
||||
|
@ -13,39 +11,45 @@ function getBaseWDetsAndAdjs({
|
|||
if (selection.type === "sandwich") {
|
||||
return getSandwichPsBaseAndAdjectives(selection);
|
||||
}
|
||||
const determiners = (
|
||||
("determiners" in selection && selection.determiners?.determiners) ||
|
||||
[]
|
||||
).map((x) => x.ps);
|
||||
const detWOutNoun =
|
||||
"determiners" in selection &&
|
||||
selection.determiners &&
|
||||
!selection.determiners.withNoun;
|
||||
const adjs = (("adjectives" in selection && selection.adjectives) || []).map(
|
||||
(x) => x.ps
|
||||
const adjs = "adjectives" in selection && selection.adjectives;
|
||||
const demonstrativePs = ("demonstrative" in selection &&
|
||||
selection.demonstrative?.ps) || { p: "", f: "" };
|
||||
if (!adjs) {
|
||||
// TODO: does this ever get used??
|
||||
return flattenLengths(selection.ps).map((x) =>
|
||||
concatPsString(demonstrativePs, x)
|
||||
);
|
||||
}
|
||||
|
||||
if (selection.demonstrative && !selection.demonstrative.withNoun) {
|
||||
return [demonstrativePs];
|
||||
}
|
||||
|
||||
return flattenLengths(selection.ps).map((p) =>
|
||||
concatPsString(
|
||||
demonstrativePs,
|
||||
// demons ? " " : "",
|
||||
adjs.reduce(
|
||||
(accum, curr) => {
|
||||
// TODO: with variations of adjs? {
|
||||
return concatPsString(
|
||||
accum,
|
||||
accum.p === "" && accum.f === "" ? "" : "", //" ",
|
||||
curr.ps[0]
|
||||
);
|
||||
},
|
||||
{ p: "", f: "" }
|
||||
),
|
||||
" ",
|
||||
p
|
||||
)
|
||||
);
|
||||
const base = flattenLengths(selection.ps);
|
||||
return assemblePsWords([
|
||||
...determiners,
|
||||
...(detWOutNoun ? [] : [...adjs, base]),
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: perhaps use this for more things (a simple compileIntoText ?)
|
||||
function assemblePsWords(words: T.PsString[][]): T.PsString[] {
|
||||
return concatAll(monoidPsStringWVars)([
|
||||
...intersperse(words, [{ p: " ", f: " " }]),
|
||||
]);
|
||||
}
|
||||
|
||||
function intersperse<T>(arr: T[], sep: T): T[] {
|
||||
return arr.reduce((a: T[], v: T) => [...a, v, sep], []).slice(0, -1);
|
||||
}
|
||||
|
||||
function getSandwichPsBaseAndAdjectives(
|
||||
s: T.Rendered<T.SandwichSelection<T.Sandwich>>
|
||||
): T.PsString[] {
|
||||
const insideBase = getBaseWDetsAndAdjs(s.inside);
|
||||
const insideBase = getBaseAndAdjectives(s.inside);
|
||||
const willContractWithPronoun =
|
||||
s.before &&
|
||||
s.before.p === "د" &&
|
||||
|
@ -114,7 +118,7 @@ export function getPashtoFromRendered(
|
|||
| T.Rendered<T.APSelection>,
|
||||
subjectsPerson: false | T.Person
|
||||
): T.PsString[] {
|
||||
const base = getBaseWDetsAndAdjs(b);
|
||||
const base = getBaseAndAdjectives(b);
|
||||
if (b.selection.type === "loc. adv." || b.selection.type === "adverb") {
|
||||
return base;
|
||||
}
|
||||
|
@ -168,7 +172,7 @@ function addPossesor(
|
|||
);
|
||||
}
|
||||
const wPossesor = existing.flatMap((ps) =>
|
||||
getBaseWDetsAndAdjs(owner).map((v) =>
|
||||
getBaseAndAdjectives(owner).map((v) =>
|
||||
owner.selection.type === "pronoun" &&
|
||||
subjectsPerson !== false &&
|
||||
willBeReflexive(subjectsPerson, owner.selection.person)
|
||||
|
@ -200,7 +204,7 @@ function addArticlesAndAdjs(
|
|||
const adjs = !np.adjectives
|
||||
? ""
|
||||
: np.adjectives.reduce((accum, curr): string => {
|
||||
if (!curr.e) return "ADJ";
|
||||
if (!curr.e) throw new Error("no english for adjective");
|
||||
return accum + curr.e + " ";
|
||||
}, "");
|
||||
const genderTag = np.genderCanChange
|
||||
|
@ -208,17 +212,10 @@ function addArticlesAndAdjs(
|
|||
? " (f.)"
|
||||
: " (m.)"
|
||||
: "";
|
||||
const moreThanOneDet = (np.determiners?.determiners.length || 0) > 1;
|
||||
const determiners =
|
||||
np.determiners && np.determiners.determiners
|
||||
? np.determiners.determiners
|
||||
// @ts-ignore - weird, ts is not recognizing this as rendered
|
||||
.map((x) => (moreThanOneDet ? `(${x.e})` : x.e))
|
||||
.join(" ")
|
||||
: "";
|
||||
const detsWithoutNoun = np.determiners && !np.determiners.withNoun;
|
||||
return `${np.determiners ? "" : articles}${determiners}${
|
||||
detsWithoutNoun ? ` (${(adjs + word).trim()})` : adjs + word
|
||||
const demonstrative = np.demonstrative ? ` ${np.demonstrative.e}` : "";
|
||||
const demWithoutNoun = np.demonstrative && !np.demonstrative.withNoun;
|
||||
return `${np.demonstrative ? "" : articles}${demonstrative}${
|
||||
demWithoutNoun ? ` (${(adjs + word).trim()})` : adjs + word
|
||||
}${genderTag}`;
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
|
|
|
@ -15,7 +15,6 @@ import { shortVerbEndConsonant } from "../parsing/misc";
|
|||
import { removeL } from "../new-verb-engine/rs-helpers";
|
||||
import { applySingleOrLengthOpts } from "../fp-ps";
|
||||
import { accentOnNFromEnd } from "../accent-helpers";
|
||||
import { getInfsAndVocative } from "../inflections-and-vocative";
|
||||
|
||||
// TODO: can have subject and objects in possesors!!
|
||||
|
||||
|
@ -116,20 +115,6 @@ export function renderNounSelection(
|
|||
return ps.length > 0 ? ps : [psStringFromEntry(n.entry)];
|
||||
})();
|
||||
const person = getPersonNumber(n.gender, n.number);
|
||||
const determiners: T.Rendered<T.DeterminersSelection> | undefined =
|
||||
n.determiners
|
||||
? {
|
||||
...n.determiners,
|
||||
determiners: n.determiners.determiners.map((determiner) =>
|
||||
renderDeterminer({
|
||||
determiner,
|
||||
inflected,
|
||||
number: n.number,
|
||||
gender: n.gender,
|
||||
})
|
||||
),
|
||||
}
|
||||
: undefined;
|
||||
return {
|
||||
...n,
|
||||
adjectives: n.adjectives.map((a) =>
|
||||
|
@ -146,119 +131,64 @@ export function renderNounSelection(
|
|||
ps: pashto,
|
||||
e: english,
|
||||
possesor: renderPossesor(n.possesor, role),
|
||||
determiners,
|
||||
demonstrative: renderDemonstrative({
|
||||
demonstrative: n.demonstrative,
|
||||
inflected,
|
||||
plural: n.number === "plural",
|
||||
gender: n.gender,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function renderDeterminer({
|
||||
determiner: { determiner },
|
||||
function renderDemonstrative({
|
||||
demonstrative,
|
||||
inflected,
|
||||
number,
|
||||
plural,
|
||||
gender,
|
||||
}: {
|
||||
determiner: T.DeterminerSelection;
|
||||
demonstrative: T.DemonstrativeSelection | undefined;
|
||||
inflected: boolean;
|
||||
number: T.NounNumber;
|
||||
plural: boolean;
|
||||
gender: T.Gender;
|
||||
}): T.Rendered<T.DeterminerSelection> {
|
||||
if (determiner.p === "دا") {
|
||||
const ps = inflected ? { p: "دې", f: "de" } : { p: "دا", f: "daa" };
|
||||
return {
|
||||
type: "determiner",
|
||||
determiner,
|
||||
inflected,
|
||||
number,
|
||||
gender,
|
||||
ps: [ps],
|
||||
e: number === "plural" ? "these" : "this",
|
||||
};
|
||||
}): T.Rendered<T.DemonstrativeSelection> | undefined {
|
||||
if (!demonstrative) {
|
||||
return undefined;
|
||||
}
|
||||
if (determiner.p === "دغه") {
|
||||
const ps = inflected
|
||||
? number === "plural"
|
||||
? { p: "دغو", f: "dágho" }
|
||||
: gender === "masc"
|
||||
? { p: "دغه", f: "dághu" }
|
||||
: { p: "دغې", f: "dághe" }
|
||||
: { p: "دغه", f: "dágha" };
|
||||
return {
|
||||
type: "determiner",
|
||||
determiner,
|
||||
inflected,
|
||||
number,
|
||||
gender,
|
||||
ps: [ps],
|
||||
e: number === "plural" ? "these" : "this",
|
||||
};
|
||||
}
|
||||
if (determiner.p === "هغه") {
|
||||
const ps = inflected
|
||||
? number === "plural"
|
||||
const ps =
|
||||
demonstrative.demonstrative === "daa"
|
||||
? inflected
|
||||
? { p: "دې", f: "de" }
|
||||
: { p: "دا", f: "daa" }
|
||||
: demonstrative.demonstrative === "dagha"
|
||||
? inflected
|
||||
? plural
|
||||
? { p: "دغو", f: "dágho" }
|
||||
: gender === "masc"
|
||||
? { p: "دغه", f: "dághu" }
|
||||
: { p: "دغې", f: "dághe" }
|
||||
: { p: "دغه", f: "dágha" }
|
||||
: inflected
|
||||
? plural
|
||||
? { p: "هغو", f: "hágho" }
|
||||
: gender === "masc"
|
||||
? { p: "هغه", f: "hághu" }
|
||||
: { p: "هغې", f: "hághe" }
|
||||
: { p: "هغه", f: "hágha" };
|
||||
return {
|
||||
type: "determiner",
|
||||
determiner,
|
||||
inflected,
|
||||
number,
|
||||
gender,
|
||||
ps: [ps],
|
||||
e: number === "plural" ? "those" : "that",
|
||||
};
|
||||
}
|
||||
const e =
|
||||
determiner.f === "Tol"
|
||||
? "all/the whole"
|
||||
: determiner.f === "bul"
|
||||
? "other/another"
|
||||
: determiner.f === "har"
|
||||
? "every/each"
|
||||
: determiner.f === "koom"
|
||||
? "some/which"
|
||||
: determiner.f === "heets"
|
||||
? "no"
|
||||
: determiner.f === "dáase"
|
||||
? number === "plural"
|
||||
? "such/like these"
|
||||
: "such/like this"
|
||||
: determiner.f === "daghase"
|
||||
? `just such/just like ${number === "plural" ? "these" : "this"}`
|
||||
: determiner.f === "hase"
|
||||
? `such/like ${number === "plural" ? "those" : "that"}`
|
||||
: number === "plural"
|
||||
? "just such/just like these"
|
||||
: "just such/just like this";
|
||||
demonstrative.demonstrative === "hagha"
|
||||
? plural
|
||||
? "those"
|
||||
: "that"
|
||||
: plural
|
||||
? "these"
|
||||
: "this";
|
||||
return {
|
||||
type: "determiner",
|
||||
determiner,
|
||||
inflected,
|
||||
number,
|
||||
gender,
|
||||
ps: inflectDeterminer(determiner, inflected, gender, number),
|
||||
...demonstrative,
|
||||
ps,
|
||||
e,
|
||||
};
|
||||
}
|
||||
|
||||
function inflectDeterminer(
|
||||
determiner: T.Determiner,
|
||||
inflected: boolean,
|
||||
gender: T.Gender,
|
||||
number: T.NounNumber
|
||||
): T.PsString[] {
|
||||
const infs = getInfsAndVocative(determiner, undefined);
|
||||
if (!infs || !infs.inflections) {
|
||||
return [{ p: determiner.p, f: determiner.f }];
|
||||
}
|
||||
const inf = getBasicInf(infs.inflections, gender, number, inflected);
|
||||
if (!inf) {
|
||||
return [{ p: determiner.p, f: determiner.f }];
|
||||
}
|
||||
return inf;
|
||||
}
|
||||
|
||||
function renderPronounSelection(
|
||||
p: T.PronounSelection,
|
||||
inflected: boolean,
|
||||
|
@ -339,20 +269,6 @@ function renderPossesor(
|
|||
};
|
||||
}
|
||||
|
||||
function getBasicInf(
|
||||
infs: T.Inflections,
|
||||
gender: T.Gender,
|
||||
number: T.NounNumber,
|
||||
inflected: boolean
|
||||
): T.PsString[] | false {
|
||||
const inflectionNumber = (inflected ? 1 : 0) + (number === "plural" ? 1 : 0);
|
||||
if (gender in infs) {
|
||||
// @ts-ignore
|
||||
return infs[gender][inflectionNumber];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getInf(
|
||||
infs: T.InflectorOutput,
|
||||
t: "plural" | "arabicPlural" | "inflections",
|
||||
|
|
|
@ -11,7 +11,6 @@ import {
|
|||
getSubjectSelection,
|
||||
insertNewAP,
|
||||
removeAP,
|
||||
removeHeetsDet,
|
||||
setAP,
|
||||
shiftBlock,
|
||||
} from "./blocks-utils";
|
||||
|
@ -20,7 +19,6 @@ import {
|
|||
changeTransitivity,
|
||||
makeVPSelectionState,
|
||||
} from "./verb-selection";
|
||||
import { mapGen } from "../fp-ps";
|
||||
|
||||
export type VpsReducerAction =
|
||||
| {
|
||||
|
@ -205,13 +203,11 @@ export function vpsReducer(
|
|||
}
|
||||
if (action.type === "set negativity") {
|
||||
if (!vps.verb) return vps;
|
||||
const negative = action.payload === "true";
|
||||
return {
|
||||
...vps,
|
||||
blocks: !negative ? removeHeetsDet(vps.blocks) : vps.blocks,
|
||||
verb: {
|
||||
...vps.verb,
|
||||
negative,
|
||||
negative: action.payload === "true",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -62,23 +62,14 @@ export function isNounOrAdjEntry(
|
|||
}
|
||||
|
||||
export function isInflectableEntry(
|
||||
e: T.Entry | T.DictionaryEntry | T.DictionaryEntryNoFVars | T.Determiner
|
||||
e: T.Entry | T.DictionaryEntry | T.DictionaryEntryNoFVars
|
||||
): e is T.InflectableEntry {
|
||||
if ("entry" in e) {
|
||||
return false;
|
||||
}
|
||||
if (isDeterminer(e)) {
|
||||
return true;
|
||||
}
|
||||
return isNounEntry(e) || isAdjectiveEntry(e) || isNumberEntry(e);
|
||||
}
|
||||
|
||||
export function isDeterminer(
|
||||
e: T.Entry | T.DictionaryEntry | T.Determiner
|
||||
): e is T.Determiner {
|
||||
return "type" in e && e.type === "det";
|
||||
}
|
||||
|
||||
export function isNumberEntry(
|
||||
e: T.Entry | T.DictionaryEntry
|
||||
): e is T.NumberEntry {
|
||||
|
|
51
src/types.ts
51
src/types.ts
|
@ -899,35 +899,13 @@ export type NounSelection = {
|
|||
genStativeComplement?: boolean;
|
||||
adjectives: AdjectiveSelection[];
|
||||
possesor: undefined | PossesorSelection;
|
||||
determiners?: DeterminersSelection;
|
||||
demonstrative: undefined | DemonstrativeSelection;
|
||||
};
|
||||
|
||||
export type DeterminersSelection = {
|
||||
type: "determiners";
|
||||
export type DemonstrativeSelection = {
|
||||
type: "demonstrative";
|
||||
demonstrative: "daa" | "hagha" | "dagha";
|
||||
withNoun: boolean;
|
||||
determiners: DeterminerSelection[];
|
||||
};
|
||||
|
||||
export const determiners = [
|
||||
{ p: "دا", f: "daa", type: "det", demonstrative: true },
|
||||
{ p: "دغه", f: "dágha", type: "det", demonstrative: true },
|
||||
{ p: "هغه", f: "hágha", type: "det", demonstrative: true },
|
||||
{ p: "کوم", f: "koom", type: "det" },
|
||||
{ p: "داسې", f: "dáase", type: "det" },
|
||||
{ p: "دغسې", f: "daghase", type: "det" },
|
||||
{ p: "هسې", f: "hase", type: "det" },
|
||||
{ p: "هغسې", f: "hagháse", type: "det" },
|
||||
{ p: "هر", f: "har", type: "det" },
|
||||
{ p: "ټول", f: "Tol", type: "det" },
|
||||
{ p: "بل", f: "bul", type: "det" },
|
||||
{ p: "هیڅ", f: "heets", type: "det", noInf: true },
|
||||
] as const;
|
||||
|
||||
export type Determiner = (typeof determiners)[number];
|
||||
|
||||
export type DeterminerSelection = {
|
||||
type: "determiner";
|
||||
determiner: Determiner;
|
||||
};
|
||||
|
||||
export type AdverbSelection = {
|
||||
|
@ -992,8 +970,7 @@ export type Rendered<
|
|||
| AdjectiveSelection
|
||||
| SandwichSelection<Sandwich>
|
||||
| ComplementSelection
|
||||
| DeterminersSelection
|
||||
| DeterminerSelection
|
||||
| DemonstrativeSelection
|
||||
| ComplementSelection["selection"]
|
||||
| UnselectedComplementSelection
|
||||
| undefined
|
||||
|
@ -1043,21 +1020,13 @@ export type Rendered<
|
|||
inflected: boolean;
|
||||
person: Person;
|
||||
}
|
||||
: T extends DeterminersSelection
|
||||
: T extends DemonstrativeSelection
|
||||
? {
|
||||
type: "determiners";
|
||||
type: "demonstrative";
|
||||
demonstrative: DemonstrativeSelection["demonstrative"];
|
||||
withNoun: boolean;
|
||||
determiners: Rendered<DeterminerSelection>[];
|
||||
}
|
||||
: T extends DeterminerSelection
|
||||
? {
|
||||
type: "determiner";
|
||||
determiner: DeterminerSelection["determiner"];
|
||||
ps: PsString[];
|
||||
ps: PsString;
|
||||
e: string;
|
||||
inflected: boolean;
|
||||
number: NounNumber;
|
||||
gender: Gender;
|
||||
}
|
||||
: T extends ComplementSelection
|
||||
? {
|
||||
|
@ -1109,7 +1078,7 @@ export type Rendered<
|
|||
shrunken: boolean;
|
||||
np: Rendered<NPSelection>;
|
||||
};
|
||||
determiners?: Rendered<DeterminersSelection>;
|
||||
demonstrative?: Rendered<DemonstrativeSelection>;
|
||||
};
|
||||
|
||||
export type EPSelectionState = {
|
||||
|
|
Loading…
Reference in New Issue