This commit is contained in:
lingdocs 2022-04-26 12:51:25 +05:00
parent fc9dfe0299
commit bbc1187684
10 changed files with 116 additions and 7273 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
"main": "lib/functions/src/index.js",
"dependencies": {
"@google-cloud/storage": "^5.8.1",
"@lingdocs/pashto-inflector": "2.1.9",
"@lingdocs/pashto-inflector": "2.3.1",
"@types/cors": "^2.8.10",
"@types/google-spreadsheet": "^3.0.2",
"cors": "^2.8.5",
@ -35,6 +35,6 @@
},
"private": true,
"peerDependencies": {
"@lingdocs/pashto-inflector": "2.1.9"
"@lingdocs/pashto-inflector": "2.3.1"
}
}

3955
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@
"url": "git@github.com-lingdocs:lingdocs/lingdocs-main.git"
},
"peerDependencies": {
"@lingdocs/pashto-inflector": "2.1.9"
"@lingdocs/pashto-inflector": "2.3.1"
},
"author": "lingdocs.com",
"license": "MIT",
@ -26,7 +26,7 @@
"passport-github2": "^0.1.12",
"passport-google-oauth": "^2.0.0",
"passport-twitter": "^1.0.4",
"@lingdocs/pashto-inflector": "2.1.9"
"@lingdocs/pashto-inflector": "2.3.1"
},
"devDependencies": {
"@types/passport-github2": "^1.2.5",

View File

@ -6,7 +6,7 @@
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2",
"@lingdocs/pashto-inflector": "2.1.9",
"@lingdocs/pashto-inflector": "2.3.1",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
@ -100,6 +100,6 @@
"user-event": "^4.0.0"
},
"peerDependencies": {
"@lingdocs/pashto-inflector": "2.1.9"
"@lingdocs/pashto-inflector": "2.3.1"
}
}

View File

