Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
corscheid committed Nov 15, 2023
1 parent 0b45397 commit e88614e
Show file tree
Hide file tree
Showing 15 changed files with 729 additions and 414 deletions.
203 changes: 147 additions & 56 deletions src/affixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ export interface LenitionTable {
}

/**
* get table of all the possible lenition changes
*
* @return {LenitionTable} table of all possible lenition changes
*/
* get table of all the possible lenition changes
*
* @return {LenitionTable} table of all possible lenition changes
*/
export function getLenitionTable(): LenitionTable {
return {
"kx": "k",
"px": "p",
"tx": "t",
"k": "h",
"p": "f",
"ts": "s",
"t": "s",
"'": "",
kx: 'k',
px: 'p',
tx: 't',
k: 'h',
p: 'f',
ts: 's',
t: 's',
"'": ''
}
}

Expand All @@ -53,21 +53,30 @@ export function prefix(inputWord: Word): Word {

// pull this out of the switch because the pos data for verbs is so irregular,
// the switch condition would be like 25 possibilities long
if (word.data.PartOfSpeech.startsWith('v') || word.data.PartOfSpeech.startsWith('svin') || word.data.PartOfSpeech === '') {
if (
word.data.PartOfSpeech.startsWith('v') ||
word.data.PartOfSpeech.startsWith('svin') ||
word.data.PartOfSpeech === ''
) {
const inf = word.data.Affixes.Infix
if (inf.length > 0 && (inf[0] === 'us' || inf[0] === 'awn')) {
reString = '(a|tì)?'
} else if (word.target.includes('ketsuk') || word.target.includes("tsuk")) {
} else if (word.target.includes('ketsuk') || word.target.includes('tsuk')) {
reString = '(a)?(ketsuk|tsuk)?'
} else if (word.target.includes('siyu') && word.data.PartOfSpeech === 'vin.') {
reString = '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?'
} else if (
word.target.includes('siyu') &&
word.data.PartOfSpeech === 'vin.'
) {
reString =
'^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?'
}
} else {
switch (word.data.PartOfSpeech) {
case 'n.':
case 'pn.':
case 'prop.n.':
reString = '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?'
reString =
'^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?'
break
case 'adj.':
reString = '^(nìk|nì|a)?(ke|a)?'
Expand All @@ -77,7 +86,11 @@ export function prefix(inputWord: Word): Word {
}
}

if (word.target.startsWith('me') || word.target.startsWith('pxe') || word.target.startsWith('pe')) {
if (
word.target.startsWith('me') ||
word.target.startsWith('pxe') ||
word.target.startsWith('pe')
) {
if (word.attempt.startsWith('e')) {
reString = reString + '(e)?'
word.attempt = word.attempt.slice(1)
Expand Down Expand Up @@ -112,8 +125,22 @@ export function prefix(inputWord: Word): Word {
if (containsArr(matchPrefixes, ['fne', 'munsna'])) {
return word
}
const lenPre = ['pep', 'pem', 'pe', 'fray', 'tsay', 'fay', 'pay', 'ay', 'me', 'pxe']
if (containsArr(matchPrefixes, ['fì', 'tsa', 'fra']) && !containsArr(matchPrefixes, lenPre)) {
const lenPre = [
'pep',
'pem',
'pe',
'fray',
'tsay',
'fay',
'pay',
'ay',
'me',
'pxe'
]
if (
containsArr(matchPrefixes, ['fì', 'tsa', 'fra']) &&
!containsArr(matchPrefixes, lenPre)
) {
return word
}
}
Expand Down Expand Up @@ -151,7 +178,8 @@ export function suffix(inputWord: Word): Word {
let matchSuffixes: string[] = []

const adjSufRe = '(a|sì)?$'
const nSufRe = "(nga'|tsyìp|tu)?(o)?(pe)?(mungwrr|kxamlä|tafkip|pxisre|pximaw|ftumfa|mìkam|nemfa|takip|lisre|talun|krrka|teri|fkip|pxaw|pxel|luke|rofa|fpi|ftu|kip|vay|lok|maw|sìn|sre|few|kam|kay|nuä|sko|yoa|äo|eo|fa|hu|ka|mì|na|ne|ta|io|uo|ro|wä|sì|ìri|ìl|eyä|yä|ä|it|ri|ru|ti|ur|l|r|t)?$"
const nSufRe =
"(nga'|tsyìp|tu)?(o)?(pe)?(mungwrr|kxamlä|tafkip|pxisre|pximaw|ftumfa|mìkam|nemfa|takip|lisre|talun|krrka|teri|fkip|pxaw|pxel|luke|rofa|fpi|ftu|kip|vay|lok|maw|sìn|sre|few|kam|kay|nuä|sko|yoa|äo|eo|fa|hu|ka|mì|na|ne|ta|io|uo|ro|wä|sì|ìri|ìl|eyä|yä|ä|it|ri|ru|ti|ur|l|r|t)?$"
const ngey = 'ngey'

// hardcoded hack for tseyä
Expand All @@ -176,7 +204,11 @@ export function suffix(inputWord: Word): Word {
}

// verbs
if (!word.data.PartOfSpeech.includes('adv.') && word.data.PartOfSpeech.includes('v') || word.data.PartOfSpeech === '') {
if (
(!word.data.PartOfSpeech.includes('adv.') &&
word.data.PartOfSpeech.includes('v')) ||
word.data.PartOfSpeech === ''
) {
const inf = word.data.Affixes.Infix
const pre = word.data.Affixes.Prefix
// word is verb with <us> or <awn>
Expand Down Expand Up @@ -232,10 +264,56 @@ export function suffix(inputWord: Word): Word {
reString = word.attempt.replace(/a/g, '[ae]') + reString
} else if (word.data.Navi === 'tsaw') {
const tsaSuf = [
'mungwrr', 'kxamlä', 'tafkip', 'pxisre', 'pximaw', 'ftumfa', 'mìkam', 'nemfa', 'takip', 'lisre', 'talun',
'krrka', 'teri', 'fkip', 'pxaw', 'pxel', 'luke', 'rofa', 'fpi', 'ftu', 'kip', 'vay', 'lok', 'maw', 'sìn', 'sre',
'few', 'kam', 'kay', 'nuä', 'sko', 'yoa', 'äo', 'eo', 'fa', 'hu', 'ka', 'mì', 'na', 'ne', 'ta', 'io', 'uo',
'ro', 'wä', 'ìri', 'ri', 'ru', 'ti', 'r'
'mungwrr',
'kxamlä',
'tafkip',
'pxisre',
'pximaw',
'ftumfa',
'mìkam',
'nemfa',
'takip',
'lisre',
'talun',
'krrka',
'teri',
'fkip',
'pxaw',
'pxel',
'luke',
'rofa',
'fpi',
'ftu',
'kip',
'vay',
'lok',
'maw',
'sìn',
'sre',
'few',
'kam',
'kay',
'nuä',
'sko',
'yoa',
'äo',
'eo',
'fa',
'hu',
'ka',
'mì',
'na',
'ne',
'ta',
'io',
'uo',
'ro',
'wä',
'ìri',
'ri',
'ru',
'ti',
'r'
]
for (let s of tsaSuf) {
if (word.target.endsWith('tsa' + s) || word.target.endsWith('sa' + s)) {
Expand Down Expand Up @@ -301,76 +379,86 @@ export function suffix(inputWord: Word): Word {
export function infix(inputWord: Word): Word {
const word = inputWord.clone()
// Have we already attempted infixes or does the word even have infix positions??
if (word.data.Affixes.Infix.length !== 0 || word.data.InfixLocations === "NULL") {
if (
word.data.Affixes.Infix.length !== 0 ||
word.data.InfixLocations === 'NULL'
) {
return word
}

let re: RegExp
let reString: string
let attempt: string
let pos0InfixRe = "(äp)?(eyk)?"
let pos1InfixRe = "(ìyev|iyev|ìlm|ìly|ìrm|ìry|ìsy|alm|aly|arm|ary|asy|ìm|imv|ilv|irv|ìy|am|ay|er|iv|ol|us|awn)?"
let pos2InfixRe = "(eiy|ei|äng|eng|ats|uy)?"
let pos0InfixRe = '(äp)?(eyk)?'
let pos1InfixRe =
'(ìyev|iyev|ìlm|ìly|ìrm|ìry|ìsy|alm|aly|arm|ary|asy|ìm|imv|ilv|irv|ìy|am|ay|er|iv|ol|us|awn)?'
let pos2InfixRe = '(eiy|ei|äng|eng|ats|uy)?'
let pos0InfixString: string = ''
let pos1InfixString: string = ''
let pos2InfixString: string = ''
let matchInfixes: string[] = []

// Hardcode hack for z**enke
if (word.data.Navi === "zenke" && (word.target.includes("uy") || word.target.includes("ats"))) {
if (
word.data.Navi === 'zenke' &&
(word.target.includes('uy') || word.target.includes('ats'))
) {
word.data.InfixLocations = word.data.InfixLocations.replace(/ke$/, 'eke')
}

reString = word.data.InfixLocations.replace("<0>", pos0InfixRe)
reString = word.data.InfixLocations.replace('<0>', pos0InfixRe)

// handle <ol>ll and <er>rr
if (reString.includes("<1>ll")) {
reString = reString.replace("<1>ll", pos1InfixRe + "(ll)?")
} else if (word.data.InfixLocations.includes("<1>rr")) {
reString = reString.replace("<1>rr", pos1InfixRe + "(rr)?")
if (reString.includes('<1>ll')) {
reString = reString.replace('<1>ll', pos1InfixRe + '(ll)?')
} else if (word.data.InfixLocations.includes('<1>rr')) {
reString = reString.replace('<1>rr', pos1InfixRe + '(rr)?')
} else {
reString = reString.replace("<1>", pos1InfixRe)
reString = reString.replace('<1>', pos1InfixRe)
}
reString = reString.replace("<2>", pos2InfixRe)
reString = reString.replace('<2>', pos2InfixRe)

re = new RegExp(reString, 'g')
const tmp = Array.from(word.target.matchAll(re))
if (tmp.length > 0 && tmp[0].length >= 1) {
matchInfixes = tmp[0].slice(1)
}
matchInfixes = deleteEmpty(matchInfixes)
matchInfixes = deleteElement(matchInfixes, "ll")
matchInfixes = deleteElement(matchInfixes, "rr")
matchInfixes = deleteElement(matchInfixes, 'll')
matchInfixes = deleteElement(matchInfixes, 'rr')

for (const i of matchInfixes) {
if (i === "äp" || i === "eyk") {
if (i === 'äp' || i === 'eyk') {
pos0InfixString = pos0InfixString + i
} else if (["eiy", "ei", "äng", "eng", "ats", "uy"].includes(i)) {
} else if (['eiy', 'ei', 'äng', 'eng', 'ats', 'uy'].includes(i)) {
pos2InfixString = i
} else {
pos1InfixString = i
}
}

attempt = word.data.InfixLocations.replace("<0>", pos0InfixString)
attempt = attempt.replace("<1>", pos1InfixString)
attempt = attempt.replace("<2>", pos2InfixString)
attempt = word.data.InfixLocations.replace('<0>', pos0InfixString)
attempt = attempt.replace('<1>', pos1InfixString)
attempt = attempt.replace('<2>', pos2InfixString)

// eiy override?
if (matchInfixes.includes("eiy")) {
const eiy = matchInfixes.indexOf("eiy")
matchInfixes[eiy] = "ei"
if (matchInfixes.includes('eiy')) {
const eiy = matchInfixes.indexOf('eiy')
matchInfixes[eiy] = 'ei'
}

// handle <ol>ll and <er>rr
if (attempt.includes("olll")) {
attempt = attempt.replace("olll", "ol")
} else if (attempt.includes("errr")) {
attempt = attempt.replace("errr", "er")
if (attempt.includes('olll')) {
attempt = attempt.replace('olll', 'ol')
} else if (attempt.includes('errr')) {
attempt = attempt.replace('errr', 'er')
}

if (matchInfixes.length !== 0) {
const combined = combineArrays<string>(word.data.Affixes.Infix, matchInfixes)
const combined = combineArrays<string>(
word.data.Affixes.Infix,
matchInfixes
)
if (combined != null) {
word.data.Affixes.Infix = combined
}
Expand All @@ -383,7 +471,7 @@ export function infix(inputWord: Word): Word {
/**
* Lenite the word, based on the attempt. The target is not relevant here, so not given.
* Returns the lenite attempt.
*
*
* @param {Word} inputWord - the Fwew Word on which to track lenition
* @return {Word} The lenited version of this word
*/
Expand Down Expand Up @@ -421,7 +509,10 @@ export function reconstruct(inputWord: Word, target: string): Word | undefined {
word.attempt = word.data.Navi

// only try to infix verbs
if (word.data.PartOfSpeech.startsWith("v") || word.data.PartOfSpeech.startsWith('svin.')) {
if (
word.data.PartOfSpeech.startsWith('v') ||
word.data.PartOfSpeech.startsWith('svin.')
) {
word = word.infix()

if (word.attempt === word.target) {
Expand Down Expand Up @@ -472,5 +563,5 @@ export function reconstruct(inputWord: Word, target: string): Word | undefined {
if (word2.attempt === word2.target) {
return word2
}
return undefined;
return undefined
}
10 changes: 5 additions & 5 deletions src/fwew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { stripChars } from './util'
* !! Only one word is allowed, if spaces are found, they will be treated like part of the word !!
* This will return an array of Words, that fit the input text
* One Navi-Word can have multiple meanings and words (e.g. synonyms)
*
*
* @param {string} searchNaviWord word to search
* @return {Word[]} array of matching Fwew Word
*/
Expand All @@ -47,7 +47,7 @@ export function translateFromNavi(searchNaviWord: string): Word[] {
* fwew function: searches for Na'vi words in the dictionary
*
* Will run on each entry of the dictionary, appending matching Word entries to the previously-defined results array
*
*
* @param {Word} word in the dictionary we are currently comparing to the user's search input
*/
const fwew = (word: Word): void => {
Expand All @@ -67,12 +67,12 @@ export function translateFromNavi(searchNaviWord: string): Word[] {

// skip words that obviously won't work
const similarityScore = word.similarity(searchNaviWord)
if (similarityScore < 0.50 && !searchNaviWord.endsWith("eyä")) {
if (similarityScore < 0.5 && !searchNaviWord.endsWith('eyä')) {
return
}

// check if applying affix rules to word will yield any matches against the user's search input, and add them if so
const result = word.reconstruct(searchNaviWord);
const result = word.reconstruct(searchNaviWord)
if (result != null) {
result.data.Navi = naviWord
fwewResults.push(result)
Expand All @@ -99,7 +99,7 @@ export function translateToNavi(searchWord: string, langCode: string): Word[] {
* fwewReverse function: searches for Na'vi words in the dictionary in the reverse direction
*
* Will run on each entry of the dictionary, appending matching Word entries to the previously-defined results array
*
*
* @param {Word} word in the dictionary we are currently comparing to the user's search input
*/
const fwewReverse = (word: Word): void => {
Expand Down
Loading

0 comments on commit e88614e

Please sign in to comment.