Skip to content

Commit

Permalink
Merge pull request #24 from Seen-Arabic/21-remove-arabic-affixes-does…
Browse files Browse the repository at this point in the history
…-not-work-with-sentences

Fix #21 Remove Affixes doesn't work with sentences
  • Loading branch information
AbdelrahmanBayoumi authored Dec 3, 2023
2 parents 4b9c2ab + 334b131 commit 9434361
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<h1 align=center>📜 Changelog - سجل التغيير</h1>
<p align=center>All notable changes to this project will be documented in this file.</p>

## [Unreleased](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.5...HEAD)
## [Unreleased](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.6...HEAD)

## [1.0.6](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.6) - 2023-12-03 (19 Jumada al-awwal 1445)

### Fixed

- Remove Arabic Affixes does not work with sentences ([#21](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/21))

[Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.6...v1.0.6)

## [1.0.5](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.5) - 2023-12-03 (19 Jumada al-awwal 1445)

### Updated

- Trim text before converting ([#22](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/22))

[Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.3...v1.0.4)
[Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.4...v1.0.5)

## [1.0.4](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.4) - 2023-11-30 (16 Jumada al-awwal 1445)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arabic-services",
"version": "1.0.5",
"version": "1.0.6",
"description": "Utility functions on Arabic text",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
21 changes: 19 additions & 2 deletions src/scripts/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export function wordToLetters(word: string): string {
* for linguistic, stylistic, or morphological reasons.
*
* @param {string} word - The Arabic word from which the affixes are to be removed.
* @returns {string} The word after removing any matching affixes. Returns the original word if no affix matches are found.
* @returns {string} The word after removing any matching affixes. Returns the original word trimmed if no affix matches are found.
*/
export function removeArabicAffixes(word: string): string {
function removeArabicAffixesFromWord(word: string): string {
word = word.trim();
if (ARABIC_PREFIXES.includes(word.substring(0, 2))) {
// For: ALEF & LAM
Expand All @@ -145,6 +145,23 @@ export function removeArabicAffixes(word: string): string {
return word;
}

/**
* Removes predefined affixes (prefixes and suffixes) from an Arabic text if words start or end with those affixes.
* This function is designed specifically for processing Arabic text, where certain affixes might need to be removed
* for linguistic, stylistic, or morphological reasons.
*
* @param {string} text - The Arabic text from which the affixes are to be removed.
* @returns {string} The text after removing any matching affixes from each word. Returns the original text trimmed if no affix matches are found.
*/
export function removeArabicAffixes(text: string): string {
let new_sentence = '';
text = text.trim();
for (const word of text.split(' ')) {
new_sentence += removeArabicAffixesFromWord(word) + ' ';
}
return new_sentence.trim();
}

/**
* Calculates the encryption level based on the input level and word length.
* @param {number} level - The input encryption level.
Expand Down
6 changes: 6 additions & 0 deletions tests/scripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ describe('#removeArabicAffixes', () => {
const result = ArabicServices.removeArabicAffixes(word);
expect(result).toEqual('طلاب');
});

it('should remove prefix & suffix from a sentence', () => {
const word = 'المدرسون يحبون طلابهم';
const result = ArabicServices.removeArabicAffixes(word);
expect(result).toEqual('مدرس حب طلاب');
});
});

describe('#similarityScore', () => {
Expand Down

0 comments on commit 9434361

Please sign in to comment.