fix phrase bugs and expose renderAP

This commit is contained in:
lingdocs 2022-05-26 15:01:25 -05:00
parent fdf8714207
commit e3b3b9f2b6
8 changed files with 34 additions and 27 deletions

View File

@ -24,7 +24,6 @@
},
"dependencies": {
"@formkit/auto-animate": "^1.0.0-beta.1",
"assert-never": "^1.2.1",
"classnames": "^2.2.6",
"jsurl2": "^2.1.0",
"lz-string": "^1.4.4",

View File

@ -279,7 +279,7 @@ function App() {
opts={textOptions}
/>
</div>}
<h4>🆕 Equative Phrase Builder</h4>
<h4>Equative Phrase Builder</h4>
<EPExplorer
opts={textOptions}
entryFeeder={entryFeeder}

View File

@ -401,7 +401,8 @@ function compileEnglishEP(EP: T.EPRendered): string[] | undefined {
function insertEWords(e: string, { subject, predicate, APs }: { subject: string, predicate: string, APs: string }): string {
return e.replace("$SUBJ", subject).replace("$PRED", predicate || "") + APs;
}
const engSubj = getRenderedSubjectSelection(EP.blocks).selection.e;
const engSubjR = getRenderedSubjectSelection(EP.blocks).selection;
const engSubj = getEnglishFromRendered(engSubjR);
const engPred = getEnglishFromRendered(EP.predicate);
const engAPs = getEnglishAPs(EP.blocks);
// require all English parts for making the English phrase
@ -559,10 +560,11 @@ export function findPossesivesToShrinkInEP(EP: T.EPRendered): FoundNP[] {
? []
: (EP.predicate.type === "adjective")
? findPossesivesInAdjective(EP.predicate)
: findPossesivesInNP(
// @ts-ignore - ts being dumb
EP.predicate as T.NPSelection
)).map(np => ({ np, from: "predicate" }));
: EP.predicate.type === "sandwich"
? findPossesivesInNP(EP.predicate.inside)
: EP.predicate.type === "pronoun"
? []
: findPossesivesInNP(EP.predicate)).map(np => ({ np, from: "predicate" }));
return [
...inBlocks,
...inPredicate,

View File

@ -201,12 +201,13 @@ export function getEnglishFromRendered(r: T.Rendered<T.NPSelection | T.EqCompSel
if (r.type === "adjective") {
return getEnglishFromRenderedAdjective(r);
}
if (r.type !== "pronoun") {
// TODO: shouldn't have to do this 'as' - should be automatically narrowing
const np = r as T.Rendered<T.NounSelection>;
return addPossesors(np.possesor?.np, addArticlesAndAdjs(np), r.type);
if (r.type === "pronoun") {
return r.e;
}
return r.e;
if (r.type === "participle") {
return addPossesors(r.possesor?.np, r.e, r.type);
}
return addPossesors(r.possesor?.np, addArticlesAndAdjs(r), r.type);
}
function getEnglishFromRenderedSandwich(r: T.Rendered<T.SandwichSelection<T.Sandwich>>): string | undefined {

View File

@ -0,0 +1,12 @@
import * as T from "../../types";
import { renderAdverbSelection } from "./render-ep";
import { renderSandwich } from "./render-sandwich";
export function renderAP(ap: T.APSelection): T.Rendered<T.APSelection> {
if (ap.type === "sandwich") {
return renderSandwich(ap);
}
// if (ap.type === "adverb") {
return renderAdverbSelection(ap);
// }
}

View File

@ -23,8 +23,7 @@ import { renderEnglishVPBase } from "./english-vp-rendering";
import { personGender } from "../../lib/misc-helpers";
import { renderNPSelection } from "./render-np";
import { getObjectSelection, getSubjectSelection } from "./blocks-utils";
import { renderSandwich } from "./render-sandwich";
import { renderAdverbSelection } from "./render-ep";
import { renderAP } from "./render-ap";
// TODO: ISSUE GETTING SPLIT HEAD NOT MATCHING WITH FUTURE VERBS
@ -78,26 +77,21 @@ function renderVPBlocks(blocks: T.VPSBlockComplete[], config: {
king: "subject" | "object",
}): T.RenderedVPSBlock[] {
return blocks.map(({ block }): T.RenderedVPSBlock => {
if (block.type === "sandwich") {
return renderSandwich(block);
}
if (block.type === "adverb") {
return renderAdverbSelection(block);
}
if (block.type === "subjectSelection") {
return {
type: "subjectSelection",
selection: renderNPSelection(block.selection, config.inflectSubject, false, "subject", config.king === "subject" ? "king" : "servant"),
}
}
// if (block.type === "objectSelection") {
if (block.type === "objectSelection") {
const object = typeof block === "object" ? block.selection : block;
const selection = renderNPSelection(object, config.inflectObject, true, "object", config.king === "object" ? "king" : "servant");
return {
type: "objectSelection",
selection,
};
// }
}
return renderAP(block);
});
}

View File

@ -143,6 +143,9 @@ import {
compileEP,
compileVP,
} from "./lib/phrase-building/compile";
import {
renderAP,
} from "./lib/phrase-building/render-ap";
import NPPicker from "./components/np-picker/NPPicker";
import EPExplorer from "./components/ep-explorer/EPExplorer";
import shuffleArray from "./lib/shuffle-array";
@ -219,6 +222,7 @@ export {
renderNPSelection,
getEnglishFromRendered,
getPashtoFromRendered,
renderAP,
// protobuf helpers
readDictionary,
writeDictionary,

View File

@ -2762,11 +2762,6 @@ asn1.js@^5.2.0:
minimalistic-assert "^1.0.0"
safer-buffer "^2.1.0"
assert-never@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/assert-never/-/assert-never-1.2.1.tgz#11f0e363bf146205fb08193b5c7b90f4d1cf44fe"
integrity sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw==
assert@^1.1.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/assert/-/assert-1.5.0.tgz#55c109aaf6e0aefdb3dc4b71240c70bf574b18eb"