fix up phrase builder, accent issue, and issue w catorgorize skipping the loc. adv. etc

This commit is contained in:
adueck 2022-09-23 12:12:07 +04:00
parent 9236bad240
commit c6ef12b451
14 changed files with 120 additions and 89 deletions

View File

@ -1,16 +0,0 @@
import {
Types as T,
EPExplorer,
} from "@lingdocs/pashto-inflector";
import entryFeeder from "../lib/entry-feeder";
function EPBuilder({ opts }: { opts: T.TextOptions }) {
return <div className="mb-4">
<EPExplorer
entryFeeder={entryFeeder}
opts={opts}
/>
</div>;
}
export default EPBuilder;

View File

@ -0,0 +1,76 @@
import { useStickyState } from "@lingdocs/pashto-inflector";
import {
Types as T,
ButtonSelect,
EPExplorer,
defaultTextOptions as opts,
EntrySelect,
VPExplorer,
} from "@lingdocs/pashto-inflector";
import { useEffect } from "react";
import entryFeeder from "../lib/entry-feeder";
function PhraseBuilder() {
const [type, setType] = useStickyState<"EP" | "VP">("VP", "phraseBuilderType");
const [entry, setEntry] = useStickyState<T.VerbEntry | undefined>(
undefined,
"vEntrySelect",
);
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const vp = params.get("vp");
const ep = params.get("ep");
if (vp) {
setType("VP");
} else if (ep) {
setType("EP");
}
}, [setType]);
return <div style={{ maxWidth: "1250px", margin: "0 auto 200px auto" }}>
<div className="text-center mb-3 mt-3">
<ButtonSelect
options={[
{ label: "Verb Phrase", value: "VP" },
{ label: "Equative Phrase", value: "EP" },
]}
value={type}
handleChange={setType}
/>
</div>
{type === "EP" ? <div>
<h3 className="mb-4">Equative Phrase Builder</h3>
<EPExplorer
opts={opts}
entryFeeder={entryFeeder}
/>
</div>
: <div>
<h3 className="mb-4">Verb Phrase Builder</h3>
<div style={{ maxWidth: "300px" }}>
<div className="h5">Verb:</div>
<EntrySelect
value={entry}
onChange={setEntry}
entryFeeder={entryFeeder.verbs}
opts={opts}
isVerbSelect
name="Verb"
/>
</div>
<div style={{ margin: "0 auto" }}>
{entry
? <VPExplorer
verb={entry}
opts={opts}
entryFeeder={entryFeeder}
handleLinkClick="none"
/>
: <div className="lead">
Choose a verb to start building
</div>}
</div>
</div>}
</div>
}
export default PhraseBuilder;

View File

@ -1,40 +0,0 @@
import {
defaultTextOptions,
VPExplorer,
EntrySelect,
Types as T,
} from "@lingdocs/pashto-inflector";
import { useStickyState } from "@lingdocs/pashto-inflector";
import entryFeeder from "../lib/entry-feeder";
function VPBuilder() {
const [entry, setEntry] = useStickyState<T.VerbEntry | undefined>(undefined, "vEntrySelect");
return <div>
<div style={{ maxWidth: "300px" }}>
<div className="h5">Verb:</div>
<EntrySelect
value={entry}
onChange={setEntry}
entryFeeder={entryFeeder.verbs}
opts={defaultTextOptions}
isVerbSelect
name="Verb"
/>
</div>
<div style={{ margin: "0 auto" }}>
{entry
? <VPExplorer
verb={entry}
opts={defaultTextOptions}
entryFeeder={entryFeeder}
handleLinkClick="none"
/>
: <div className="lead">
Choose a verb to start building
</div>}
</div>
</div>;
}
export default VPBuilder;

View File

@ -1,11 +0,0 @@
---
title: Equative Explorer 🌎
fullWidth: true
---
import {
defaultTextOptions,
} from "@lingdocs/pashto-inflector";
import EPBuilder from "../../components/EPBuilder";
<EPBuilder opts={defaultTextOptions} />

View File

@ -557,3 +557,7 @@ This is used to talk about:
<h5>8. <Link to="/equatives/other-equatives/#would-have-been-equative">"Would have been" Equative</Link></h5> <h5>8. <Link to="/equatives/other-equatives/#would-have-been-equative">"Would have been" Equative</Link></h5>
- (given some hypothetical condition) A would have been B - (given some hypothetical condition) A would have been B
<hr />
You can explore how all the equatives by browsing the charts and building equative phrases in the <Link to="/phrase-builder">phrase builder</Link>.

