Skip to content

Commit

Permalink
refactor: rename fluent to fleeting vowels
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Dec 31, 2024
1 parent 26f4eca commit 2677256
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 57 deletions.
41 changes: 41 additions & 0 deletions src/common/fleetingVowels.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { inferFleetingVowel, markFleetingVowel } from './fleetingVowels';

describe('fleetingVowels', () => {
describe('markFleetingVowel', () => {
it('marks the fleeting vowel in the word', () => {
expect(markFleetingVowel('pes', 'psa')).toBe('p(e)s');
expect(markFleetingVowel('son', 'sna')).toBe('s(o)n');
});

it('returns the same word when there is no fleeting vowel', () => {
expect(markFleetingVowel('mama', 'mama')).toBe('mama');
});

it('marks the fleeting vowel when it includes a diacritic', () => {
expect(markFleetingVowel('pènj', 'pnja')).toBe('p(e)nj');
expect(markFleetingVowel('sòn', 'sna')).toBe('s(o)n');
});
});

describe('inferFleetingVowel', () => {
it('infers the fleeting vowel in the word', () => {
expect(inferFleetingVowel('pės')).toBe('p(e)s');
expect(inferFleetingVowel('pèsȯk')).toBe('pès(o)k');
expect(inferFleetingVowel('sȯn')).toBe('s(o)n');
expect(inferFleetingVowel('dėnj')).toBe('d(e)nj');
expect(inferFleetingVowel('orėl')).toBe('or(e)l');
});

it('infers the fleeting vowel in complex words', () => {
expect(inferFleetingVowel('pėsȯk, kotȯk i orėl')).toBe(
'pės(o)k, kot(o)k i or(e)l',
);
});

it('does not infer incorrect fleeting vowels in the word', () => {
expect(inferFleetingVowel('pėj')).toBe('pėj');
expect(inferFleetingVowel('dvėri')).toBe('dvėri');
expect(inferFleetingVowel('dȯžď')).toBe('dȯžď');
});
});
});
14 changes: 7 additions & 7 deletions src/common/fluentVowels.ts → src/common/fleetingVowels.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ALL_LETTERS, ALL_CONSONANTS } from '../substitutions';

export function markFluentVowel(word: string, add: string): string {
export function markFleetingVowel(word: string, add: string): string {
let i = 0;

const L = Math.min(word.length - 1, add.length);
Expand All @@ -9,13 +9,13 @@ export function markFluentVowel(word: string, add: string): string {
}

if (word[i] !== add[i] && word[i + 1] === add[i]) {
return replaceFluentVowel(word, i);
return replaceFleetingVowel(word, i);
}

return word;
}

export function inferFluentVowel(word: string): string {
export function inferFleetingVowel(word: string): string {
let i = word.length - 1;
let end = word.length;
let replaced = false;
Expand All @@ -30,7 +30,7 @@ export function inferFluentVowel(word: string): string {

if (!replaced && isFleetingVowel(char)) {
if (isLastSyllable(word, i, end)) {
result = replaceFluentVowel(result, i);
result = replaceFleetingVowel(result, i);
}
}

Expand All @@ -44,9 +44,9 @@ function isFleetingVowel(char: string): boolean {
return char === 'è' || char === 'ė' || char === 'ȯ' || char === 'ò';
}

function replaceFluentVowel(word: string, j: number): string {
const fluentVowel = word[j].normalize('NFD')[0];
return `${word.slice(0, j)}(${fluentVowel})${word.slice(j + 1)}`;
function replaceFleetingVowel(word: string, j: number): string {
const fleetingVowel = word[j].normalize('NFD')[0];
return `${word.slice(0, j)}(${fleetingVowel})${word.slice(j + 1)}`;
}

function isLastSyllable(word: string, i: number, end: number): boolean {
Expand Down
41 changes: 0 additions & 41 deletions src/common/fluentVowels.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './stripDiacritics';
export * from './fluentVowels';
export * from './fleetingVowels';
16 changes: 8 additions & 8 deletions src/noun/declensionNoun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { declensionAdjective } from '../adjective';
import { inferFluentVowel, markFluentVowel } from '../common';
import { inferFleetingVowel, markFleetingVowel } from '../common';
import type { Noun } from '../partOfSpeech';
import { removeBrackets, replaceStringAt } from '../utils';
import { establishGender } from './establishGender';
Expand Down Expand Up @@ -106,9 +106,9 @@ export function declensionNoun(
}

if (add && noun !== add) {
noun = markFluentVowel(noun, add);
noun = markFleetingVowel(noun, add);
} else {
noun = inferFluentVowel(noun);
noun = inferFleetingVowel(noun);
}

const rawGender = prepareGender(originGender, animated);
Expand All @@ -118,12 +118,12 @@ export function declensionNoun(
noun =
noun.slice(0, -2) + noun.slice(-2).replace(/([cšžčćńľŕťďśźđj])/g, '$1ь');

const nounWithoutFluent = noun.replace(/\([oe]\)/, '');
const nounWithoutFleeting = noun.replace(/\([oe]\)/, '');

noun = noun.replace('(e)', 'ė').replace('(o)', 'ȯ');

const gender = establishGender(noun, rawGender);
const root = establish_root(nounWithoutFluent, gender);
const root = establish_root(nounWithoutFleeting, gender);
const plroot = establish_plural_root(root);
const plgen = establishPluralGender(root, plroot, gender, rawGender);

Expand Down Expand Up @@ -188,7 +188,7 @@ function establish_root(noun: string, gender: string) {
result = 'dn';
}*/

const fluentVowelIndex = Math.max(
const fleetingVowelIndex = Math.max(
noun.lastIndexOf('ė'),
noun.lastIndexOf('ȯ'),
);
Expand Down Expand Up @@ -230,8 +230,8 @@ function establish_root(noun: string, gender: string) {
result = noun;
}

if (!hasVowelEnding && fluentVowelIndex > result.length - 3) {
result = replaceStringAt(result, fluentVowelIndex, '');
if (!hasVowelEnding && fleetingVowelIndex > result.length - 3) {
result = replaceStringAt(result, fleetingVowelIndex, '');
}

return result;
Expand Down

0 comments on commit 2677256

Please sign in to comment.