示例#1
0
        private void btnAuto_Click(object sender, RoutedEventArgs e)
        {
            string Word = Tashkeel.Remove(txtWord.Text);

            txtDiacritics.Text = Tashkeel.Guess(Word);
            txtWord.Text       = Tashkeel.SetTashkeel(Word, txtDiacritics.Text);
        }
示例#2
0
        public static string AnalyzeText(string TextToParse, ref BackgroundWorker BackGroundProcess)
        {
            //TextToParse = Tashkeel.Remove(TextToParse);
            Analyzer.TextToParse = TextToParse;
            Corrections          = 0;
            NotRecognized        = 0;
            ArabicWords          = ExtractArabicWords(TextToParse, out Sentences);
            //للاحتفاظ باحتمالات النطق المختلفة لكل كلمة لأغراض التعديل
            AllWordsInfo = new List <List <WordInfo> >();
            con.Open();
            LoadInterpreterData();
            for (int i = 0; i < ArabicWords.Count; i++) //التحليل الصرفي
            {
                if (ArabicWords[i].word == "EOS")       //نهاية جملة
                {
                    List <WordInfo> EOS = new List <WordInfo>();
                    EOS.Add(new WordInfo {
                        Word = "EOS"
                    });
                    AllWordsInfo.Add(EOS);
                    continue;
                }
                List <WordInfo> NewWordInfo = ProcessWord(ArabicWords[i]);                        //ابدأ معالجة الكلمة الجديدة
                AllWordsInfo.Add(NewWordInfo);                                                    //أضف ناتج المعالجة لمعلومات الكلمات
                if (NewWordInfo.Count == 0)                                                       //إذا لم يجد تفسير للكلمة
                {
                    NewWordInfo = Morphology.LookForForignWord(ArabicWords[i].word, NewWordInfo); //ابحث في الكلمات الأعجمية المخزنة
                    if (NewWordInfo.Count == 0)
                    {
                        //فشل تفسير الكلمة والتشكيل بناء على تتابع الحروف -غالبا للكلمات الأعجمية
                        //هذه الخوارزمية تحتاج تحسين
                        //للتعامل مع الكلمات الأعجمية المضاف لها ألف ولام أو ياء نسب
                        WordInfo NewWord = new WordInfo();
                        NewWord.Word       = ArabicWords[i].word;
                        NewWord.Diacritics = Tashkeel.Guess(ArabicWords[i].word);
                        NewWord.Meaning    = "N";
                        NewWordInfo.Add(NewWord);
                        NotRecognized += 1;
                    }
                }
                BackGroundProcess.ReportProgress((i + 1) * 100 / ArabicWords.Count);//تحديث شريط التقدم
            }

            for (int i = 0; i < ArabicWords.Count; i++)
            {
                int Longest = 0, Index = 0;
                List <GrammarRelation> PossibleRelations = Interpreter.StartInterpreting(i, "", 1, false);
                for (int PR = 0; PR < PossibleRelations.Count; PR++)
                {
                    if (Longest < PossibleRelations[PR].WordsCovered)
                    {
                        Longest = PossibleRelations[PR].WordsCovered;
                        Index   = PR;
                    }
                    //Interpreter.ApplyGrammarRelation(PossibleRelations[PR]);
                }
                i += Longest;
                if (PossibleRelations.Count > 0)
                {
                    GrammarRelation.ApplyGrammarRelation(PossibleRelations[Index]);
                    PossibleRelations[Index].ActivateRelation();
                }
            }
            con.Close();
            return(GenerateOutput());
        }