private void ApplyPersianDeclensionRules(PersianPartOfSpeech[] baseTags, double[] baseWeights, string suffix, out PersianPartOfSpeech[] targetTags, out double[] targetWeights) { Dictionary <PersianPartOfSpeech, double> results = new Dictionary <PersianPartOfSpeech, double>(); PersianSuffixesCategory suffixCat = InflectionAnalyser.SuffixCategory(suffix); for (int i = 0; i < baseTags.Length; i++) { foreach (PersianSuffixesCategory cat in Enum.GetValues(typeof(PersianSuffixesCategory))) { if ((suffixCat & cat) == cat) { PersianPartOfSpeech pos = ApplyDeclension(baseTags[i], cat); if (pos == (PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Comparative) && suffix.Equals("ترین")) { pos = PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Superlative; } if (!results.ContainsKey(pos)) { results.Add(pos, baseWeights[i]); } else { results[pos] = Math.Max(baseWeights[i], results[pos]); } } } } double sum = results.Values.Sum(); targetTags = (from result in results orderby result.Value descending select result.Key).ToArray(); targetWeights = (from result in results orderby result.Value descending select result.Value / sum).ToArray(); }
/// <summary> /// Add a correct word to dictionary /// </summary> /// <param name="userSelectedWord">Form of word which user select to add to dictionary</param> /// <param name="originalWord">Original word without lemmatization</param> ///<returns>True if word is successfully added, otherwise False</returns> private void AddToDictionary(string userSelectedWord, string originalWord) { string suffix = originalWord.Remove(0, userSelectedWord.Length); PersianPOSTag extractedPOSTag = PersianPOSTag.UserPOS; if (suffix.Length > 0) { PersianSuffixesCategory suffixCategory = InflectionAnalyser.SuffixCategory(suffix); extractedPOSTag = InflectionAnalyser.AcceptingPOS(suffixCategory); extractedPOSTag = extractedPOSTag.Set(PersianPOSTag.UserPOS); } AddWordToFinalList(userSelectedWord, m_wordList[userSelectedWord], extractedPOSTag); }
// TODO: Examin the rules! We also might want to add probability to rule application. // TODO: Also consider revising the order of rules private static PersianPartOfSpeech ApplyDeclension(PersianPartOfSpeech baseTag, PersianSuffixesCategory suffixCat) { if (baseTag == PersianPartOfSpeech.Adjective && (suffixCat == PersianSuffixesCategory.PluralSignHaa || suffixCat == PersianSuffixesCategory.PluralSignAan)) { return(PersianPartOfSpeech.Noun | PersianPartOfSpeech.Plural); } if (baseTag == PersianPartOfSpeech.Noun && suffixCat == PersianSuffixesCategory.YaaNesbat) { return(PersianPartOfSpeech.Adjective); } if (baseTag == PersianPartOfSpeech.Adjective && suffixCat == PersianSuffixesCategory.ToBeVerb) { return(PersianPartOfSpeech.Noun); } if (baseTag == PersianPartOfSpeech.Noun && suffixCat == PersianSuffixesCategory.ComparativeAdjectives) { return(PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Comparative); } if (baseTag == PersianPartOfSpeech.Unknown) { if (suffixCat == PersianSuffixesCategory.ComparativeAdjectives) { return(PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Comparative); } if (suffixCat == PersianSuffixesCategory.PluralSignHaa) { return(PersianPartOfSpeech.Noun | PersianPartOfSpeech.Plural); } if (suffixCat == PersianSuffixesCategory.PluralSignAan) { return(PersianPartOfSpeech.Noun | PersianPartOfSpeech.Plural); } } return(baseTag); }