-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
343 additions
and
184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as T from "../../../types"; | ||
import { endsWith, psStringFromEntry } from "../p-text-helpers"; | ||
import { isPattern1Entry } from "../type-predicates"; | ||
import { accentOnNFromEnd, countSyllables } from "../accent-helpers"; | ||
import { monoidPsString } from "../fp-ps"; | ||
import { concatAll } from "fp-ts/lib/Monoid"; | ||
|
||
export function mayoOnWord( | ||
isMayoSandwich: "req" | "opt" | "no" | undefined, | ||
entry: T.InflectableEntry, | ||
gender: T.Gender, | ||
number: T.NounNumber | ||
): "req" | "opt" | "no" { | ||
return isMayoSandwich && | ||
isMayoSandwich !== "no" && | ||
isPattern1Entry(entry) && | ||
number === "singular" && | ||
gender === "masc" && | ||
!endsWith(entry, { p: "ه", f: "u" }) | ||
? isMayoSandwich | ||
: "no"; | ||
} | ||
|
||
export function addMayo(entry: T.InflectableEntry, req: boolean): T.PsString[] { | ||
const base = psStringFromEntry(entry); | ||
const ps1 = concatAll(monoidPsString)([base, { p: "ه", f: "a" }]); | ||
const ps = countSyllables(base) === 1 ? accentOnNFromEnd(ps1, 1) : ps1; | ||
return [ps, ...(!req ? [base] : [])]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,85 @@ | ||
import * as T from "../../../types"; | ||
import { inflectWord } from "../pashto-inflector"; | ||
import { | ||
psStringFromEntry, | ||
isUnisexSet, | ||
} from "../p-text-helpers"; | ||
import { psStringFromEntry, isUnisexSet } from "../p-text-helpers"; | ||
import { getEnglishWord } from "../get-english-word"; | ||
import { | ||
personGender, | ||
personIsPlural, | ||
} from "../misc-helpers"; | ||
import { personGender, personIsPlural } from "../misc-helpers"; | ||
import { renderSandwich } from "./render-sandwich"; | ||
import { isPattern1Entry } from "../type-predicates"; | ||
import { addMayo, mayoOnWord } from "./mayo-utils"; | ||
|
||
function chooseInflection(inflections: T.UnisexSet<T.InflectionSet>, pers: T.Person, inflected?: boolean): T.ArrayOneOrMore<T.PsString> { | ||
const gender = personGender(pers); | ||
const plural = personIsPlural(pers); | ||
const infNumber = (plural ? 1 : 0) + (inflected ? 1 : 0); | ||
return inflections[gender][infNumber]; | ||
function chooseInflection( | ||
inflections: T.UnisexSet<T.InflectionSet>, | ||
pers: T.Person, | ||
inflected?: boolean | ||
): T.ArrayOneOrMore<T.PsString> { | ||
const gender = personGender(pers); | ||
const plural = personIsPlural(pers); | ||
const infNumber = (plural ? 1 : 0) + (inflected ? 1 : 0); | ||
return inflections[gender][infNumber]; | ||
} | ||
|
||
export function inflectAdvAdj(a: T.AdjectiveSelection | T.AdverbSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> { | ||
const infs = inflectWord(a.entry); | ||
if (!infs) { | ||
return [psStringFromEntry(a.entry)]; | ||
} | ||
if (!infs.inflections || !isUnisexSet(infs.inflections)) { | ||
throw new Error("error getting inflections for adjective, looks like a noun's inflections"); | ||
} | ||
return chooseInflection(infs.inflections, person, inflected); | ||
export function inflectAdvAdj( | ||
a: T.AdjectiveSelection | T.AdverbSelection, | ||
person: T.Person, | ||
inflected: boolean, | ||
mayo: "req" | "opt" | "no" | ||
): T.ArrayOneOrMore<T.PsString> { | ||
if (mayo !== "no") { | ||
return addMayo(a.entry, mayo === "req") as T.ArrayOneOrMore<T.PsString>; | ||
} | ||
const infs = inflectWord(a.entry); | ||
if (!infs) { | ||
return [psStringFromEntry(a.entry)]; | ||
} | ||
if (!infs.inflections || !isUnisexSet(infs.inflections)) { | ||
throw new Error( | ||
"error getting inflections for adjective, looks like a noun's inflections" | ||
); | ||
} | ||
return chooseInflection(infs.inflections, person, inflected); | ||
} | ||
|
||
export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> { | ||
return inflectAdvAdj(a, person, inflected) | ||
export function inflectAdjective( | ||
a: T.AdjectiveSelection, | ||
person: T.Person, | ||
inflected: boolean, | ||
mayo: "req" | "opt" | "no" | ||
): T.ArrayOneOrMore<T.PsString> { | ||
return inflectAdvAdj(a, person, inflected, mayo); | ||
} | ||
|
||
export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean, isLocationSingSandwich?: boolean): T.Rendered<T.AdjectiveSelection> { | ||
const eWord = getEnglishWord(a.entry); | ||
const e = !eWord | ||
? undefined | ||
: typeof eWord === "string" | ||
? eWord | ||
: (eWord.singular || undefined); | ||
const ps = inflectAdjective( | ||
a, | ||
person, | ||
isLocationSingSandwich && isPattern1Entry(a.entry) | ||
? false | ||
: inflected, | ||
); | ||
return { | ||
type: "adjective", | ||
entry: a.entry, | ||
ps, | ||
e, | ||
inflected, | ||
person, | ||
sandwich: a.sandwich ? renderSandwich(a.sandwich) : undefined, | ||
}; | ||
} | ||
export function renderAdjectiveSelection( | ||
a: T.AdjectiveSelection, | ||
person: T.Person, | ||
inflected: boolean, | ||
isLocationSingSandwich: boolean, | ||
mayo: "req" | "opt" | "no" | ||
): T.Rendered<T.AdjectiveSelection> { | ||
const eWord = getEnglishWord(a.entry); | ||
const e = !eWord | ||
? undefined | ||
: typeof eWord === "string" | ||
? eWord | ||
: eWord.singular || undefined; | ||
const toAddMayo = mayoOnWord( | ||
mayo, | ||
a.entry, | ||
personGender(person), | ||
personIsPlural(person) ? "plural" : "singular" | ||
); | ||
const ps = inflectAdjective( | ||
a, | ||
person, | ||
isLocationSingSandwich && isPattern1Entry(a.entry) ? false : inflected, | ||
toAddMayo | ||
); | ||
return { | ||
type: "adjective", | ||
entry: a.entry, | ||
ps, | ||
e, | ||
inflected, | ||
person, | ||
sandwich: a.sandwich ? renderSandwich(a.sandwich) : undefined, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.