Example #1
0
        public static List <WordSuffix> CheckSuffixes(string Word)
        {
            string[]          suffixes      = { "ة", "ت", "ا", "ن", "تم", "ك", "كم", "هم", "ه", "ي" };
            List <WordSuffix> ValidSuffixes = new List <WordSuffix>();

            for (int i = 0; i < suffixes.Length; i++)
            {
                if (Word.EndsWith(suffixes[i], StringComparison.Ordinal)) // =word.endwith()==suffixes[i]
                {
                    OleDbCommand com = new OleDbCommand();
                    com.Connection  = Analyzer.con;
                    com.CommandText = "select * from suffixes where StrComp( Right( add , " + suffixes[i].Length + "),'" + suffixes[i] + "',0)=0";
                    OleDbDataReader dread = com.ExecuteReader();
                    while (dread.Read())
                    {
                        if (Word.EndsWith(dread[0].ToString(), StringComparison.Ordinal))
                        {
                            WordSuffix s = new WordSuffix();
                            s.Text            = dread["Add"].ToString();
                            s.Tashkeel        = dread["Diacritics"].ToString();
                            s.WordClass       = dread["Class"].ToString();
                            s.Meaning         = dread["Meaning"].ToString();
                            s.ConnectedLetter = dread["WordLetter"].ToString();
                            ValidSuffixes.Add(s);
                        }
                    }
                    dread.Close();
                    break;
                }
            }
            return(ValidSuffixes);
        }
Example #2
0
 public WordInfo()
 {
     Prefix   = new WordPrefix();
     Suffix   = new WordSuffix();
     Word     = "";
     Meaning  = "";
     Template = "";
 }
