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 910d1f8 commit b21409e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
40 changes: 35 additions & 5 deletions src/rhyme-helper-bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class RhymeHelperBG {

static getRhymeRate(word, withWord) {

if (word.length < 3) {
if (word.length < 2) {
return 0;
}
if (withWord.length < 3) {
if (withWord.length < 2) {
return 0;
}
word = word.toLowerCase();
Expand All @@ -17,14 +17,44 @@ class RhymeHelperBG {
let rhymeRate = 0;
const wordSimilar = this.getSimilarSounding(word);
const wordCombinations = this.wordCombinations(word, 4);
const wordLastTwoLetters = word.substring(word.length - 2);
const wordLastFourLetters = word.substring(word.length - 4);
const wordLastThreeLetters = word.substring(word.length - 3);

if (withWord.includes(wordLastFourLetters)) {
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);

if (wordLastFourLetters === withWordLastFourLetters) {
rhymeRate = rhymeRate + 1;
}
if (withWord.includes(wordLastThreeLetters)) {
rhymeRate = rhymeRate + 1;
if (wordLastThreeLetters === withWordLastThreeLetters) {
rhymeRate = rhymeRate + 0.5;
}
if (wordLastTwoLetters === withWordLastTwoLetters) {
rhymeRate = rhymeRate + 0.05;
}

if (wordSimilar.length > 0) {
for (let similar of wordSimilar) {

let wordSimilarTwoLetters = similar.substring(similar.length - 2);
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;
}

}
}

return rhymeRate;
Expand Down
7 changes: 5 additions & 2 deletions src/rhyme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Read content from file
const RhymeEngine = require('./rhyme-engine');
const RhymeAnalysis = require("./rhyme-analysis");
const RhymeHelperBG = require("./rhyme-helper-bg");
//
// // Read the file
// const rhyme = fs.readFileSync('src/dict/bg-spellchecked.txt', 'utf8');
Expand Down Expand Up @@ -32,6 +33,8 @@ let txt = '' +
'Не питай защо, само здраво се дръж, \n' +
'мед ще ми носиш когато сваля те веднъж.';

let rhymeAnalysis = RhymeAnalysis.analyze(txt);
// let rhymeAnalysis = RhymeAnalysis.analyze(txt);
//
// console.log(rhymeAnalysis);

console.log(rhymeAnalysis);
RhymeHelperBG.getRhymeRate("Сняг", "Як");
4 changes: 2 additions & 2 deletions tests/rhyme-helper.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const RhymeHelperBG = require("../src/rhyme-helper-bg");
test("Check rhymes", () => {

expect(RhymeHelperBG.getRhymeRate("Сняг", "Як"))
.toBeGreaterThan(0.04);

expect(RhymeHelperBG.getRhymeRate("Божидар", "Говедар"))
.toBeGreaterThan(0.5);
Expand All @@ -12,6 +14,4 @@ test("Check rhymes", () => {
.toBeGreaterThan(0.5);




})

0 comments on commit b21409e

Please sign in to comment.