public static List <WordPrefix> CheckPrefix(string Word) { string[] prefixes = { "ا", "ي", "ت", "ن", "س", "ب", "ل", "ك", "ف", "و", "أ" }; List <WordPrefix> ValidPrefixes = new List <WordPrefix>(); for (int i = 0; i < prefixes.Length; i++) //هل تبدأ الكلمة بأحد حروف السوابق؟ { if (Word.StartsWith(prefixes[i], StringComparison.Ordinal)) // the two strings must match character for character: "and" does not equal "And" or "AND" { OleDbCommand com = new OleDbCommand(); com.Connection = Analyzer.con; com.CommandText = "select * from prefixes where StrComp( Left( add , 1 ),'" + prefixes[i] + "',0)=0"; OleDbDataReader dread = com.ExecuteReader(); while (dread.Read()) { if (Word.StartsWith(dread[0].ToString(), StringComparison.Ordinal)) { WordPrefix p = new WordPrefix(); p.Text = dread["Add"].ToString(); p.Tashkeel = dread["Diacritics"].ToString(); p.WordClass = dread["Class"].ToString(); p.Meaning = dread["Meaning"].ToString(); ValidPrefixes.Add(p); } } dread.Close(); break; } } return(ValidPrefixes); }
public WordInfo() { Prefix = new WordPrefix(); Suffix = new WordSuffix(); Word = ""; Meaning = ""; Template = ""; }
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); }