From 2ba678b1ff2f97e61d35496d8d6e9fbc805080a4 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sat, 11 Jun 2022 11:25:28 -0400 Subject: [PATCH] AP and NP block diagrams working --- package.json | 2 +- .../phrase-diagram/EditableExample.tsx | 45 +++++ .../phrase-diagram/EditablePhraseDiagram.tsx | 16 +- .../phrase-diagram/PhraseDiagram.tsx | 179 ++---------------- src/content/phrase-structure/ap.mdx | 136 +++++++------ src/content/phrase-structure/ep.mdx | 3 - src/content/phrase-structure/np.mdx | 108 ++++++----- src/games/sub-cores/EquativeGame.tsx | 42 ++-- src/types/gramm-types.d.ts | 7 - yarn.lock | 8 +- 10 files changed, 238 insertions(+), 308 deletions(-) create mode 100644 src/components/phrase-diagram/EditableExample.tsx diff --git a/package.json b/package.json index 1ae86d9..5c7adb6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@formkit/auto-animate": "^1.0.0-beta.1", "@fortawesome/fontawesome-free": "^5.15.4", "@lingdocs/lingdocs-main": "^0.3.1", - "@lingdocs/pashto-inflector": "^2.6.8", + "@lingdocs/pashto-inflector": "^2.8.2", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/src/components/phrase-diagram/EditableExample.tsx b/src/components/phrase-diagram/EditableExample.tsx new file mode 100644 index 0000000..c554468 --- /dev/null +++ b/src/components/phrase-diagram/EditableExample.tsx @@ -0,0 +1,45 @@ +import { + Types as T, + Examples, + renderEP, + compileEP, + +} from "@lingdocs/pashto-inflector"; +import { completeEPSelection } from "@lingdocs/pashto-inflector/dist/lib/phrase-building/render-ep"; +import { useState } from "react"; +// import EPBlocks from "./EPBlocks"; + +function getShort(i: T.SingleOrLengthOpts): X { + if ("long" in i) { + return i.long; + } + return i; +} + +function EditableExample({ children: eps, opts }: { children: T.EPSelectionState, opts: T.TextOptions }) { + const [mode, setMode] = useState<"example" | "blocks">("example"); + const EPS = completeEPSelection(eps); + if (!EPS) { + return
Error: Invalid/incomplete Phrase
; + } + const rendered = renderEP(EPS); + const compiled = compileEP(rendered); + const text: T.PsString = { + ...getShort(compiled.ps)[0], + e: compiled.e ? compiled.e.join(" / ") : undefined, + }; + return
+
+ {mode === "example" ?
setMode("blocks")}> + +
:
setMode("example")}> + +
} +
+ {/* {mode === "example" + ? {[text]} + : {rendered}} */} +
; +} + +export default EditableExample; \ No newline at end of file diff --git a/src/components/phrase-diagram/EditablePhraseDiagram.tsx b/src/components/phrase-diagram/EditablePhraseDiagram.tsx index 20a13ab..335d2dd 100644 --- a/src/components/phrase-diagram/EditablePhraseDiagram.tsx +++ b/src/components/phrase-diagram/EditablePhraseDiagram.tsx @@ -16,10 +16,17 @@ export function EditIcon() { return ; } +function selectionToBlock(s: T.NPSelection | T.APSelection): { type: "NP", block: T.NPSelection | undefined } | { type: "AP", block: T.APSelection | undefined } { + return (s.type === "AP") + ? { type: "AP", block: s } + : { type: "NP", block: s }; +} + function EditablePhraseDiagram({ opts, children }: { opts: T.TextOptions, - children: BlockInput[], + children: (T.NPSelection | T.APSelection)[], }) { + console.log({ aa: children[0] }) const block = children[0]; const parent = useRef(null); useEffect(() => { @@ -32,8 +39,7 @@ function EditablePhraseDiagram({ opts, children }: { } | { type: "AP", block: T.APSelection | undefined, - }>(block); - console.log({ block }); + }>(selectionToBlock(block)); if (children.length === 0) return null; function handleNPChange(np: T.NPSelection | undefined) { setEdited({ type: "NP", block: np }); @@ -42,7 +48,7 @@ function EditablePhraseDiagram({ opts, children }: { setEdited({ type: "AP", block: ap }); } function handleReset() { - setEdited(block); + setEdited(selectionToBlock(block)); setEditing(false); } return
@@ -76,7 +82,7 @@ function EditablePhraseDiagram({ opts, children }: {
} {edited.block && - {[edited] as BlockInput[]} + {edited.block} } ; diff --git a/src/components/phrase-diagram/PhraseDiagram.tsx b/src/components/phrase-diagram/PhraseDiagram.tsx index 9d0627c..694b10f 100644 --- a/src/components/phrase-diagram/PhraseDiagram.tsx +++ b/src/components/phrase-diagram/PhraseDiagram.tsx @@ -1,182 +1,31 @@ import { renderNPSelection, Types as T, - getEnglishFromRendered, renderAPSelection, + NPBlock, + APBlock, } from "@lingdocs/pashto-inflector"; -import classNames from "classnames"; function PhraseDiagram({ opts, children }: { opts: T.TextOptions, - children: BlockInput[] + children: T.NPSelection | T.APSelection, }) { + try { + const rendered = children.type === "AP" + ? renderAPSelection(children) + : renderNPSelection(children, false, false, "subject", "none"); return
- {children.map((block) => ( - {block} - ))} + {rendered.type === "NP" + ? {rendered} + : {rendered}}
; + } catch(e) { + console.log(e); + return
ERROR
; + } } -function Block({ opts, children }: { - opts: T.TextOptions, - children: BlockInput, -}) { - if (children.type === "NP") { - const rendered = renderNPSelection(children.block, false, false, "subject", "none"); - const english = getEnglishFromRendered(rendered) - return
- {rendered} -
; - } - const rendered = renderAPSelection(children.block); - const english = getEnglishFromRendered(rendered) - return
- {rendered} -
; -} - -function AP({ opts, children, english }: { - opts: T.TextOptions, - children: T.Rendered, - english?: string, -}) { - const ap = children; - if (ap.type === "adverb") { - return
-
- {ap.ps[0].f} -
-
AP
- {english &&
{english}
} -
; - } - return
-
Sandwich 🥪
-
-
- {ap.inside.type !== "pronoun" ? ap.inside.possesor : undefined} -
{ap.before ? ap.before.f : ""}
-
- {ap.inside} -
-
{ap.after ? ap.after.f : ""}
-
-
-
AP
- {english &&
{english}
} -
; -} - -function NP({ opts, children, inside, english }: { - opts: T.TextOptions, - children: T.Rendered, - inside?: boolean, - english?: string, -}) { - const np = children; - const hasPossesor = !!(np.type !== "pronoun" && np.possesor); - return
-
- {!inside && {np.type !== "pronoun" ? np.possesor : undefined}} - {np.adjectives} -
{np.ps[0].f}
-
-
NP
- {english &&
{english}
} -
-} - -function Possesors({ opts, children }: { - opts: T.TextOptions, - children: { shrunken: boolean, np: T.Rendered } | undefined, -}) { - if (!children) { - return null; - } - const contraction = checkForContraction(children.np); - return
- {children.np.type !== "pronoun" && {children.np.possesor}} -
- {contraction &&
({contraction})
} -
-
du
-
- {children.np} -
-
- -
-
-} - -function checkForContraction(np: T.Rendered): string | undefined { - if (np.type !== "pronoun") return undefined; - if (np.person === T.Person.FirstSingMale || np.person === T.Person.FirstSingFemale) { - return "zmaa" - } - if (np.person === T.Person.SecondSingMale || np.person === T.Person.SecondSingFemale) { - return "staa" - } - if (np.person === T.Person.FirstPlurMale || np.person === T.Person.FirstPlurFemale) { - return "zmoonG" - } - if (np.person === T.Person.SecondPlurMale || np.person === T.Person.SecondPlurFemale) { - return "staaso" - } - return undefined; -} - -function Adjectives({ opts, children }: { - opts: T.TextOptions, - children: T.Rendered[] | undefined, -}) { - if (!children) { - return null; - } - return - {children.map(a => a.ps[0].f).join(" ")}{` `} - -} export default PhraseDiagram; \ No newline at end of file diff --git a/src/content/phrase-structure/ap.mdx b/src/content/phrase-structure/ap.mdx index 30fb722..b1c68c4 100644 --- a/src/content/phrase-structure/ap.mdx +++ b/src/content/phrase-structure/ap.mdx @@ -28,7 +28,7 @@ An adverb is a word or expression that modifies the time, manner, place, etc. of {[ { type: "AP", - block: { + selection: { type: "adverb", entry: {"ts":1527815160,"i":2394,"p":"پرون","f":"paroon","g":"paroon","e":"yesterday","c":"adv."}, }, @@ -38,7 +38,7 @@ An adverb is a word or expression that modifies the time, manner, place, etc. of {[ { type: "AP", - block: { + selection: { type: "adverb", entry: {"ts":1527819967,"i":5428,"p":"خامخا","f":"khaamakhaa","g":"khaamakhaa","e":"definitely, for sure, whether someone wants or not, willy-nilly (this last use more in Urdu)","c":"adv."}, }, @@ -54,20 +54,23 @@ These "sandwiches" are also used as an adverb to give more information for the p {[ { type: "AP", - block: { + selection: { type: "sandwich", before: { p: "په", f: "pu" }, after: { p: "کې", f: "ke" }, e: "in", inside: { - type: "noun", - entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, - gender: "masc", - genderCanChange: false, - number: "singular", - numberCanChange: true, - adjectives: [], - possesor: undefined, + type: "NP", + selection: { + type: "noun", + entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, + gender: "masc", + genderCanChange: false, + number: "singular", + numberCanChange: true, + adjectives: [], + possesor: undefined, + }, }, }, }, @@ -78,23 +81,26 @@ Because the inside of a sandwich is an NP{[ { type: "AP", - block: { + selection: { type: "sandwich", before: { p: "په", f: "pu" }, after: { p: "کې", f: "ke" }, e: "in", inside: { - type: "noun", - entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, - gender: "masc", - genderCanChange: false, - number: "singular", - numberCanChange: true, - adjectives: [{ - type: "adjective", - entry: {"ts":1527812625,"i":9128,"p":"غټ","f":"ghuT, ghaT","g":"ghuT,ghaT","e":"big, fat","c":"adj."}, - }], - possesor: undefined, + type: "NP", + selection: { + type: "noun", + entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, + gender: "masc", + genderCanChange: false, + number: "singular", + numberCanChange: true, + adjectives: [{ + type: "adjective", + entry: {"ts":1527812625,"i":9128,"p":"غټ","f":"ghuT, ghaT","g":"ghuT,ghaT","e":"big, fat","c":"adj."}, + }], + possesor: undefined, + }, }, }, }, @@ -105,33 +111,39 @@ We can also add a possesor it hangs outside of the sandwich. All together it's s {[ { type: "AP", - block: { + selection: { type: "sandwich", before: { p: "په", f: "pu" }, after: { p: "کې", f: "ke" }, e: "in", inside: { - type: "noun", - entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, - gender: "masc", - genderCanChange: false, - number: "singular", - numberCanChange: true, - adjectives: [{ - type: "adjective", - entry: {"ts":1527812625,"i":9128,"p":"غټ","f":"ghuT, ghaT","g":"ghuT,ghaT","e":"big, fat","c":"adj."}, - }], - possesor: { - shrunken: false, - np: { - type: "noun", - entry: {"ts":1527815251,"i":7802,"p":"سړی","f":"saRéy","g":"saRey","e":"man","c":"n. m.","ec":"man","ep":"men"}, - gender: "masc", - genderCanChange: false, - number: "singular", - numberCanChange: true, - adjectives: [], - possesor: undefined, + type: "NP", + selection: { + type: "noun", + entry: {"ts":1527812828,"i":10539,"p":"کور","f":"kor","g":"kor","e":"house, home","c":"n. m."}, + gender: "masc", + genderCanChange: false, + number: "singular", + numberCanChange: true, + adjectives: [{ + type: "adjective", + entry: {"ts":1527812625,"i":9128,"p":"غټ","f":"ghuT, ghaT","g":"ghuT,ghaT","e":"big, fat","c":"adj."}, + }], + possesor: { + shrunken: false, + np: { + type: "NP", + selection: { + type: "noun", + entry: {"ts":1527815251,"i":7802,"p":"سړی","f":"saRéy","g":"saRey","e":"man","c":"n. m.","ec":"man","ep":"men"}, + gender: "masc", + genderCanChange: false, + number: "singular", + numberCanChange: true, + adjectives: [], + possesor: undefined, + }, + }, }, }, }, @@ -144,25 +156,31 @@ Here's another example using the sandwich {[ { type: "AP", - block: { + selection: { type: "sandwich", before: { p: "له", f: "la" }, after: { p: "سره", f: "sara" }, e: "with", inside: { - type: "noun", - entry: {"ts":1527814159,"i":12723,"p":"ملګری","f":"malgúrey","g":"malgurey","e":"friend, companion","c":"n. m. anim. unisex"}, - gender: "masc", - genderCanChange: true, - number: "singular", - numberCanChange: true, - adjectives: [], - possesor: { - shrunken: false, - np: { - type: "pronoun", - distance: "far", - person: 0, + type: "NP", + selection: { + type: "noun", + entry: {"ts":1527814159,"i":12723,"p":"ملګری","f":"malgúrey","g":"malgurey","e":"friend, companion","c":"n. m. anim. unisex"}, + gender: "masc", + genderCanChange: true, + number: "singular", + numberCanChange: true, + adjectives: [], + possesor: { + shrunken: false, + np: { + type: "NP", + selection: { + type: "pronoun", + distance: "far", + person: 0, + }, + }, }, }, }, diff --git a/src/content/phrase-structure/ep.mdx b/src/content/phrase-structure/ep.mdx index 3b6d0c7..ccec6a5 100644 --- a/src/content/phrase-structure/ep.mdx +++ b/src/content/phrase-structure/ep.mdx @@ -10,9 +10,6 @@ import { } from "@lingdocs/pashto-inflector"; import psmd from "../../lib/psmd"; import Link from "../../components/Link"; -import EditablePhraseDiagram, { - EditIcon, -} from "../../components/phrase-diagram/EditablePhraseDiagram"; import EquativeIllustration from "../../components/EquativeIllustration"; import BasicBlocks from "../../components/BasicBlocks" diff --git a/src/content/phrase-structure/np.mdx b/src/content/phrase-structure/np.mdx index 0331758..4aae014 100644 --- a/src/content/phrase-structure/np.mdx +++ b/src/content/phrase-structure/np.mdx @@ -40,7 +40,7 @@ A **noun** is a word that we use to identify people, places, things, or ideas. O {[ { type: "NP", - block: { + selection: { type: "noun", entry: {"ts":1527812817,"i":9999,"p":"کتاب","f":"kitáab","g":"kitaab","e":"book","c":"n. m."}, gender: "masc", @@ -58,7 +58,7 @@ We can also **extend our noun by adding *adjectives***. Let's add the *adjective {[ { type: "NP", - block: { + selection: { type: "noun", entry: {"ts":1527812817,"i":9999,"p":"کتاب","f":"kitáab","g":"kitaab","e":"book","c":"n. m."}, gender: "masc", @@ -70,7 +70,7 @@ We can also **extend our noun by adding *adjectives***. Let's add the *adjective entry: {"ts":1527815451,"i":7245,"p":"زوړ","f":"zoR","g":"zoR","e":"old","c":"adj. irreg.","infap":"زاړه","infaf":"zaaRu","infbp":"زړ","infbf":"zaR"}, }], possesor: undefined, - }, + } }, ]} @@ -79,7 +79,7 @@ Now we have two words, but it's still **one NP**, one building block. We can add {[ { type: "NP", - block: { + selection: { type: "noun", entry: {"ts":1527812817,"i":9999,"p":"کتاب","f":"kitáab","g":"kitaab","e":"book","c":"n. m."}, gender: "masc", @@ -101,7 +101,7 @@ Now we have two words, but it's still **one NP**, one building block. We can add }, ], possesor: undefined, - }, + } }, ]} @@ -110,7 +110,7 @@ We can also add a **possesor** by adding another NP {[ { type: "NP", - block: { + selection: { type: "noun", entry: {"ts":1527812817,"i":9999,"p":"کتاب","f":"kitáab","g":"kitaab","e":"book","c":"n. m."}, gender: "masc", @@ -160,23 +163,29 @@ If our possesor is a noun, we can add a possesor to *it*. Try clicking the {[ { type: "NP", - block: { + selection: { type: "pronoun", person: 0, distance: "far", - }, + } }, ]} {[ + {type: "NP", selection: { - type: "NP", - block: { type: "pronoun", person: 11, distance: "far", - }, - }, + }}, ]} ### Participle @@ -235,12 +242,12 @@ In Pashto you can use the infinitive form of a verb as a participle, meaning you {[ { type: "NP", - block: { + selection: { type: "participle", verb: { entry: {"ts":1527812856,"i":11617,"p":"لیکل","f":"leekul","g":"leekul","e":"to write","c":"v. trans./gramm. trans.","ec":"write,writes,writing,wrote,written"}, }, - }, + } }, ]} @@ -291,12 +298,12 @@ For example, if we take the participle {[ { type: "NP", - block: { + selection: { type: "participle", verb: { entry: {"ts":1527815399,"i":14463,"p":"وهل","f":"wahul","g":"wahul","e":"to hit","c":"v. trans.","tppp":"واهه","tppf":"waahu","ec":"hit,hits,hitting,hit,hit"}, }, - }, + } }, ]} @@ -305,7 +312,7 @@ And we can add the word {[ { type: "NP", - block: { + selection: { type: "participle", verb: { entry: {"ts":1527815399,"i":14463,"p":"وهل","f":"wahul","g":"wahul","e":"to hit","c":"v. trans.","tppp":"واهه","tppf":"waahu","ec":"hit,hits,hitting,hit,hit"}, @@ -313,13 +320,16 @@ And we can add the word x.type === "equative"); + if (!eblock || eblock.type !== "equative") throw new Error("Error getting equative block"); + return eblock.equative; } \ No newline at end of file diff --git a/src/types/gramm-types.d.ts b/src/types/gramm-types.d.ts index 36ee08d..a355137 100644 --- a/src/types/gramm-types.d.ts +++ b/src/types/gramm-types.d.ts @@ -4,10 +4,3 @@ type Pronoun = { person: import("@lingdocs/pashto-inflector").Types.Person, }; -type BlockInput = { - type: "NP", - block: import("@lingdocs/pashto-inflector").Types.NPSelection, -} | { - type: "AP", - block: import("@lingdocs/pashto-inflector").Types.APSelection, -}; diff --git a/yarn.lock b/yarn.lock index 964370e..2373852 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1695,10 +1695,10 @@ rambda "^6.7.0" react-select "^5.2.2" -"@lingdocs/pashto-inflector@^2.6.8": - version "2.6.8" - resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.8.tgz#d104620a75a4f034d3dcd9d8a097eab40b77024d" - integrity sha512-z2RetX9mRgZxM0FIX8R3cgCF+Exof/OigMDZIlEHLhBAljSwaojA9ZdXnyKP1zW8EDtjLIqsr3rWQre6niU80w== +"@lingdocs/pashto-inflector@^2.8.2": + version "2.8.2" + resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.8.2.tgz#006f1f3f8223f5ea67ac75106369c3f6072441a3" + integrity sha512-mA9L37+Tq5teDTxczjfIBMfOStfqAzn7QFUNoRSEXl7ci4Yo+5bomHf2sjGDr0ZbneFAyp0K05tVJCWi8SBkeg== dependencies: "@formkit/auto-animate" "^1.0.0-beta.1" classnames "^2.2.6"