View File

@ -16,8 +16,6 @@ import * as presentEquative from "!babel-loader!@lingdocs/mdx-loader!./equatives
import * as habitualEquative from "!babel-loader!@lingdocs/mdx-loader!./equatives/habitual-equative.mdx"; import * as habitualEquative from "!babel-loader!@lingdocs/mdx-loader!./equatives/habitual-equative.mdx";
// @ts-ignore // @ts-ignore
import * as otherEquatives from "!babel-loader!@lingdocs/mdx-loader!./equatives/other-equatives.mdx"; import * as otherEquatives from "!babel-loader!@lingdocs/mdx-loader!./equatives/other-equatives.mdx";
// @ts-ignore
import * as equativeExplorer from "!babel-loader!@lingdocs/mdx-loader!./equatives/equative-explorer.mdx";
// @ts-ignore // @ts-ignore
import * as nounsGender from "!babel-loader!@lingdocs/mdx-loader!./nouns/nouns-gender.mdx"; import * as nounsGender from "!babel-loader!@lingdocs/mdx-loader!./nouns/nouns-gender.mdx";
@ -123,7 +121,7 @@ import * as games from "!babel-loader!@lingdocs/mdx-loader!./games.mdx";
// @ts-ignore // @ts-ignore
import * as pronounPicker from "!babel-loader!@lingdocs/mdx-loader!./practice-tools/pronoun-picker.mdx"; import * as pronounPicker from "!babel-loader!@lingdocs/mdx-loader!./practice-tools/pronoun-picker.mdx";
// @ts-ignore // @ts-ignore
import * as phraseBuilder from "!babel-loader!@lingdocs/mdx-loader!./practice-tools/phrase-builder.mdx"; import * as phraseBuilder from "!babel-loader!@lingdocs/mdx-loader!./phrase-builder.mdx";
type ChapterSection = { type ChapterSection = {
import: any, import: any,
@ -144,6 +142,10 @@ const contentTree: (ChapterSection | ChaptersSection)[] = [
import: games, import: games,
slug: "games", slug: "games",
}, },
{
import: phraseBuilder,
slug: "phrase-builder",
},
{ {
heading: "Equatives", heading: "Equatives",
subdirectory: "equatives", subdirectory: "equatives",
@ -160,10 +162,6 @@ const contentTree: (ChapterSection | ChaptersSection)[] = [
import: otherEquatives, import: otherEquatives,
slug: "other-equatives", slug: "other-equatives",
}, },
{
import: equativeExplorer,
slug: "equative-explorer",
},
], ],
}, },
{ {

View File

@ -0,0 +1,12 @@
---
title: Phrase Builder
fullWidth: true
---
import PhraseBuilder from "../components/PhraseBuilder";
<p className="small mb-4">To build phrases with a full dictionary of words, see the phrase builder included in the <a href="https://dictionary.lingdocs.com">LingDocs Pashto Dictionary</a>.</p>
<hr />
<PhraseBuilder />

View File

@ -1,8 +0,0 @@
---
title: Phrase Builder
fullWidth: true
---
import VPBuilder from "../../components/VPBuilder";
<VPBuilder />

View File

@ -62,15 +62,16 @@ export function categorize<I, X extends Record<string, I[]>>(
// go through each item in the array and add it to the category based on // go through each item in the array and add it to the category based on
// the first predicate it matches // the first predicate it matches
arr.forEach((item) => { arr.forEach((item) => {
let placed: boolean = false;
for (const p of Object.keys(preds)) { for (const p of Object.keys(preds)) {
// @ts-ignore // @ts-ignore
if ((preds[p] !== "leftovers") && preds[p](item)) { if ((preds[p] !== "leftovers") && preds[p](item)) {
o[p].push(item); o[p].push(item);
return; placed = true;
} }
} }
// doesn't fit a predicate, add it to the leftovers // doesn't fit a predicate, add it to the leftovers
if (leftoverKey) { if (!placed && leftoverKey) {
o[leftoverKey].push(item); o[leftoverKey].push(item);
} }
}); });

View File

@ -7,6 +7,8 @@ import {
adverbs, adverbs,
} from "../words/words"; } from "../words/words";
console.log({ locativeAdverbs });
const entryFeeder: T.EntryFeeder = { const entryFeeder: T.EntryFeeder = {
nouns, nouns,
verbs, verbs,

View File

@ -6,6 +6,7 @@ import {
standardizePhonetics, standardizePhonetics,
flattenLengths, flattenLengths,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import { removeAShort } from "./misc-helpers";
export function getPercentageDone(current: number, total: number): number { export function getPercentageDone(current: number, total: number): number {
return Math.round( return Math.round(
@ -22,12 +23,14 @@ export function getPercentageDone(current: number, total: number): number {
* @param answer - the correct answer in phonetics * @param answer - the correct answer in phonetics
*/ */
export function compareF(input: string, answer: string): boolean { export function compareF(input: string, answer: string): boolean {
return input === (hasAccents(input) ? answer : removeAccents(answer)); const inp = removeAShort(input);
const ans = removeAShort(answer);
return inp === (hasAccents(inp) ? ans : removeAccents(ans));
} }
export function comparePs(input: string, answer: T.SingleOrLengthOpts<T.PsString | T.PsString[]>): boolean { export function comparePs(input: string, answer: T.SingleOrLengthOpts<T.PsString | T.PsString[]>): boolean {
if ("long" in answer) { if ("long" in answer) {
return comparePs(input, flattenLengths(answer)) return comparePs(input, flattenLengths(answer));
} }
if (Array.isArray(answer)) { if (Array.isArray(answer)) {
return answer.some(a => comparePs(input, a)); return answer.some(a => comparePs(input, a));

6
src/lib/misc-helpers.ts Normal file
View File

@ -0,0 +1,6 @@
/**
* Removes ă and replaces with a
*/
export function removeAShort(s: string): string {
return s.replace(/ă/g, "a");
}

View File

@ -33,7 +33,7 @@ const content: {
title: "Experiment with the Phrase Builder 🧪", title: "Experiment with the Phrase Builder 🧪",
subTitle: "Interactive Phrase Structure Analysis", subTitle: "Interactive Phrase Structure Analysis",
description: "Build your own phrases in the interactive phrase builder. See how the words change and interact as you explore different tenses and forms.", description: "Build your own phrases in the interactive phrase builder. See how the words change and interact as you explore different tenses and forms.",
link: "/practice-tools/phrase-builder/", link: "/phrase-builder/",
linkDescription: "Phrase Builder", linkDescription: "Phrase Builder",
}, },
]; ];

View File

@ -6,6 +6,7 @@ import {
Types as T, Types as T,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import { categorize } from "../lib/categorize"; import { categorize } from "../lib/categorize";
import { removeAShort } from "../lib/misc-helpers";
// TODO: BIG ISSUE WITH THE LOC ADVERBS BEING LUMPED INTO THE ADVERBS! // TODO: BIG ISSUE WITH THE LOC ADVERBS BEING LUMPED INTO THE ADVERBS!
@ -36,6 +37,9 @@ export function wordQuery(
category: "nouns" | "adjectives" | "adverbs" | "locativeAdverbs" | "verbs", category: "nouns" | "adjectives" | "adverbs" | "locativeAdverbs" | "verbs",
w: string[], w: string[],
): T.NounEntry[] | T.AdjectiveEntry[] | T.AdverbEntry[] | T.LocativeAdverbEntry[] | T.VerbEntry[] { ): T.NounEntry[] | T.AdjectiveEntry[] | T.AdverbEntry[] | T.LocativeAdverbEntry[] | T.VerbEntry[] {
function queryRemoveAccents(s: string): string {
return removeAShort(removeAccents(s));
}
if (category === "verbs") { if (category === "verbs") {
return w.map(word => { return w.map(word => {
const l = words[category]; const l = words[category];
@ -46,11 +50,11 @@ export function wordQuery(
} }
function vMatches(x: T.VerbEntry, y: string) { function vMatches(x: T.VerbEntry, y: string) {
return (y === x.entry.p) return (y === x.entry.p)
|| (removeAccents(y) === removeAccents(removeFVarients(x.entry.f))); || (queryRemoveAccents(y) === queryRemoveAccents(removeFVarients(x.entry.f)));
} }
function wMatches(x: T.DictionaryEntry, y: string) { function wMatches(x: T.DictionaryEntry, y: string) {
return (y === x.p) return (y === x.p)
|| (removeAccents(y) === removeAccents(removeFVarients(x.f))); || (queryRemoveAccents(y) === queryRemoveAccents(removeFVarients(x.f)));
} }
return w.map(word => { return w.map(word => {
const l = words[category]; const l = words[category];