arabic
Normalising Arabic-script text: Arabic yeh and kaf, vowel marks, tatweel, the zero width non-joiner and digits, for search and comparison.
import arabic
Arabic-script text does not arrive in one shape. One source writes «كتاب» with an Arabic kaf and another with a Persian one; one adds vowel marks, another a tatweel (ـــ), and some text, from a PDF for instance, carries the presentation forms of the letters. To a reader they are the same word; to a computer they are different strings, and the search fails.
The arabic package removes those differences. Normalize works from flags you choose, combined with +. For most purposes NormalizePersian or SearchKey is all you need.
Constants and variables
FoldLetters
const FoldLetters: i32 = 1import arabic
func main:
text := "كتابٌ عربيّة ـــ ٣٤ ﻻ"
println arabic.NormalizePersian(text)
println arabic.Normalize(text, arabic.StripHarakat)
println arabic.Normalize(text, arabic.FoldLetters + arabic.FoldDigits)
println arabic.Normalize("میخواهم", arabic.StripZWNJ)
println arabic.Normalize("أحمد إيران", arabic.FoldAlef)
println arabic.Normalize("مدرسة", arabic.FoldTehMarbuta)
println arabic.Normalize("ﻻ ﻣﺮﺣﺒﺎ", arabic.FoldPresentation)
println arabic.Normalize("ســلام", arabic.StripTatweel)
endStripHarakat
const StripHarakat: i32 = 2The example for this item is shown with the ones above: arabic-Normalize.salam
StripTatweel
const StripTatweel: i32 = 4The example for this item is shown with the ones above: arabic-Normalize.salam
FoldDigits
const FoldDigits: i32 = 8The example for this item is shown with the ones above: arabic-Normalize.salam
FoldAlef
const FoldAlef: i32 = 16The example for this item is shown with the ones above: arabic-Normalize.salam
FoldTehMarbuta
const FoldTehMarbuta: i32 = 32The example for this item is shown with the ones above: arabic-Normalize.salam
StripZWNJ
const StripZWNJ: i32 = 64The example for this item is shown with the ones above: arabic-Normalize.salam
FoldPresentation
const FoldPresentation: i32 = 128The example for this item is shown with the ones above: arabic-Normalize.salam
Functions
IsArabicScript
func IsArabicScript(cp: int): boolimport arabic
func main:
println arabic.IsArabicScript(1588), arabic.IsArabicScript(65)
println arabic.IsHaraka(1614), arabic.IsHaraka(1588)
println arabic.IsTatweel(1600), arabic.IsTatweel(1588)
endIsHaraka
func IsHaraka(cp: int): boolThe example for this item is shown with the ones above: arabic-IsArabicScript.salam
IsTatweel
func IsTatweel(cp: int): boolThe example for this item is shown with the ones above: arabic-IsArabicScript.salam
Normalize
func Normalize(s: str, flags: int): strThe example for this item is shown with the ones above: arabic-Normalize.salam
NormalizePersian
func NormalizePersian(s: str): strThe example for this item is shown with the ones above: arabic-Normalize.salam
SearchKey
func SearchKey(s: str): strimport arabic
func main:
println arabic.SearchKey("كتابٌ"), arabic.SearchKey("کتاب")
println arabic.EqualLoose("ميخواهم", "میخواهم")
println arabic.EqualLoose("سلام", "کلام")
endEqualLoose
func EqualLoose(a: str, b: str): boolThe example for this item is shown with the ones above: arabic-SearchKey.salam