normalizeArabic function

String normalizeArabic(
  1. String text
)

Normalize Arabic text for better word matching

Implementation

String normalizeArabic(String text) {
  return text
      .replaceAll(RegExp(r'[\u064B-\u0652]'), '') // Remove diacritics
      .replaceAll(RegExp(r'[\u0670]'), '') // Remove dagger alif
      .replaceAll(RegExp(r'[\u0671]'), '') // Remove alif wasla
      .replaceAll(RegExp(r'[\u0640]'), '') // Remove tatweel (kashida)
      .replaceAll(RegExp(r'[۪۬۟۫۠ۡ۝۞ۣۖۗۘۙۚۛۜۢۤۥۦۧۨ]'), '') // Remove other marks
      .replaceAll(RegExp(r'[.،؛؟!]'), '') // Remove punctuation
      .replaceAll(RegExp(r'[ٱأإآ]'), 'ا') // Normalize alif forms
      .replaceAll('ى', 'ي') // Normalize alif maqsurah to yaa
      .replaceAll('ة', 'ه') // Normalize ta marbuta to ha
      .trim();
}