diff --git a/src/rhyme-analysis.js b/src/rhyme-analysis.js index 096d0bc..d7777a6 100644 --- a/src/rhyme-analysis.js +++ b/src/rhyme-analysis.js @@ -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, diff --git a/src/rhyme-helper-bg.js b/src/rhyme-helper-bg.js index 55f3e21..9e53ea8 100644 --- a/src/rhyme-helper-bg.js +++ b/src/rhyme-helper-bg.js @@ -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; @@ -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 { "ба": "па", diff --git a/tests/rhyme-helper.test.js b/tests/rhyme-helper.test.js index 41cf3f7..25f4e32 100644 --- a/tests/rhyme-helper.test.js +++ b/tests/rhyme-helper.test.js @@ -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);