@ -357,55 +357,66 @@ export function allEntries() {
return dictDb.collection.find();
}
export function getNounByTs(ts: number): undefined | T.NounEntry {
const res = dictDb.findOneByTs(ts);
if (!res) return undefined;
return tp.isNounEntry(res) ? res : undefined;
}
export function getVerbByTs(ts: number): undefined | T.VerbEntry {
const entry = dictDb.findOneByTs(ts);
if (!entry) return undefined;
if (!tp.isVerbDictionaryEntry(entry)) {
console.error("not valid verb entry");
return undefined;
function makeLookupPortal<X extends T.DictionaryEntry>(tpFilter: (x: T.DictionaryEntry) => x is X): T.EntryLookupPortal<X> {
return {
search: (s: string) => fuzzyLookup({
searchString: s,
language: "Pashto",
page: 1,
tpFilter,
}),
getByTs: (ts: number) => {
const res = dictDb.findOneByTs(ts);
if (!res) return undefined;
return tpFilter(res) ? res : undefined;
},
}
const complement = (() => {
if (entry.c?.includes("comp") && entry.l) {
const comp = dictDb.findOneByTs(entry.l);
if (!comp) {
console.error("complement not found for", entry);
}
function makeVerbLookupPortal(): T.EntryLookupPortal<T.VerbEntry> {
return {
search: (s: string) => {
const vEntries = fuzzyLookup({
searchString: s,
language: "Pashto",
page: 1,
tpFilter: tp.isVerbDictionaryEntry,
});
return vEntries.map((entry): T.VerbEntry => ({
entry,
complement: (entry.c?.includes("comp.") && entry.l)
? dictionary.findOneByTs(entry.l)
: undefined,
}));
},
getByTs: (ts: number): T.VerbEntry | undefined => {
const entry = dictDb.findOneByTs(ts);
if (!entry) return undefined;
if (!tp.isVerbDictionaryEntry(entry)) {
console.error("not valid verb entry");
return undefined;
}
return comp;
} else {
return undefined;
}
})();
return { entry, complement };
const complement = (() => {
if (entry.c?.includes("comp") && entry.l) {
const comp = dictDb.findOneByTs(entry.l);
if (!comp) {
console.error("complement not found for", entry);
}
return comp;
} else {
return undefined;
}
})();
return { entry, complement };
},
}
}
export function searchNouns(s: string): T.NounEntry[] {
console.log("searching nouns");
return fuzzyLookup({
searchString: s,
language: "Pashto",
page: 1,
tpFilter: tp.isNounEntry,
});
}
export function searchVerbs(s: string): T.VerbEntry[] {
const vEntries = fuzzyLookup({
searchString: s,
language: "Pashto",
page: 1,
tpFilter: tp.isVerbDictionaryEntry,
});
return vEntries.map((entry): T.VerbEntry => ({
entry,
complement: (entry.c?.includes("comp.") && entry.l)
? dictionary.findOneByTs(entry.l)
: undefined,
}));
export const entryFeeder: T.EntryFeeder = {
nouns: makeLookupPortal(tp.isNounEntry),
verbs: makeVerbLookupPortal(),
adjectives: makeLookupPortal(tp.isAdjectiveEntry),
locativeAdverbs: makeLookupPortal(tp.isLocativeAdverbEntry),
}
export const dictionary: DictionaryAPI = {

View File

@ -9,6 +9,8 @@
import { useEffect, useState } from "react";
import classNames from "classnames";
import { Link } from "react-router-dom";
import { VPExplorer } from "@lingdocs/pashto-inflector";
import { entryFeeder } from "../lib/dictionary";
import {
ConjugationViewer,
InflectionsTable,
@ -16,6 +18,7 @@ import {
Types as T,
InlinePs,
validateEntry,
typePredicates,
} from "@lingdocs/pashto-inflector";
import Entry from "../components/Entry";
import * as FT from "../types/functions-types";
@ -338,6 +341,19 @@ function EntryEditor({ isolatedEntry, dictionary, searchParams, textOptions, use
{inf && "plural" in inf && inf.plural !== undefined && <InflectionsTable inf={inf.plural} textOptions={textOptions} />}
{inf && "arabicPlural" in inf && inf.arabicPlural !== undefined && <InflectionsTable inf={inf.arabicPlural} textOptions={textOptions} />}
{/* TODO: aay tail from state options */}
{typePredicates.isVerbEntry({ entry, complement }) && <div className="pb-4">
<VPExplorer
verb={{
// TODO: CLEAN THIS UP!
// @ts-ignore
entry,
complement,
}}
opts={textOptions}
entryFeeder={entryFeeder}
handleLinkClick="none"
/>
</div>}
<ConjugationViewer
entry={entry}
complement={complement}

View File

@ -33,12 +33,7 @@ import AudioPlayButton from "../components/AudioPlayButton";
import { Helmet } from "react-helmet";
import { Modal } from "react-bootstrap";
import { getTextOptions } from "../lib/get-text-options";
import {
searchNouns,
searchVerbs,
getNounByTs,
getVerbByTs,
} from "../lib/dictionary";
import { entryFeeder } from "../lib/dictionary";
function IsolatedEntry({ state, dictionary, isolateEntry }: {
state: State,
@ -214,10 +209,7 @@ function IsolatedEntry({ state, dictionary, isolateEntry }: {
complement,
}}
opts={textOptions}
nouns={searchNouns}
verbs={searchVerbs}
getNounByTs={getNounByTs}
getVerbByTs={getVerbByTs}
entryFeeder={entryFeeder}
handleLinkClick={isolateEntry}
/>
</div>}

View File

@ -1585,10 +1585,10 @@
"@types/yargs" "^16.0.0"
chalk "^4.0.0"
"@lingdocs/pashto-inflector@2.1.9":
version "2.1.9"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.1.9.tgz#a906d118d687e4eafd2f0d91aac0cd80b888b8df"
integrity sha512-r2rh9EWG3GpgXiqEuc52QZTRwXrL61uolZSCEbjnXV+k2kG07JjPmnchQORZfbPmjsx301rzzoywR5Ko+F2qpw==
"@lingdocs/pashto-inflector@2.3.1":
version "2.3.1"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.3.1.tgz#bfb5be4e2d821671389a3224ca704affedf1997d"
integrity sha512-ODJJo8UZFs6hO6rNQYNaxKNsPyeIEeARqRxrMKfwm4G2hdqx5k5CHoSM8fSRXsrne4dAhll+biexlqvSNXNn4w==
dependencies:
classnames "^2.2.6"
pbf "^3.2.1"

View File

@ -168,10 +168,10 @@
"resolved" "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.2.1.tgz"
"version" "9.2.1"
"@lingdocs/pashto-inflector@2.1.9":
"integrity" "sha512-r2rh9EWG3GpgXiqEuc52QZTRwXrL61uolZSCEbjnXV+k2kG07JjPmnchQORZfbPmjsx301rzzoywR5Ko+F2qpw=="
"resolved" "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.1.9.tgz"
"version" "2.1.9"
"@lingdocs/pashto-inflector@2.3.0":
"integrity" "sha512-XWiQqgjS4pEusMQSj6IVoIhmgP2z2I7ZNR1cID1yOJ5yxtEN1V8Hq8vAAGxf+RhvIZ+qTPID6FEtGXxUmQbAjg=="
"resolved" "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.3.0.tgz"
"version" "2.3.0"
dependencies:
"classnames" "^2.2.6"
"pbf" "^3.2.1"