Skip to content

Commit 334b131

Browse files
Fix #21 Remove Affixes doesn't work with sentences
Remove Arabic Affixes does not work with sentences #21
1 parent 4b9c2ab commit 334b131

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
<h1 align=center>📜 Changelog - سجل التغيير</h1>
22
<p align=center>All notable changes to this project will be documented in this file.</p>
33

4-
## [Unreleased](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.5...HEAD)
4+
## [Unreleased](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.6...HEAD)
5+
6+
## [1.0.6](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.6) - 2023-12-03 (19 Jumada al-awwal 1445)
7+
8+
### Fixed
9+
10+
- Remove Arabic Affixes does not work with sentences ([#21](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/21))
11+
12+
[Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.6...v1.0.6)
513

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

816
### Updated
917

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

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

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arabic-services",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Utility functions on Arabic text",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/scripts/scripts.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ export function wordToLetters(word: string): string {
123123
* for linguistic, stylistic, or morphological reasons.
124124
*
125125
* @param {string} word - The Arabic word from which the affixes are to be removed.
126-
* @returns {string} The word after removing any matching affixes. Returns the original word if no affix matches are found.
126+
* @returns {string} The word after removing any matching affixes. Returns the original word trimmed if no affix matches are found.
127127
*/
128-
export function removeArabicAffixes(word: string): string {
128+
function removeArabicAffixesFromWord(word: string): string {
129129
word = word.trim();
130130
if (ARABIC_PREFIXES.includes(word.substring(0, 2))) {
131131
// For: ALEF & LAM
@@ -145,6 +145,23 @@ export function removeArabicAffixes(word: string): string {
145145
return word;
146146
}
147147

148+
/**
149+
* Removes predefined affixes (prefixes and suffixes) from an Arabic text if words start or end with those affixes.
150+
* This function is designed specifically for processing Arabic text, where certain affixes might need to be removed
151+
* for linguistic, stylistic, or morphological reasons.
152+
*
153+
* @param {string} text - The Arabic text from which the affixes are to be removed.
154+
* @returns {string} The text after removing any matching affixes from each word. Returns the original text trimmed if no affix matches are found.
155+
*/
156+
export function removeArabicAffixes(text: string): string {
157+
let new_sentence = '';
158+
text = text.trim();
159+
for (const word of text.split(' ')) {
160+
new_sentence += removeArabicAffixesFromWord(word) + ' ';
161+
}
162+
return new_sentence.trim();
163+
}
164+
148165
/**
149166
* Calculates the encryption level based on the input level and word length.
150167
* @param {number} level - The input encryption level.

tests/scripts.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ describe('#removeArabicAffixes', () => {
211211
const result = ArabicServices.removeArabicAffixes(word);
212212
expect(result).toEqual('طلاب');
213213
});
214+
215+
it('should remove prefix & suffix from a sentence', () => {
216+
const word = 'المدرسون يحبون طلابهم';
217+
const result = ArabicServices.removeArabicAffixes(word);
218+
expect(result).toEqual('مدرس حب طلاب');
219+
});
214220
});
215221

216222
describe('#similarityScore', () => {

0 commit comments

Comments
 (0)