Example #3
0
        private static List <WordInfo> ProcessWord(ArabicWord WordToProcess)
        {
            List <WordInfo> CurrentWordInfo = new List <WordInfo>();
            WordInfo        NewInfo;

            Morphology.CheckForSpecialWord(WordToProcess, ref CurrentWordInfo);
            Morphology.CheckForPronoun(WordToProcess, ref CurrentWordInfo);
            if (FastAnalysis && CurrentWordInfo.Count > 0) //للاكتفاء باحتمالات الكلمات الخاصة وعدم البحث عن تحليل صرفي لأسماء أو أفعال
            {
                return(CurrentWordInfo);
            }
            List <WordPrefix> ValidPrefixes = WordPrefix.CheckPrefix(WordToProcess.word);
            List <WordSuffix> ValidSuffixes = WordSuffix.CheckSuffixes(WordToProcess.word);

            //المعاني الافتراضية عند عدم وجود إضافات
            ValidPrefixes.Add(new WordPrefix()
            {
                WordClass = "N1"
            });                                                      //الأسماء نكرة
            ValidPrefixes.Add(new WordPrefix()
            {
                WordClass = "V1"
            });                                                      //فعل ماض
            ValidPrefixes.Add(new WordPrefix()
            {
                WordClass = "V3"
            });                                                      //فعل أمر

            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "N0001"
            });                                                         //اسم مذكر
            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "V10311"
            });                                                          //فعل ماض غائب مفرد مذكر
            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "V20211"
            });                                                          //فعل مضارع مخاطب مفرد مذكر
            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "V201"
            });                                                        //فعل مضارع متكلم
            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "V2031"
            });                                                         //فعل مضارع غائب مفرد
            ValidSuffixes.Add(new WordSuffix()
            {
                WordClass = "V30011"
            });                                                          //فعل أمر مفرد مذكر
            List <string[]> Result = new List <string[]>();
            string          Stem;

            for (int i = 0; i < ValidPrefixes.Count; i++)
            {
                for (int j = 0; j < ValidSuffixes.Count; j++)
                {
                    Result = new List <string[]>();

                    if (WordToProcess.word.Length <= (ValidSuffixes[j].Text.Length + ValidPrefixes[i].Text.Length))
                    {   //طول الإضافات يغطي طول الكلمة بأكملها
                        continue;
                    }
                    List <string> CompatibleAdditions = Morphology.CheckAdditionsCompatibility(ValidPrefixes[i].WordClass, ValidSuffixes[j].WordClass);
                    if (CompatibleAdditions.Count == 0)
                    {   //إضافات غير متوافقة
                        continue;
                    }
                    Stem = WordToProcess.word.Substring(ValidPrefixes[i].Text.Length, WordToProcess.word.Length - (ValidPrefixes[i].Text.Length + ValidSuffixes[j].Text.Length));
                    //ابحث عن الأوزان المتوافقة مع الإضافات المحددة
                    Result = Morphology.LookForTemplate(Stem, CompatibleAdditions, Result);
                    if (Result.Count == 0)
                    {
                        continue;
                    }

                    /* اختبار وجود جذر للكلمة متوافق مع الوزن المحدد
                     * واختبار توافق الجذر الموجود مع هذا الوزن
                     * يمكن الاستغناء عن بعض هذه الخطوات عند إكمال قاعدة البيانات
                     *
                     */

                    #region اختبار توافق الوزن والجذر
                    string[]          CurrentResult;
                    ArabicRoot        CurrentRoot      = new ArabicRoot();
                    List <ArabicRoot> CheckRootResults = new List <ArabicRoot>();
                    for (int R = 0; R < Result.Count; R++)
                    {
                        CurrentResult = Result[R];
                        bool RootResult = Morphology.CheckRoot(Stem, CurrentResult[2], CurrentResult[4], CurrentResult[5], CurrentResult[6], CurrentResult[7], ref CurrentResult[3], ref CurrentRoot);
                        if (!RootResult) //اختبار وجود الجذر حسب الوزن
                        {
                            Result.RemoveAt(R);
                            R--;
                        }
                        else
                        {
                            if (CurrentRoot.IsCompatible)
                            {
                                for (int prev = 0; prev < R; prev++)
                                {
                                    //عثر على جذر متوافق احذف كل الأوزان السابقة التي ليس لها جذور متوافقة
                                    if (!CheckRootResults[prev].IsCompatible)
                                    {
                                        Result.RemoveAt(prev);
                                        CheckRootResults.RemoveAt(prev);
                                        R--;
                                        prev--;
                                    }
                                }
                                CheckRootResults.Add(CurrentRoot);
                            }
                            else
                            {
                                bool AddThisOne = true;
                                for (int prev = 0; prev < R; prev++)
                                {
                                    if (CheckRootResults[prev].IsCompatible)
                                    {
                                        AddThisOne = false; //عثر من قبل على جذور متوافقة لها أولوية
                                        Result.RemoveAt(R--);
                                        break;
                                    }
                                    //مفاضلة الأوزان من نفس قاعدة الاشتقاق
                                    byte CompareResult = Morphology.CompareRules(CurrentResult[7], Result[prev][7]);
                                    if (CompareResult == 1)
                                    {
                                        CheckRootResults.RemoveAt(prev);
                                        Result.RemoveAt(prev--);
                                        R--;
                                    }
                                    else if (CompareResult == 2)//الوزن المضاف مسبقا أولى
                                    {
                                        AddThisOne = false;
                                        Result.RemoveAt(R--);
                                        break;
                                    }
                                }
                                if (AddThisOne)
                                {
                                    CheckRootResults.Add(CurrentRoot);
                                }
                            }
                        }
                    }
                    #endregion

                    for (int R = 0; R < Result.Count; R++)
                    {
                        NewInfo            = new WordInfo();
                        NewInfo.Word       = Stem;
                        NewInfo.Diacritics = Result[R][1];
                        NewInfo.Prefix     = ValidPrefixes[i];
                        NewInfo.Suffix     = ValidSuffixes[j];
                        Tashkeel.DiacritizeWord(NewInfo);
                        if (!IgnoreExistingDiacritics && !CheckOriginalDiacritics(WordToProcess.Original, NewInfo.FullDiacritics))
                        {
                            continue;
                        }

                        NewInfo.Template = Result[R][0];
                        NewInfo.Meaning  = Result[R][3];
                        NewInfo.Root     = CheckRootResults[R];
                        CurrentWordInfo.Add(NewInfo);
                    }
                }
            }

            for (int W = 0; W < CurrentWordInfo.Count; W++)
            {
                if (CurrentWordInfo[W].Root.IsCompatible)
                {
                    WordInfo Temp;
                    for (int prev = W; prev > 0; prev--)
                    {
                        Temp = CurrentWordInfo[prev];
                        CurrentWordInfo[prev]     = CurrentWordInfo[prev - 1];
                        CurrentWordInfo[prev - 1] = Temp;
                    }
                }
            }
            CurrentWordInfo = RecallCorrections(WordToProcess, CurrentWordInfo);
            return(CurrentWordInfo);
        }