Skip to content

Commit 768fe80

Browse files
update
1 parent d683f62 commit 768fe80

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

src/rhyme-engine.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,15 @@ class RhymeEngine {
55

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

8-
let findRhymesForWordSimilar = RhymeHelperBG.getSimilarSounding(findRhymesForWord);
9-
let findRhymesForWordCombinations = RhymeHelperBG.wordCombinations(findRhymesForWord, 4);
10-
let findRhymesForWordLastFourLetters = findRhymesForWord.substring(findRhymesForWord.length - 4);
11-
let findRhymesForWordLastThreeLetters = findRhymesForWord.substring(findRhymesForWord.length - 3);
12-
13-
148
let rhymes = [];
159
let maxRyhmes = 10000;
1610

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

19-
let rhymeRate = 0;
2013
const word = words[i];
21-
const wordSimilar = RhymeHelperBG.getSimilarSounding(word);
22-
const wordCombinations = RhymeHelperBG.wordCombinations(word, 4);
23-
const wordLastFourLetters = word.substring(word.length - 4);
24-
const wordLastThreeLetters = word.substring(word.length - 3);
25-
26-
// for (let j = 0; j < wordCombinations.length; j++) {
27-
// if (findRhymesForWordCombinations.includes(wordCombinations[j])) {
28-
// rhymeRate = rhymeRate + 0.5;
29-
// }
30-
// }
31-
if (findRhymesForWordLastFourLetters === wordLastFourLetters) {
32-
rhymeRate = rhymeRate + 1;
33-
}
34-
if (findRhymesForWordLastThreeLetters === wordLastThreeLetters) {
35-
rhymeRate = rhymeRate + 1;
36-
}
37-
3814

39-
if (rhymeRate === 0) {
15+
let rhymeRate = RhymeHelperBG.getRhymeRate(findRhymesForWord, words[i]);
16+
if (rhymeRate < 1) {
4017
continue;
4118
}
4219

src/rhyme-helper-bg.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RhymeHelperBG {
3434
for (let withVowel of withWordVowels) {
3535
if (vowel.letter === withVowel.letter) {
3636
if (vowel.position === withVowel.position) {
37-
rhymeRate = rhymeRate + 0.5;
37+
rhymeRate = rhymeRate + 0.5;
3838
} else {
3939
rhymeRate = rhymeRate + 0.05;
4040
}
@@ -44,14 +44,12 @@ class RhymeHelperBG {
4444
}
4545

4646
if (wordLastFourLetters === withWordLastFourLetters) {
47-
rhymeRate = rhymeRate + 1;
48-
}
49-
if (wordLastThreeLetters === withWordLastThreeLetters) {
47+
rhymeRate = rhymeRate + 1;
48+
} else if (wordLastThreeLetters === withWordLastThreeLetters) {
5049
rhymeRate = rhymeRate + 0.5;
50+
} else if (wordLastTwoLetters === withWordLastTwoLetters) {
51+
rhymeRate = rhymeRate + 0.05;
5152
}
52-
// if (wordLastTwoLetters === withWordLastTwoLetters) {
53-
// rhymeRate = rhymeRate + 0.05;
54-
// }
5553

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

63-
// if (wordSimilarTwoLetters === withWordLastTwoLetters) {
64-
// rhymeRate = rhymeRate + 0.05;
65-
// }
66-
if (wordSimilarThreeLetters === withWordLastThreeLetters) {
67-
rhymeRate = rhymeRate + 0.5;
68-
}
6961
if (wordSimilarFourLetters === withWordLastFourLetters) {
7062
rhymeRate = rhymeRate + 1;
63+
} else if (wordSimilarThreeLetters === withWordLastThreeLetters) {
64+
rhymeRate = rhymeRate + 0.5;
65+
} else if (wordSimilarTwoLetters === withWordLastTwoLetters) {
66+
rhymeRate = rhymeRate + 0.05;
7167
}
7268

7369
}

src/rhyme.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ let txt = '' +
3737
//
3838
// console.log(rhymeAnalysis);
3939

40-
RhymeHelperBG.getRhymeRate("Сняг", "Як");
40+
//RhymeHelperBG.getRhymeRate("Сняг", "Як");
41+
42+
let rhymeTopRanking = [];
43+
44+
const words = require('./dict/bg-words.json');

0 commit comments

Comments
 (0)