Пример #1
0
        public static string GenerateOutput()
        {
            StringBuilder OutPutText = new StringBuilder();;
            WordInfo      WordToAdd;
            int           LastAdded = -1;

            for (int i = 0; i < ArabicWords.Count; i++)
            {
                if (ArabicWords[i].word == "EOS")
                {
                    continue;
                }
                WordToAdd = AllWordsInfo[i][0];
                OutPutText.Append(TextToParse.Substring(LastAdded + 1, ArabicWords[i].Start - (LastAdded + 1)));
                OutPutText.Append(WordToAdd.ToString());
                LastAdded = ArabicWords[i].End; //آخر حرف أضيف هو آخر حروف الكلمة
                //إضافة الحروف غير العربية التالية إلى المخرجات كما هي
                if (i + 1 == ArabicWords.Count && LastAdded + 1 < TextToParse.Length)
                {
                    OutPutText.Append(TextToParse.Substring(LastAdded + 1));
                }
            }

            return(OutPutText.ToString());
        }
Пример #2
0
        public static string AnalyzeText(string TextToParse, ref BackgroundWorker BackGroundProcess)
        {
            Corrections   = 0;
            NotRecognized = 0;
            ArabicWords   = ExtractArabicWords(TextToParse);
            //للاحتفاظ باحتمالات النطق المختلفة لكل كلمة لأغراض التعديل
            AllWordsInfo = new List <List <WordInfo> >();
            StringBuilder OutPutText = new StringBuilder();

            conn.Open();
            con.Open();
            LoadInterpreterData();
            for (int i = 0; i < ArabicWords.Count; i++) //التحليل الصرفي
            {
                //
                ///http://ar.wikipedia.org/wiki/%D8%B2%D8%A7%D8%A6%D8%AF%D8%A9_(%D9%84%D8%BA%D8%A9)
                List <WordInfo> NewWordInfo = ProcessWord(ArabicWords[i]); //ابدأ معالجة الكلمة الجديدة
                AllWordsInfo.Add(NewWordInfo);                             //أضف ناتج المعالجة لمعلومات الكلمات
                if (NewWordInfo.Count == 0)                                //إذا لم يجد تفسير للكلمة
                {
                    //فشل تفسير الكلمة والتشكيل بناء على تتابع الحروف -غالبا للكلمات الأعجمية
                    //هذه الخوارزمية تحتاج تحسين
                    //للتعامل مع الكلمات الأعجمية المضاف لها ألف ولام أو ياء نسب
                    WordInfo NewWord = new WordInfo();
                    NewWord.Word       = ArabicWords[i].word;
                    NewWord.Diacritics = Tashkeel.Guess(ArabicWords[i].word);
                    NewWordInfo.Add(NewWord);
                    NotRecognized += 1;
                }
                BackGroundProcess.ReportProgress((i + 1) * 100 / ArabicWords.Count);//تحديث شريط التقدم
            }

            int             LastAdded = -1;
            WordInfo        WordToAdd;
            GrammarRelation GR;

            for (int i = 0; i < ArabicWords.Count; i++)
            {
                GR = new GrammarRelation();
                i += Interpreter.StartInterpreting(ref GR, i, "", 1, false);
            }
            for (int i = 0; i < ArabicWords.Count; i++)
            {
                WordToAdd = AllWordsInfo[i][0];
                OutPutText.Append(TextToParse.Substring(LastAdded + 1, ArabicWords[i].Start - (LastAdded + 1)));
                OutPutText.Append(WordToAdd.ToString());
                LastAdded = ArabicWords[i].End; //آخر حرف أضيف هو آخر حروف الكلمة
                //إضافة الحروف غير العربية التالية إلى المخرجات كما هي
                if (i + 1 == ArabicWords.Count && LastAdded + 1 < TextToParse.Length)
                {
                    OutPutText.Append(TextToParse.Substring(LastAdded + 1));
                }
            }

            conn.Close();
            con.Close();
            return(OutPutText.ToString());
        }