Skip to content

Commit

Permalink
Convert To Old Arabic And Tashfeer Panned Words
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
MohamedAmgd committed Mar 2, 2024
1 parent 79b8cbd commit 1774438
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,41 @@ public static String tashfeerBannedWords(String text, int levelOfTashfeer) {
return newText.toString().trim();
}

/**
* Converts the provided text to old Arabic while handling banned words with
* tashfeer.
* Uses a default tashfeer level of 2.
*
* @param text The input text to be processed.
* @return The processed text with words converted to old Arabic and tashfeer
* applied to banned words.
*/
public static String toOldArabicAndTashfeerBannedWords(String text) {
return toOldArabicAndTashfeerBannedWords(text, 2);
}

/**
* Converts words in a sentence to old Arabic while handling banned words with
* tashfeer.
*
* @param text The input text to be processed.
* @param levelOfTashfeer The level of tashfeer to apply to banned words.
* @return The processed text with words converted to old Arabic and
* tashfeer applied to banned words.
*/
public static String toOldArabicAndTashfeerBannedWords(String text, int levelOfTashfeer) {
StringBuilder result = new StringBuilder();
String[] words = text.trim().split("\\s+");
for (String word : words) {
if (checkIfBannedWord(word)) {
result.append(tashfeerHandler(word, levelOfTashfeer)).append(" ");
} else {
result.append(textToOldArabic(word)).append(" ");
}
}
return result.toString().trim();
}

private static String handleNoonIssue(String text) {
String arabicLetters = String.join("", Data.LETTERS_DICT.keySet()) + "ـ";
String regex = Data.NOON + "(" + "?=[^" + arabicLetters + "]" + ")|" + Data.NOON + "\\z";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,15 @@ public void tashfeerBannedWordsShouldHandleEmptyInput() {
String result = ArabicServices.tashfeerBannedWords(sentence);
assertEquals("", result);
}

@Test
public void testToOldArabicAndTashfeerBannedWords() {
String sentence = "جيش العدو يقتل الأطفال";
String result = ArabicServices.toOldArabicAndTashfeerBannedWords(sentence);
assertNotEquals(sentence, result);
assertTrue(result.contains("الاطڡال"));
assertFalse(result.contains("جيش"));
assertFalse(result.contains("العدو"));
assertFalse(result.contains("يقتل"));
}
}

0 comments on commit 1774438

Please sign in to comment.