I am having utf-8 encoded file containing arabic text and I have to search it.
My problem are diacritics, how to search skipping them?
Like if you load that text in Internet Explorer (converting text in HTML ofcourse ), IE is skipping those diacritics?
Any help?
Edit1: Search is simply performed by following code:
var m1 : TMemo; //contains utf-8 data)
m2 : TMemo; // contains results
...
m2.lines.BeginUpdate;
for s in m1.Lines do
begin
if pos(eSearch.Text,s)>0 then
begin
m2.Lines.Add(s);
end;
end;
m2.Lines.EndUpdate;
Edit2: Example of unicode data:
قُلْ هُوَ اللَّهُ أَحَدٌ
If you search only letters without diacritics قل the word قُلْ wont be found.
I find that diacritics are not the only problem.
I would do character replacements, replacing them by empty strings, I would also normalize the text ‘أ’ ‘إ’ ‘آ’ are all converted to ‘ا’, and also do the same for ى ئ ي ؤ و ة ه …
For search I’d also use a light stemmer like the “khoja stemmer” (Java source here)
A more advanced way is to do it like TREC:
(and) from the beginnings of normalized words
I would index the text by this modified text (for memos I’d store the index of the word in the original text), and do the same thing for the search query.
I would also search in Memo1.Text and not the lines one by one, the search could be for multiple words that may be at the end of a line and wrapped to the next line.