From ad0538c737091628af24e8be93ad25ef9a7ddb33 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Mon, 29 Aug 2022 17:47:51 +0400 Subject: [PATCH] humanReadableTense --- package.json | 2 +- src/lib/human-readable.ts | 65 +++++++++++++++++++++++++++++++++++++++ src/library.ts | 2 ++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/lib/human-readable.ts diff --git a/package.json b/package.json index f43917f..2e490c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "3.8.0", + "version": "3.8.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", diff --git a/src/lib/human-readable.ts b/src/lib/human-readable.ts new file mode 100644 index 0000000..dddbd9b --- /dev/null +++ b/src/lib/human-readable.ts @@ -0,0 +1,65 @@ +import * as T from "../types"; +import { + isModalTense, + isPerfectTense, + isImperativeTense, +} from "./type-predicates"; + +function humanReadableVerbTense(tense: T.VerbTense): string { + return tense === "presentVerb" + ? "present" + : tense === "subjunctiveVerb" + ? "subjunctive" + : tense === "imperfectiveFuture" + ? "imperfective future" + : tense === "perfectiveFuture" + ? "perfective future" + : tense === "perfectivePast" + ? "simple past" + : tense === "imperfectivePast" + ? "continuous past" + : tense === "habitualImperfectivePast" + ? "habitual simple past" + // : tense === "habitualPerfectivePast" + : "habitual continuous past"; +} + +function humanReadableModalTense(tense: T.ModalTense): string { + const base = tense.replace("Modal", "") as T.VerbTense; + return `${humanReadableVerbTense(base)} ability`; +} + +function humanReadablePerfectTense(tense: T.PerfectTense): string { + return tense === "pastPerfect" + ? "past perfect" + : tense === "futurePerfect" + ? "future perfect" + : tense === "presentPerfect" + ? "present perfect" + : tense === "habitualPerfect" + ? "habitual perfect" + : tense === "subjunctivePerfect" + ? "subjunctive perfect" + : tense === "pastSubjunctivePerfect" + ? "past subjunctive perfect" + : tense === "wouldBePerfect" + ? `"would be" perfect` + // : tense === "wouldHaveBeenPerfect" + : `"would have been" perfect` +} + +function humanReadableImperativeTense(tense: T.ImperativeTense): string { + return tense === "imperfectiveImperative" + ? "imperfective imperative" + : "perfective imperative"; +} + +export function humanReadableTense(tense: T.VerbTense | T.PerfectTense | T.ModalTense | T.ImperativeTense): string { + return isModalTense(tense) + ? humanReadableModalTense(tense) + : isPerfectTense(tense) + ? humanReadablePerfectTense(tense) + : isImperativeTense(tense) + ? humanReadableImperativeTense(tense as T.ImperativeTense) + : humanReadableVerbTense(tense); +} \ No newline at end of file diff --git a/src/library.ts b/src/library.ts index b2c4818..8af94a4 100644 --- a/src/library.ts +++ b/src/library.ts @@ -157,6 +157,7 @@ import { import { renderAPSelection, } from "./lib/phrase-building/render-ap"; +import { humanReadableTense } from "./lib/human-readable"; import NPPicker from "./components/np-picker/NPPicker"; import EPPicker from "./components/ep-explorer/EPPicker"; import EPExplorer from "./components/ep-explorer/EPExplorer"; @@ -243,6 +244,7 @@ export { getPashtoFromRendered, renderAPSelection, getEnglishVerb, + humanReadableTense, roleIcon, vpsReducer, makeVPSelectionState,