Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed May 23, 2024
1 parent ec504e2 commit 37e53af
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rhyme-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RhymeAnalysis {
let word2 = words[j];

let rhymeRate = RhymeHelperBG.getRhymeRate(word1, word2);
if (rhymeRate > 0) {
if (rhymeRate > 1) {

rhymes.push({
word1: word1,
Expand Down
29 changes: 29 additions & 0 deletions src/rhyme-helper-bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ class RhymeHelperBG {
const wordLastTwoLetters = word.substring(word.length - 2);
const wordLastFourLetters = word.substring(word.length - 4);
const wordLastThreeLetters = word.substring(word.length - 3);
const wordVowels = this.getVowelLettersFromWord(word);

const withWordSimilar = this.getSimilarSounding(withWord);
const withWordCombinations = this.wordCombinations(withWord, 4);
const withWordLastTwoLetters = withWord.substring(withWord.length - 2);
const withWordLastFourLetters = withWord.substring(withWord.length - 4);
const withWordLastThreeLetters = withWord.substring(withWord.length - 3);
const withWordVowels = this.getVowelLettersFromWord(withWord);

if (wordVowels.length > 0 && withWordVowels.length > 0) {
for (let vowel of wordVowels) {
if (withWordVowels.includes(vowel)) {
rhymeRate = rhymeRate + 0.05;
}
}
}

if (wordLastFourLetters === withWordLastFourLetters) {
rhymeRate = rhymeRate + 1;
Expand Down Expand Up @@ -149,6 +159,25 @@ class RhymeHelperBG {
};
}

static getVowelLettersFromWord(word) {
let vowels = [];
let wordArray = this.split(word);
for (let letter of wordArray) {
if (this.vowelLetters().includes(letter)) {
vowels.push(letter);
}
}
return vowels;
}

static vowelLetters() {
return ["а", "ъ", "о", "у", "е", "и"];
}
static consonantsLetters()
{
return ["б", "в", "г", "д", "ж", "з", "к", "л", "м", "н", "п", "р", "с", "т", "ф", "х", "ц", "ч", "ш", "щ"];
}

static soundlyAndSoundlessConsonants() {
return {
"ба": "па",
Expand Down
15 changes: 15 additions & 0 deletions tests/rhyme-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ test("Check rhymes", () => {
// expect(RhymeHelperBG.getRhymeRate("Сняг", "Як"))
// .toBeGreaterThan(0.04);

expect(RhymeHelperBG.getRhymeRate("Oдма", "Kобра"))
.toBeGreaterThan(0.04);

expect(RhymeHelperBG.getRhymeRate("Помогна", "Доволна"))
.toBeGreaterThan(0.1);

expect(RhymeHelperBG.getRhymeRate("Помогна", "Кротна"))
.toBeGreaterThan(0.1);

expect(RhymeHelperBG.getRhymeRate("Смогна", "Бодна"))
.toBeGreaterThan(0.09);

expect(RhymeHelperBG.getRhymeRate("Непознато", "Десперадо"))
.toBeGreaterThan(0.4);

expect(RhymeHelperBG.getRhymeRate("Божидар", "Говедар"))
.toBeGreaterThan(0.5);

Expand Down

0 comments on commit 37e53af

Please sign in to comment.