Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed May 24, 2024
1 parent d683f62 commit 768fe80
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
27 changes: 2 additions & 25 deletions src/rhyme-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,15 @@ class RhymeEngine {

const words = require('./dict/bg-words.json');

let findRhymesForWordSimilar = RhymeHelperBG.getSimilarSounding(findRhymesForWord);
let findRhymesForWordCombinations = RhymeHelperBG.wordCombinations(findRhymesForWord, 4);
let findRhymesForWordLastFourLetters = findRhymesForWord.substring(findRhymesForWord.length - 4);
let findRhymesForWordLastThreeLetters = findRhymesForWord.substring(findRhymesForWord.length - 3);


let rhymes = [];
let maxRyhmes = 10000;

for (let i = 0; i < words.length; i++) {

let rhymeRate = 0;
const word = words[i];
const wordSimilar = RhymeHelperBG.getSimilarSounding(word);
const wordCombinations = RhymeHelperBG.wordCombinations(word, 4);
const wordLastFourLetters = word.substring(word.length - 4);
const wordLastThreeLetters = word.substring(word.length - 3);

// for (let j = 0; j < wordCombinations.length; j++) {
// if (findRhymesForWordCombinations.includes(wordCombinations[j])) {
// rhymeRate = rhymeRate + 0.5;
// }
// }
if (findRhymesForWordLastFourLetters === wordLastFourLetters) {
rhymeRate = rhymeRate + 1;
}
if (findRhymesForWordLastThreeLetters === wordLastThreeLetters) {
rhymeRate = rhymeRate + 1;
}


if (rhymeRate === 0) {
let rhymeRate = RhymeHelperBG.getRhymeRate(findRhymesForWord, words[i]);
if (rhymeRate < 1) {
continue;
}

Expand Down
22 changes: 9 additions & 13 deletions src/rhyme-helper-bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RhymeHelperBG {
for (let withVowel of withWordVowels) {
if (vowel.letter === withVowel.letter) {
if (vowel.position === withVowel.position) {
rhymeRate = rhymeRate + 0.5;
rhymeRate = rhymeRate + 0.5;
} else {
rhymeRate = rhymeRate + 0.05;
}
Expand All @@ -44,14 +44,12 @@ class RhymeHelperBG {
}

if (wordLastFourLetters === withWordLastFourLetters) {
rhymeRate = rhymeRate + 1;
}
if (wordLastThreeLetters === withWordLastThreeLetters) {
rhymeRate = rhymeRate + 1;
} else if (wordLastThreeLetters === withWordLastThreeLetters) {
rhymeRate = rhymeRate + 0.5;
} else if (wordLastTwoLetters === withWordLastTwoLetters) {
rhymeRate = rhymeRate + 0.05;
}
// if (wordLastTwoLetters === withWordLastTwoLetters) {
// rhymeRate = rhymeRate + 0.05;
// }

if (wordSimilar.length > 0) {
for (let similar of wordSimilar) {
Expand All @@ -60,14 +58,12 @@ class RhymeHelperBG {
let wordSimilarThreeLetters = similar.substring(similar.length - 3);
let wordSimilarFourLetters = similar.substring(similar.length - 4);

// if (wordSimilarTwoLetters === withWordLastTwoLetters) {
// rhymeRate = rhymeRate + 0.05;
// }
if (wordSimilarThreeLetters === withWordLastThreeLetters) {
rhymeRate = rhymeRate + 0.5;
}
if (wordSimilarFourLetters === withWordLastFourLetters) {
rhymeRate = rhymeRate + 1;
} else if (wordSimilarThreeLetters === withWordLastThreeLetters) {
rhymeRate = rhymeRate + 0.5;
} else if (wordSimilarTwoLetters === withWordLastTwoLetters) {
rhymeRate = rhymeRate + 0.05;
}

}
Expand Down
6 changes: 5 additions & 1 deletion src/rhyme.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ let txt = '' +
//
// console.log(rhymeAnalysis);

RhymeHelperBG.getRhymeRate("Сняг", "Як");
//RhymeHelperBG.getRhymeRate("Сняг", "Як");

let rhymeTopRanking = [];

const words = require('./dict/bg-words.json');

0 comments on commit 768fe80

Please sign in to comment.